|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""tests for days.py""" |
| 3 | + |
| 4 | +import os |
| 5 | +import random |
| 6 | +import re |
| 7 | +import string |
| 8 | +from subprocess import getstatusoutput |
| 9 | + |
| 10 | +prg = './days.py' |
| 11 | + |
| 12 | + |
| 13 | +# -------------------------------------------------- |
| 14 | +def test_exists(): |
| 15 | + """exists""" |
| 16 | + |
| 17 | + assert os.path.isfile(prg) |
| 18 | + |
| 19 | + |
| 20 | +# -------------------------------------------------- |
| 21 | +def test_usage(): |
| 22 | + """usage""" |
| 23 | + |
| 24 | + for flag in ['-h', '--help']: |
| 25 | + rv, out = getstatusoutput(f'{prg} {flag}') |
| 26 | + assert rv == 0 |
| 27 | + assert out.lower().startswith('usage') |
| 28 | + |
| 29 | + |
| 30 | +# -------------------------------------------------- |
| 31 | +def run_day(day, expected): |
| 32 | + """Run a day""" |
| 33 | + |
| 34 | + rv, out = getstatusoutput(f'{prg} {day}') |
| 35 | + assert rv == 0 |
| 36 | + assert out == expected |
| 37 | + |
| 38 | + |
| 39 | +# -------------------------------------------------- |
| 40 | +def test_monday(): |
| 41 | + """Monday""" |
| 42 | + |
| 43 | + run_day('Monday', 'On Mondays I never go to work') |
| 44 | + |
| 45 | + |
| 46 | +# -------------------------------------------------- |
| 47 | +def test_tuesday(): |
| 48 | + """Tuesday""" |
| 49 | + |
| 50 | + run_day('Tuesday', 'On Tuesdays I stay at home') |
| 51 | + |
| 52 | + |
| 53 | +# -------------------------------------------------- |
| 54 | +def test_wednesday(): |
| 55 | + """Wednesday""" |
| 56 | + |
| 57 | + run_day('Wednesday', 'On Wednesdays I never feel inclined') |
| 58 | + |
| 59 | + |
| 60 | +# -------------------------------------------------- |
| 61 | +def test_thursday(): |
| 62 | + """Thursday""" |
| 63 | + |
| 64 | + run_day('Thursday', "On Thursdays, it's a holiday") |
| 65 | + |
| 66 | + |
| 67 | +# -------------------------------------------------- |
| 68 | +def test_friday(): |
| 69 | + """Friday""" |
| 70 | + |
| 71 | + run_day('Friday', 'And Fridays I detest') |
| 72 | + |
| 73 | + |
| 74 | +# -------------------------------------------------- |
| 75 | +def test_saturday(): |
| 76 | + """Saturday""" |
| 77 | + |
| 78 | + run_day('Saturday', "Oh, it's much too late on a Saturday") |
| 79 | + |
| 80 | + |
| 81 | +# -------------------------------------------------- |
| 82 | +def test_sunday(): |
| 83 | + """Sunday""" |
| 84 | + |
| 85 | + run_day('Sunday', 'And Sunday is the day of rest') |
| 86 | + |
| 87 | + |
| 88 | +# -------------------------------------------------- |
| 89 | +def test_lower(): |
| 90 | + """monday""" |
| 91 | + |
| 92 | + for day in [ |
| 93 | + 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', |
| 94 | + 'sunday' |
| 95 | + ]: |
| 96 | + rv, out = getstatusoutput(f'{prg} {day}') |
| 97 | + assert rv == 0 |
| 98 | + assert out == f'Can\'t find "{day}"' |
| 99 | + |
| 100 | + |
| 101 | +# -------------------------------------------------- |
| 102 | +def test_monday_tuesday(): |
| 103 | + """Monday Tuesday""" |
| 104 | + |
| 105 | + run_day( |
| 106 | + 'Monday Tuesday', '\n'.join( |
| 107 | + ['On Mondays I never go to work', 'On Tuesdays I stay at home'])) |
| 108 | + |
| 109 | + |
| 110 | +# -------------------------------------------------- |
| 111 | +def test_mix(): |
| 112 | + """Mix good and bad""" |
| 113 | + |
| 114 | + run_day( |
| 115 | + 'Sunday Odinsday Thorsday Friday', '\n'.join([ |
| 116 | + 'And Sunday is the day of rest', "Can't find \"Odinsday\"", |
| 117 | + "Can't find \"Thorsday\"", 'And Fridays I detest' |
| 118 | + ])) |
0 commit comments