4
4
import runpy
5
5
import unittest .mock as mock
6
6
7
+ from freegames import __main__
8
+
7
9
8
10
def test_main_list ():
9
11
random .seed (0 )
10
12
11
13
with mock .patch ('sys.argv' , ['__main__.py' , 'list' ]):
12
- runpy . run_module ( 'freegames.__main__' )
14
+ __main__ . main ( )
13
15
14
16
15
17
def test_main_copy ():
@@ -19,7 +21,7 @@ def test_main_copy():
19
21
20
22
with mock .patch ('sys.argv' , ['__main__.py' , 'copy' , 'guess' ]):
21
23
with mock .patch ('builtins.open' , mock_open ):
22
- runpy . run_module ( 'freegames.__main__' )
24
+ __main__ . main ( )
23
25
24
26
25
27
def test_main_copy_error ():
@@ -31,7 +33,7 @@ def test_main_copy_error():
31
33
32
34
try :
33
35
with mock .patch ('sys.argv' , ['__main__.py' , 'copy' , 'guess' ]):
34
- runpy . run_module ( 'freegames.__main__' )
36
+ __main__ . main ( )
35
37
finally :
36
38
os .remove ('guess.py' )
37
39
@@ -40,4 +42,15 @@ def test_main_show():
40
42
random .seed (0 )
41
43
42
44
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