Skip to content

Commit

Permalink
Add tests for entry-point changes
Browse files Browse the repository at this point in the history
  • Loading branch information
grantjenks committed Dec 28, 2022
1 parent 6a12ec5 commit b88cf6e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/freegames/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ def main():


if __name__ == '__main__':
main()
main() # pragma: no cover
21 changes: 17 additions & 4 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import runpy
import unittest.mock as mock

from freegames import __main__


def test_main_list():
random.seed(0)

with mock.patch('sys.argv', ['__main__.py', 'list']):
runpy.run_module('freegames.__main__')
__main__.main()


def test_main_copy():
Expand All @@ -19,7 +21,7 @@ def test_main_copy():

with mock.patch('sys.argv', ['__main__.py', 'copy', 'guess']):
with mock.patch('builtins.open', mock_open):
runpy.run_module('freegames.__main__')
__main__.main()


def test_main_copy_error():
Expand All @@ -31,7 +33,7 @@ def test_main_copy_error():

try:
with mock.patch('sys.argv', ['__main__.py', 'copy', 'guess']):
runpy.run_module('freegames.__main__')
__main__.main()
finally:
os.remove('guess.py')

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

with mock.patch('sys.argv', ['__main__.py', 'show', 'guess']):
runpy.run_module('freegames.__main__')
__main__.main()


def test_main_play():
random.seed(0)
mock_input = mock.Mock()
mock_input.side_effect = [20, 70, 50]
mocks = {'print': lambda *args: None, 'input': mock_input}

with mock.patch.multiple('builtins', **mocks):
with mock.patch('sys.argv', ['__main__.py', 'play', 'guess']):
__main__.main()

0 comments on commit b88cf6e

Please sign in to comment.