7
7
import string
8
8
from subprocess import getstatusoutput , getoutput
9
9
10
- prg = ' ./howler.py'
10
+ PRG = " ./howler.py"
11
11
12
12
13
13
# --------------------------------------------------
14
14
def random_string ():
15
15
"""generate a random string"""
16
16
17
17
k = random .randint (5 , 10 )
18
- return '' .join (random .choices (string .ascii_letters + string .digits , k = k ))
18
+ return "" .join (random .choices (string .ascii_letters + string .digits , k = k ))
19
19
20
20
21
21
# --------------------------------------------------
22
22
def out_flag ():
23
23
"""Either -o or --outfile"""
24
24
25
- return '-o' if random .randint (0 , 1 ) else ' --outfile'
25
+ return "-o" if random .randint (0 , 1 ) else " --outfile"
26
26
27
27
28
28
# --------------------------------------------------
29
29
def test_exists ():
30
30
"""exists"""
31
31
32
- assert os .path .isfile (prg )
32
+ assert os .path .isfile (PRG )
33
33
34
34
35
35
# --------------------------------------------------
36
36
def test_usage ():
37
37
"""usage"""
38
38
39
- for flag in ['-h' , ' --help' ]:
40
- rv , out = getstatusoutput (f' { prg } { flag } ' )
39
+ for flag in ["-h" , " --help" ]:
40
+ rv , out = getstatusoutput (f"python3 { PRG } { flag } " )
41
41
assert rv == 0
42
42
assert re .match ("usage" , out , re .IGNORECASE )
43
43
@@ -46,8 +46,8 @@ def test_usage():
46
46
def test_text_stdout ():
47
47
"""Test STDIN/STDOUT"""
48
48
49
- out = getoutput (f'{ prg } "foo bar baz"' )
50
- assert out .strip () == ' FOO BAR BAZ'
49
+ out = getoutput (f'python3 { PRG } "foo bar baz"' )
50
+ assert out .strip () == " FOO BAR BAZ"
51
51
52
52
53
53
# --------------------------------------------------
@@ -59,11 +59,11 @@ def test_text_outfile():
59
59
os .remove (out_file )
60
60
61
61
try :
62
- out = getoutput (f'{ prg } { out_flag ()} { out_file } "foo bar baz"' )
63
- assert out .strip () == ''
62
+ out = getoutput (f'python3 { PRG } { out_flag ()} { out_file } "foo bar baz"' )
63
+ assert out .strip () == ""
64
64
assert os .path .isfile (out_file )
65
65
text = open (out_file ).read ().rstrip ()
66
- assert text == ' FOO BAR BAZ'
66
+ assert text == " FOO BAR BAZ"
67
67
finally :
68
68
if os .path .isfile (out_file ):
69
69
os .remove (out_file )
@@ -73,19 +73,18 @@ def test_text_outfile():
73
73
def test_file ():
74
74
"""Test file in/out"""
75
75
76
- for expected_file in os .listdir (' test-outs' ):
76
+ for expected_file in os .listdir (" test-outs" ):
77
77
try :
78
78
out_file = random_string ()
79
79
if os .path .isfile (out_file ):
80
80
os .remove (out_file )
81
81
82
82
basename = os .path .basename (expected_file )
83
- in_file = os .path .join (' ../inputs' , basename )
84
- out = getoutput (f' { prg } { out_flag ()} { out_file } { in_file } ' )
85
- assert out .strip () == ''
83
+ in_file = os .path .join (" ../inputs" , basename )
84
+ out = getoutput (f"python3 { PRG } { out_flag ()} { out_file } { in_file } " )
85
+ assert out .strip () == ""
86
86
produced = open (out_file ).read ().rstrip ()
87
- expected = open (os .path .join ('test-outs' ,
88
- expected_file )).read ().strip ()
87
+ expected = open (os .path .join ("test-outs" , expected_file )).read ().strip ()
89
88
assert expected == produced
90
89
finally :
91
90
if os .path .isfile (out_file ):
0 commit comments