Skip to content

Commit 6a1f093

Browse files
committed
Project 02
1 parent 88205d2 commit 6a1f093

File tree

2 files changed

+71
-19
lines changed

2 files changed

+71
-19
lines changed

02_crowsnest/crowsnest.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : Oak Hopper
4+
Date : 2024-06-17
5+
Purpose: Let the captain know what you see
6+
"""
7+
8+
import argparse
9+
10+
11+
# --------------------------------------------------
12+
def get_args():
13+
"""Get command-line arguments"""
14+
parser = argparse.ArgumentParser(
15+
description="Alert the captain!",
16+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
17+
)
18+
parser.add_argument("word", metavar="word", help="The thing we see")
19+
return parser.parse_args()
20+
21+
22+
# --------------------------------------------------
23+
def main():
24+
"""Make a jazz noise here"""
25+
26+
args = get_args()
27+
word: str = args.word
28+
article: str = "an" if word[0].lower() in "aeiou" else "a"
29+
shout: str = "Ahoy, Captain, {} {} off the larboard bow!"
30+
print(shout.format(article.title() if word[0].isupper() else article, word))
31+
32+
33+
# --------------------------------------------------
34+
if __name__ == "__main__":
35+
main()

02_crowsnest/test.py

+36-19
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,82 @@
44
import os
55
from subprocess import getstatusoutput, getoutput
66

7-
prg = './crowsnest.py'
7+
PRG = "./crowsnest.py"
88
consonant_words = [
9-
'brigantine', 'clipper', 'dreadnought', 'frigate', 'galleon', 'haddock',
10-
'junk', 'ketch', 'longboat', 'mullet', 'narwhal', 'porpoise', 'quay',
11-
'regatta', 'submarine', 'tanker', 'vessel', 'whale', 'xebec', 'yatch',
12-
'zebrafish'
9+
"brigantine",
10+
"clipper",
11+
"dreadnought",
12+
"frigate",
13+
"galleon",
14+
"haddock",
15+
"junk",
16+
"ketch",
17+
"longboat",
18+
"mullet",
19+
"narwhal",
20+
"porpoise",
21+
"quay",
22+
"regatta",
23+
"submarine",
24+
"tanker",
25+
"vessel",
26+
"whale",
27+
"xebec",
28+
"yacht",
29+
"zebrafish",
1330
]
14-
vowel_words = ['aviso', 'eel', 'iceberg', 'octopus', 'upbound']
15-
template = 'Ahoy, Captain, {} {} off the larboard bow!'
31+
vowel_words = ["aviso", "eel", "iceberg", "octopus", "upbound"]
32+
TEMPLATE = "Ahoy, Captain, {} {} off the larboard bow!"
1633

1734

1835
# --------------------------------------------------
1936
def test_exists():
2037
"""exists"""
2138

22-
assert os.path.isfile(prg)
39+
assert os.path.isfile(PRG)
2340

2441

2542
# --------------------------------------------------
2643
def test_usage():
2744
"""usage"""
2845

29-
for flag in ['-h', '--help']:
30-
rv, out = getstatusoutput(f'{prg} {flag}')
46+
for flag in ["-h", "--help"]:
47+
rv, out = getstatusoutput(f"python3 {PRG} {flag}")
3148
assert rv == 0
32-
assert out.lower().startswith('usage')
49+
assert out.lower().startswith("usage")
3350

3451

3552
# --------------------------------------------------
3653
def test_consonant():
3754
"""brigantine -> a brigantine"""
3855

3956
for word in consonant_words:
40-
out = getoutput(f'{prg} {word}')
41-
assert out.strip() == template.format('a', word)
57+
out = getoutput(f"python3 {PRG} {word}")
58+
assert out.strip() == TEMPLATE.format("a", word)
4259

4360

4461
# --------------------------------------------------
4562
def test_consonant_upper():
4663
"""brigantine -> a Brigatine"""
4764

4865
for word in consonant_words:
49-
out = getoutput(f'{prg} {word.title()}')
50-
assert out.strip() == template.format('a', word.title())
66+
out = getoutput(f"python3 {PRG} {word.title()}")
67+
assert out.strip() == TEMPLATE.format("A", word.title())
5168

5269

5370
# --------------------------------------------------
5471
def test_vowel():
5572
"""octopus -> an octopus"""
5673

5774
for word in vowel_words:
58-
out = getoutput(f'{prg} {word}')
59-
assert out.strip() == template.format('an', word)
75+
out = getoutput(f"python3 {PRG} {word}")
76+
assert out.strip() == TEMPLATE.format("an", word)
6077

6178

6279
# --------------------------------------------------
6380
def test_vowel_upper():
6481
"""octopus -> an Octopus"""
6582

6683
for word in vowel_words:
67-
out = getoutput(f'{prg} {word.upper()}')
68-
assert out.strip() == template.format('an', word.upper())
84+
out = getoutput(f"python3 {PRG} {word.upper()}")
85+
assert out.strip() == TEMPLATE.format("An", word.upper())

0 commit comments

Comments
 (0)