7
7
import string
8
8
from subprocess import getstatusoutput
9
9
10
- prg = ' ./password.py'
11
- words = ' ../inputs/words .txt'
10
+ PRG = " ./password.py"
11
+ WORDS = " ../inputs/WORDS .txt"
12
12
13
13
14
14
# --------------------------------------------------
15
15
def test_exists ():
16
16
"""exists"""
17
17
18
- assert os .path .isfile (prg )
19
- assert os .path .isfile (words )
18
+ assert os .path .isfile (PRG )
19
+ assert os .path .isfile (WORDS )
20
20
21
21
22
22
# --------------------------------------------------
23
23
def test_usage ():
24
24
"""usage"""
25
25
26
- for flag in ['-h' , ' --help' ]:
27
- rv , out = getstatusoutput (f' { prg } { flag } ' )
26
+ for flag in ["-h" , " --help" ]:
27
+ rv , out = getstatusoutput (f"python { PRG } { flag } " )
28
28
assert rv == 0
29
- assert out .lower ().startswith (' usage' )
29
+ assert out .lower ().startswith (" usage" )
30
30
31
31
32
32
# --------------------------------------------------
33
33
def test_bad_file ():
34
34
"""Dies on bad file"""
35
35
36
36
bad = random_string ()
37
- rv , out = getstatusoutput (f' { prg } { bad } ' )
37
+ rv , out = getstatusoutput (f"python { PRG } { bad } " )
38
38
assert rv != 0
39
39
assert re .search (f"No such file or directory: '{ bad } '" , out )
40
40
@@ -44,19 +44,19 @@ def test_bad_num():
44
44
"""Dies on bad num"""
45
45
46
46
bad = random_string ()
47
- flag = '-n' if random .choice ([0 , 1 ]) else ' --num'
48
- rv , out = getstatusoutput (f' { prg } { flag } { bad } { words } ' )
47
+ flag = "-n" if random .choice ([0 , 1 ]) else " --num"
48
+ rv , out = getstatusoutput (f"python { PRG } { flag } { bad } { WORDS } " )
49
49
assert rv != 0
50
50
assert re .search (f"invalid int value: '{ bad } '" , out )
51
51
52
52
53
53
# --------------------------------------------------
54
- def test_bad_num_words ():
54
+ def test_bad_num_WORDS ():
55
55
"""Dies on bad num"""
56
56
57
57
bad = random_string ()
58
- flag = '-w' if random .choice ([0 , 1 ]) else '--num_words'
59
- rv , out = getstatusoutput (f' { prg } { flag } { bad } { words } ' )
58
+ flag = "-w" if random .choice ([0 , 1 ]) else "--num_WORDS"
59
+ rv , out = getstatusoutput (f"python { PRG } { flag } { bad } { WORDS } " )
60
60
assert rv != 0
61
61
assert re .search (f"invalid int value: '{ bad } '" , out )
62
62
@@ -66,8 +66,8 @@ def test_bad_min_word_len():
66
66
"""Dies on bad min_word_len"""
67
67
68
68
bad = random_string ()
69
- flag = '-m' if random .choice ([0 , 1 ]) else ' --min_word_len'
70
- rv , out = getstatusoutput (f' { prg } { flag } { bad } { words } ' )
69
+ flag = "-m" if random .choice ([0 , 1 ]) else " --min_word_len"
70
+ rv , out = getstatusoutput (f"python { PRG } { flag } { bad } { WORDS } " )
71
71
assert rv != 0
72
72
assert re .search (f"invalid int value: '{ bad } '" , out )
73
73
@@ -77,8 +77,8 @@ def test_bad_max_word_len():
77
77
"""Dies on bad max_word_len"""
78
78
79
79
bad = random_string ()
80
- flag = '-m' if random .choice ([0 , 1 ]) else ' --max_word_len'
81
- rv , out = getstatusoutput (f' { prg } { flag } { bad } { words } ' )
80
+ flag = "-m" if random .choice ([0 , 1 ]) else " --max_word_len"
81
+ rv , out = getstatusoutput (f"python { PRG } { flag } { bad } { WORDS } " )
82
82
assert rv != 0
83
83
assert re .search (f"invalid int value: '{ bad } '" , out )
84
84
@@ -88,8 +88,8 @@ def test_bad_seed():
88
88
"""Dies on bad seed"""
89
89
90
90
bad = random_string ()
91
- flag = '-s' if random .choice ([0 , 1 ]) else ' --seed'
92
- rv , out = getstatusoutput (f' { prg } { flag } { bad } { words } ' )
91
+ flag = "-s" if random .choice ([0 , 1 ]) else " --seed"
92
+ rv , out = getstatusoutput (f"python { PRG } { flag } { bad } { WORDS } " )
93
93
assert rv != 0
94
94
assert re .search (f"invalid int value: '{ bad } '" , out )
95
95
@@ -98,70 +98,71 @@ def test_bad_seed():
98
98
def test_defaults ():
99
99
"""Test"""
100
100
101
- rv , out = getstatusoutput (f' { prg } -s 1 { words } ' )
101
+ rv , out = getstatusoutput (f"python { PRG } -s 1 { WORDS } " )
102
102
assert rv == 0
103
- assert out .strip () == ' \n ' .join ([
104
- ' DuniteBoonLociDefat' , ' WegaTitmalUnplatSatire' , ' IdeanClipsVitiArriet'
105
- ] )
103
+ assert out .strip () == " \n " .join (
104
+ [ " DuniteBoonLociDefat" , " WegaTitmalUnplatSatire" , " IdeanClipsVitiArriet" ]
105
+ )
106
106
107
107
108
108
# --------------------------------------------------
109
109
def test_num ():
110
110
"""Test"""
111
111
112
- rv , out = getstatusoutput (f' { prg } -s 1 -n 1 { words } ' )
112
+ rv , out = getstatusoutput (f"python { PRG } -s 1 -n 1 { WORDS } " )
113
113
assert rv == 0
114
- assert out .strip () == ' DuniteBoonLociDefat'
114
+ assert out .strip () == " DuniteBoonLociDefat"
115
115
116
116
117
117
# --------------------------------------------------
118
- def test_num_words ():
118
+ def test_num_WORDS ():
119
119
"""Test"""
120
120
121
- rv , out = getstatusoutput (f' { prg } -s 1 -w 2 { words } ' )
121
+ rv , out = getstatusoutput (f"python { PRG } -s 1 -w 2 { WORDS } " )
122
122
assert rv == 0
123
- assert out .strip () == ' \n ' .join ([' DuniteBoon' , ' LociDefat' , ' WegaTitmal' ])
123
+ assert out .strip () == " \n " .join ([" DuniteBoon" , " LociDefat" , " WegaTitmal" ])
124
124
125
125
126
126
# --------------------------------------------------
127
127
def test_min_word_len ():
128
128
"""Test"""
129
129
130
- rv , out = getstatusoutput (f' { prg } -s 1 -m 5 { words } ' )
130
+ rv , out = getstatusoutput (f"python { PRG } -s 1 -m 5 { WORDS } " )
131
131
assert rv == 0
132
- assert out .strip () == '\n ' .join ([
133
- 'CarneyRapperWabenoUndine' , 'BabaiFarerBugleOnlepy' ,
134
- 'UnbittMinnyNatalSkanda'
135
- ])
132
+ assert out .strip () == "\n " .join (
133
+ ["CarneyRapperWabenoUndine" , "BabaiFarerBugleOnlepy" , "UnbittMinnyNatalSkanda" ]
134
+ )
136
135
137
136
138
137
# --------------------------------------------------
139
138
def test_max_word_len ():
140
139
"""Test"""
141
140
142
- rv , out = getstatusoutput (f' { prg } -s 1 -x 10 { words } ' )
141
+ rv , out = getstatusoutput (f"python { PRG } -s 1 -x 10 { WORDS } " )
143
142
assert rv == 0
144
- assert out .strip () == '\n ' .join ([
145
- 'DicemanYardwandBoeberaKismetic' , 'CubiculumTilsitSnowcapSuer' ,
146
- 'ProhasteHaddockChristmasyTenonitis'
147
- ])
143
+ assert out .strip () == "\n " .join (
144
+ [
145
+ "DicemanYardwandBoeberaKismetic" ,
146
+ "CubiculumTilsitSnowcapSuer" ,
147
+ "ProhasteHaddockChristmasyTenonitis" ,
148
+ ]
149
+ )
148
150
149
151
150
152
# --------------------------------------------------
151
153
def test_l33t ():
152
154
"""Test"""
153
155
154
- rv , out = getstatusoutput (f' { prg } -s 1 -l { words } ' )
156
+ rv , out = getstatusoutput (f"python { PRG } -s 1 -l { WORDS } " )
155
157
assert rv == 0
156
- assert out .strip () == '\n ' .join ([
157
- 'DUn1Teb0onloCiDef4T/' , 'Weg4TiTm@LuNPl4T54+1r3_' ,
158
- 'iD3@Ncl1P5v1+14rrie+/'
159
- ])
158
+ assert out .strip () == "\n " .join (
159
+ ["DUn1Teb0onloCiDef4T/" , "Weg4TiTm@LuNPl4T54+1r3_" , "iD3@Ncl1P5v1+14rrie+/" ]
160
+ )
160
161
161
162
162
163
# --------------------------------------------------
163
164
def random_string ():
164
165
"""generate a random string"""
165
166
166
167
k = random .randint (5 , 10 )
167
- return '' .join (random .choices (string .ascii_letters + string .digits , k = k ))
168
+ return "" .join (random .choices (string .ascii_letters + string .digits , k = k ))
0 commit comments