@@ -29,25 +29,53 @@ def test_totp(self):
29
29
self .assertEqual (mintotp .totp (SECRET1 ), '626854' )
30
30
self .assertEqual (mintotp .totp (SECRET2 ), '093610' )
31
31
32
- def test_main (self ):
33
- with mock .patch ('sys.stdin' , [SECRET1 ]):
34
- with mock .patch ('time.time' , return_value = 0 ):
35
- with mock .patch ('builtins.print' ) as mock_print :
36
- mintotp .main ()
37
- mock_print .assert_called_once_with ('549419' )
38
- with mock .patch ('sys.stdin' , [SECRET1 , SECRET2 ]):
39
- with mock .patch ('time.time' , return_value = 0 ):
40
- with mock .patch ('builtins.print' ) as mock_print :
41
- mintotp .main ()
42
- self .assertEqual (mock_print .mock_calls ,
43
- [mock .call ('549419' ),
44
- mock .call ('009551' )])
45
-
46
- def test_name (self ):
47
- with mock .patch ('sys.stdin' , [SECRET1 ]):
48
- with mock .patch ('time.time' , return_value = 0 ):
49
- with mock .patch ('builtins.print' ) as mock_print :
50
- runpy .run_module ('mintotp' , run_name = 'mintotp' )
51
- mock_print .assert_not_called ()
52
- runpy .run_module ('mintotp' , run_name = '__main__' )
53
- mock_print .assert_called_once_with ('549419' )
32
+ @mock .patch ('time.time' , mock .Mock (return_value = 0 ))
33
+ @mock .patch ('sys.argv' , ['prog' ])
34
+ @mock .patch ('sys.stdin' , [SECRET1 ])
35
+ @mock .patch ('builtins.print' )
36
+ def test_main_one_secret (self , mock_print ):
37
+ mintotp .main ()
38
+ mock_print .assert_called_once_with ('549419' )
39
+
40
+ @mock .patch ('time.time' , mock .Mock (return_value = 0 ))
41
+ @mock .patch ('sys.argv' , ['prog' ])
42
+ @mock .patch ('sys.stdin' , [SECRET1 , SECRET2 ])
43
+ @mock .patch ('builtins.print' )
44
+ def test_main_two_secrets (self , mock_print ):
45
+ mintotp .main ()
46
+ self .assertEqual (mock_print .mock_calls , [mock .call ('549419' ),
47
+ mock .call ('009551' )])
48
+
49
+ @mock .patch ('time.time' , mock .Mock (return_value = 2520 ))
50
+ @mock .patch ('sys.argv' , ['prog' , '60' ])
51
+ @mock .patch ('sys.stdin' , [SECRET1 ])
52
+ @mock .patch ('builtins.print' )
53
+ def test_main_step (self , mock_print ):
54
+ mintotp .main ()
55
+ mock_print .assert_called_once_with ('626854' )
56
+
57
+ @mock .patch ('time.time' , mock .Mock (return_value = 0 ))
58
+ @mock .patch ('sys.argv' , ['prog' , '30' , '8' ])
59
+ @mock .patch ('sys.stdin' , [SECRET1 ])
60
+ @mock .patch ('builtins.print' )
61
+ def test_main_digits (self , mock_print ):
62
+ mintotp .main ()
63
+ mock_print .assert_called_once_with ('49549419' )
64
+
65
+ @mock .patch ('time.time' , mock .Mock (return_value = 0 ))
66
+ @mock .patch ('sys.argv' , ['prog' , '30' , '6' , 'sha256' ])
67
+ @mock .patch ('sys.stdin' , [SECRET1 ])
68
+ @mock .patch ('builtins.print' )
69
+ def test_main_digest (self , mock_print ):
70
+ mintotp .main ()
71
+ mock_print .assert_called_once_with ('473535' )
72
+
73
+ @mock .patch ('time.time' , mock .Mock (return_value = 0 ))
74
+ @mock .patch ('sys.argv' , ['prog' ])
75
+ @mock .patch ('sys.stdin' , [SECRET1 ])
76
+ @mock .patch ('builtins.print' )
77
+ def test_module (self , mock_print ):
78
+ runpy .run_module ('mintotp' , run_name = 'mintotp' )
79
+ mock_print .assert_not_called ()
80
+ runpy .run_module ('mintotp' , run_name = '__main__' )
81
+ mock_print .assert_called_once_with ('549419' )
0 commit comments