Skip to content

Commit fb6c52d

Browse files
committed
refactor(tests): dedupe mock input yes/no
1 parent 24c31a0 commit fb6c52d

File tree

6 files changed

+44
-40
lines changed

6 files changed

+44
-40
lines changed

tests/commands/user/test_alumni.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,13 @@ def mock_commands_reset(mock_commands_reset):
1111

1212

1313
@pytest.fixture
14-
def mock_input_yes(mock_input):
15-
fix = mock_input(MODULE)
16-
fix.return_value = "y"
17-
return fix
14+
def mock_input_yes(mock_input_yes):
15+
return mock_input_yes(MODULE)
1816

1917

2018
@pytest.fixture
21-
def mock_input_no(mock_input):
22-
fix = mock_input(MODULE)
23-
fix.return_value = "n"
24-
return fix
19+
def mock_input_no(mock_input_no):
20+
return mock_input_no(MODULE)
2521

2622

2723
@pytest.fixture

tests/commands/user/test_delete.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55

66

77
@pytest.fixture
8-
def mock_input_yes(mock_input):
9-
fix = mock_input(MODULE)
10-
fix.return_value = "y"
11-
return fix
8+
def mock_input_yes(mock_input_yes):
9+
return mock_input_yes(MODULE)
1210

1311

1412
@pytest.fixture
15-
def mock_input_no(mock_input):
16-
fix = mock_input(MODULE)
17-
fix.return_value = "n"
18-
return fix
13+
def mock_input_no(mock_input_no):
14+
return mock_input_no(MODULE)
1915

2016

2117
@pytest.fixture

tests/commands/user/test_offboard.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55

66

77
@pytest.fixture
8-
def mock_input_yes(mock_input):
9-
fix = mock_input(MODULE)
10-
fix.return_value = "y"
11-
return fix
8+
def mock_input_yes(mock_input_yes):
9+
return mock_input_yes(MODULE)
1210

1311

1412
@pytest.fixture
15-
def mock_input_no(mock_input):
16-
fix = mock_input(MODULE)
17-
fix.return_value = "n"
18-
return fix
13+
def mock_input_no(mock_input_no):
14+
return mock_input_no(MODULE)
1915

2016

2117
@pytest.fixture

tests/commands/user/test_reset.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66

77

88
@pytest.fixture
9-
def mock_input_yes(mock_input):
10-
fix = mock_input(MODULE)
11-
fix.return_value = "y"
12-
return fix
9+
def mock_input_yes(mock_input_yes):
10+
return mock_input_yes(MODULE)
1311

1412

1513
@pytest.fixture
16-
def mock_input_no(mock_input):
17-
fix = mock_input(MODULE)
18-
fix.return_value = "n"
19-
return fix
14+
def mock_input_no(mock_input_no):
15+
return mock_input_no(MODULE)
2016

2117

2218
@pytest.fixture

tests/commands/user/test_signout.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55

66

77
@pytest.fixture
8-
def mock_input_yes(mock_input):
9-
fix = mock_input(MODULE)
10-
fix.return_value = "y"
11-
return fix
8+
def mock_input_yes(mock_input_yes):
9+
return mock_input_yes(MODULE)
1210

1311

1412
@pytest.fixture
15-
def mock_input_no(mock_input):
16-
fix = mock_input(MODULE)
17-
fix.return_value = "n"
18-
return fix
13+
def mock_input_no(mock_input_no):
14+
return mock_input_no(MODULE)
1915

2016

2117
@pytest.fixture

tests/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,30 @@ def mock_input(mock_module_name):
3636
return mock_module_name("input")
3737

3838

39+
@pytest.fixture
40+
def mock_input_yes(mock_input):
41+
"""Fixture returns a function that patches the input return value to Yes in a give module."""
42+
43+
def _mock_input_yes(module):
44+
fix = mock_input(module)
45+
fix.return_value = "y"
46+
return fix
47+
48+
return _mock_input_yes
49+
50+
51+
@pytest.fixture
52+
def mock_input_no(mock_input):
53+
"""Fixture returns a function that patches the input return value to No in a give module."""
54+
55+
def _mock_input_no(module):
56+
fix = mock_input(module)
57+
fix.return_value = "n"
58+
return fix
59+
60+
return _mock_input_no
61+
62+
3963
@click.command
4064
def dummy_command(**kwargs):
4165
return RESULT_SUCCESS

0 commit comments

Comments
 (0)