|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""tests for crowsnest.py""" |
| 3 | + |
| 4 | +import os |
| 5 | +from subprocess import getstatusoutput, getoutput |
| 6 | + |
| 7 | +prg = './crowsnest.py' |
| 8 | +consonant_words = [ |
| 9 | + 'brigatine', 'clipper', 'dreadnought', 'frigate', 'galleon', 'haddock', |
| 10 | + 'junk', 'ketch', 'longboat', 'mullet', 'narwhal', 'porpoise', 'quay', |
| 11 | + 'regatta', 'submarine', 'tanker', 'vessel', 'whale', 'xebec', 'yatch', |
| 12 | + 'zebrafish' |
| 13 | +] |
| 14 | +vowel_words = ['aviso', 'eel', 'iceberg', 'octopus', 'upbound'] |
| 15 | +template = 'Ahoy, Captain, {} {} off the larboard bow!' |
| 16 | + |
| 17 | + |
| 18 | +# -------------------------------------------------- |
| 19 | +def test_exists(): |
| 20 | + """exists""" |
| 21 | + |
| 22 | + assert os.path.isfile(prg) |
| 23 | + |
| 24 | + |
| 25 | +# -------------------------------------------------- |
| 26 | +def test_usage(): |
| 27 | + """usage""" |
| 28 | + |
| 29 | + for flag in ['-h', '--help']: |
| 30 | + rv, out = getstatusoutput(f'{prg} {flag}') |
| 31 | + assert rv == 0 |
| 32 | + assert out.lower().startswith('usage') |
| 33 | + |
| 34 | + |
| 35 | +# -------------------------------------------------- |
| 36 | +def test_consonant(): |
| 37 | + """brigatine -> a brigatine""" |
| 38 | + |
| 39 | + for word in consonant_words: |
| 40 | + out = getoutput(f'{prg} {word}') |
| 41 | + assert out.strip() == template.format('a', word) |
| 42 | + |
| 43 | + |
| 44 | +# -------------------------------------------------- |
| 45 | +def test_consonant_upper(): |
| 46 | + """brigatine -> a Brigatine""" |
| 47 | + |
| 48 | + for word in consonant_words: |
| 49 | + out = getoutput(f'{prg} {word.title()}') |
| 50 | + assert out.strip() == template.format('a', word.title()) |
| 51 | + |
| 52 | + |
| 53 | +# -------------------------------------------------- |
| 54 | +def test_vowel(): |
| 55 | + """octopus -> an octopus""" |
| 56 | + |
| 57 | + for word in vowel_words: |
| 58 | + out = getoutput(f'{prg} {word}') |
| 59 | + assert out.strip() == template.format('an', word) |
| 60 | + |
| 61 | + |
| 62 | +# -------------------------------------------------- |
| 63 | +def test_vowel_upper(): |
| 64 | + """octopus -> an Octopus""" |
| 65 | + |
| 66 | + for word in vowel_words: |
| 67 | + out = getoutput(f'{prg} {word.upper()}') |
| 68 | + assert out.strip() == template.format('an', word.upper()) |
0 commit comments