Skip to content

Commit b88cf6e

Browse files
committed
Add tests for entry-point changes
1 parent 6a12ec5 commit b88cf6e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/freegames/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ def main():
7272

7373

7474
if __name__ == '__main__':
75-
main()
75+
main() # pragma: no cover

tests/test_main.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import runpy
55
import unittest.mock as mock
66

7+
from freegames import __main__
8+
79

810
def test_main_list():
911
random.seed(0)
1012

1113
with mock.patch('sys.argv', ['__main__.py', 'list']):
12-
runpy.run_module('freegames.__main__')
14+
__main__.main()
1315

1416

1517
def test_main_copy():
@@ -19,7 +21,7 @@ def test_main_copy():
1921

2022
with mock.patch('sys.argv', ['__main__.py', 'copy', 'guess']):
2123
with mock.patch('builtins.open', mock_open):
22-
runpy.run_module('freegames.__main__')
24+
__main__.main()
2325

2426

2527
def test_main_copy_error():
@@ -31,7 +33,7 @@ def test_main_copy_error():
3133

3234
try:
3335
with mock.patch('sys.argv', ['__main__.py', 'copy', 'guess']):
34-
runpy.run_module('freegames.__main__')
36+
__main__.main()
3537
finally:
3638
os.remove('guess.py')
3739

@@ -40,4 +42,15 @@ def test_main_show():
4042
random.seed(0)
4143

4244
with mock.patch('sys.argv', ['__main__.py', 'show', 'guess']):
43-
runpy.run_module('freegames.__main__')
45+
__main__.main()
46+
47+
48+
def test_main_play():
49+
random.seed(0)
50+
mock_input = mock.Mock()
51+
mock_input.side_effect = [20, 70, 50]
52+
mocks = {'print': lambda *args: None, 'input': mock_input}
53+
54+
with mock.patch.multiple('builtins', **mocks):
55+
with mock.patch('sys.argv', ['__main__.py', 'play', 'guess']):
56+
__main__.main()

0 commit comments

Comments
 (0)