88import string
99from subprocess import getstatusoutput
1010
11- prg = ' ./bottles.py'
11+ PRG = " ./bottles.py"
1212
1313
1414# --------------------------------------------------
1515def test_exists ():
1616 """exists"""
1717
18- assert os .path .isfile (prg )
18+ assert os .path .isfile (PRG )
1919
2020
2121# --------------------------------------------------
2222def test_usage ():
2323 """usage"""
2424
25- for flag in ['-h' , ' --help' ]:
26- rv , out = getstatusoutput (f' { prg } { flag } ' )
25+ for flag in ["-h" , " --help" ]:
26+ rv , out = getstatusoutput (f"python { PRG } { flag } " )
2727 assert rv == 0
2828 assert re .match ("usage" , out , re .IGNORECASE )
2929
@@ -33,17 +33,17 @@ def test_bad_int():
3333 """Bad integer value"""
3434
3535 bad = random .randint (- 10 , 0 )
36- rv , out = getstatusoutput (f' { prg } -n { bad } ' )
36+ rv , out = getstatusoutput (f"python { PRG } -n { bad } " )
3737 assert rv != 0
38- assert re .search (f'--num "{ bad } " must be greater than 0' , out )
38+ assert re .search (f'--num: "{ bad } " must be greater than 0' , out )
3939
4040
4141# --------------------------------------------------
4242def test_float ():
4343 """float value"""
4444
4545 bad = round (random .random () * 10 , 2 )
46- rv , out = getstatusoutput (f' { prg } --num { bad } ' )
46+ rv , out = getstatusoutput (f"python { PRG } --num { bad } " )
4747 assert rv != 0
4848 assert re .search (f"invalid int value: '{ bad } '" , out )
4949
@@ -53,7 +53,7 @@ def test_str():
5353 """str value"""
5454
5555 bad = random_string ()
56- rv , out = getstatusoutput (f' { prg } -n { bad } ' )
56+ rv , out = getstatusoutput (f"python { PRG } -n { bad } " )
5757 assert rv != 0
5858 assert re .search (f"invalid int value: '{ bad } '" , out )
5959
@@ -62,12 +62,14 @@ def test_str():
6262def test_one ():
6363 """One bottle of beer"""
6464
65- expected = ('1 bottle of beer on the wall,\n '
66- '1 bottle of beer,\n '
67- 'Take one down, pass it around,\n '
68- 'No more bottles of beer on the wall!' )
65+ expected = (
66+ "1 bottle of beer on the wall,\n "
67+ "1 bottle of beer,\n "
68+ "Take one down, pass it around,\n "
69+ "No more bottles of beer on the wall!"
70+ )
6971
70- rv , out = getstatusoutput (f' { prg } --num 1' )
72+ rv , out = getstatusoutput (f"python { PRG } --num 1" )
7173 assert rv == 0
7274 assert out == expected
7375
@@ -76,16 +78,18 @@ def test_one():
7678def test_two ():
7779 """Two bottles of beer"""
7880
79- expected = ('2 bottles of beer on the wall,\n '
80- '2 bottles of beer,\n '
81- 'Take one down, pass it around,\n '
82- '1 bottle of beer on the wall!\n \n '
83- '1 bottle of beer on the wall,\n '
84- '1 bottle of beer,\n '
85- 'Take one down, pass it around,\n '
86- 'No more bottles of beer on the wall!' )
87-
88- rv , out = getstatusoutput (f'{ prg } -n 2' )
81+ expected = (
82+ "2 bottles of beer on the wall,\n "
83+ "2 bottles of beer,\n "
84+ "Take one down, pass it around,\n "
85+ "1 bottle of beer on the wall!\n \n "
86+ "1 bottle of beer on the wall,\n "
87+ "1 bottle of beer,\n "
88+ "Take one down, pass it around,\n "
89+ "No more bottles of beer on the wall!"
90+ )
91+
92+ rv , out = getstatusoutput (f"python { PRG } -n 2" )
8993 assert rv == 0
9094 assert out == expected
9195
@@ -94,21 +98,19 @@ def test_two():
9498def test_random ():
9599 """Random number"""
96100
97- sums = dict (
98- map (lambda x : x .split ('\t ' ),
99- open ('sums.txt' ).read ().splitlines ()))
101+ sums = dict (map (lambda x : x .split ("\t " ), open ("sums.txt" ).read ().splitlines ()))
100102
101103 for n in random .choices (list (sums .keys ()), k = 10 ):
102- flag = '-n' if random .choice ([0 , 1 ]) == 1 else ' --num'
103- rv , out = getstatusoutput (f' { prg } { flag } { n } ' )
104- out += ' \n ' # because the last newline is removed
104+ flag = "-n" if random .choice ([0 , 1 ]) == 1 else " --num"
105+ rv , out = getstatusoutput (f"python { PRG } { flag } { n } " )
106+ out += " \n " # because the last newline is removed
105107 assert rv == 0
106- assert hashlib .md5 (out .encode (' utf-8' )).hexdigest () == sums [n ]
108+ assert hashlib .md5 (out .encode (" utf-8" )).hexdigest () == sums [n ]
107109
108110
109111# --------------------------------------------------
110112def random_string ():
111113 """generate a random string"""
112114
113115 k = random .randint (5 , 10 )
114- return '' .join (random .choices (string .ascii_letters + string .digits , k = k ))
116+ return "" .join (random .choices (string .ascii_letters + string .digits , k = k ))
0 commit comments