forked from kyclark/tiny_python_projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·85 lines (65 loc) · 1.91 KB
/
test.py
File metadata and controls
executable file
·85 lines (65 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
"""tests for crowsnest.py"""
import os
from subprocess import getstatusoutput, getoutput
prg = "crowsnest.py"
consonant_words = [
"brigantine",
"clipper",
"dreadnought",
"frigate",
"galleon",
"haddock",
"junk",
"ketch",
"longboat",
"mullet",
"narwhal",
"porpoise",
"quay",
"regatta",
"submarine",
"tanker",
"vessel",
"whale",
"xebec",
"yatch",
"zebrafish",
]
vowel_words = ["aviso", "eel", "iceberg", "octopus", "upbound"]
template = "Ahoy, Captain, {} {} off the larboard bow!"
# --------------------------------------------------
def test_exists():
"""exists"""
assert os.path.isfile(prg)
# --------------------------------------------------
def test_usage():
"""usage"""
for flag in ["-h", "--help"]:
rv, out = getstatusoutput(f"{prg} {flag}")
assert rv == 0
assert out.lower().startswith("usage")
# --------------------------------------------------
def test_consonant():
"""brigantine -> a brigantine"""
for word in consonant_words:
out = getoutput(f"{prg} {word}")
assert out.strip() == template.format("a", word)
# --------------------------------------------------
def test_consonant_upper():
"""brigantine -> a Brigatine"""
for word in consonant_words:
out = getoutput(f"{prg} {word.title()}")
assert out.strip() == template.format("a", word.title())
# --------------------------------------------------
def test_vowel():
"""octopus -> an octopus"""
for word in vowel_words:
out = getoutput(f"{prg} {word}")
assert out.strip() == template.format("an", word)
# --------------------------------------------------
def test_vowel_upper():
"""octopus -> an Octopus"""
for word in vowel_words:
out = getoutput(f"{prg} {word.upper()}")
assert out.strip() == template.format("an", word.upper())