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
·118 lines (77 loc) · 2.59 KB
/
test.py
File metadata and controls
executable file
·118 lines (77 loc) · 2.59 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python3
"""tests for days.py"""
import os
import random
import re
import string
from subprocess import getstatusoutput
prg = './days.py'
# --------------------------------------------------
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 run_day(day, expected):
"""Run a day"""
rv, out = getstatusoutput(f'{prg} {day}')
assert rv == 0
assert out == expected
# --------------------------------------------------
def test_monday():
"""Monday"""
run_day('Monday', 'On Mondays I never go to work')
# --------------------------------------------------
def test_tuesday():
"""Tuesday"""
run_day('Tuesday', 'On Tuesdays I stay at home')
# --------------------------------------------------
def test_wednesday():
"""Wednesday"""
run_day('Wednesday', 'On Wednesdays I never feel inclined')
# --------------------------------------------------
def test_thursday():
"""Thursday"""
run_day('Thursday', "On Thursdays, it's a holiday")
# --------------------------------------------------
def test_friday():
"""Friday"""
run_day('Friday', 'And Fridays I detest')
# --------------------------------------------------
def test_saturday():
"""Saturday"""
run_day('Saturday', "Oh, it's much too late on a Saturday")
# --------------------------------------------------
def test_sunday():
"""Sunday"""
run_day('Sunday', 'And Sunday is the day of rest')
# --------------------------------------------------
def test_lower():
"""monday"""
for day in [
'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday',
'sunday'
]:
rv, out = getstatusoutput(f'{prg} {day}')
assert rv == 0
assert out == f'Can\'t find "{day}"'
# --------------------------------------------------
def test_monday_tuesday():
"""Monday Tuesday"""
run_day(
'Monday Tuesday', '\n'.join(
['On Mondays I never go to work', 'On Tuesdays I stay at home']))
# --------------------------------------------------
def test_mix():
"""Mix good and bad"""
run_day(
'Sunday Odinsday Thorsday Friday', '\n'.join([
'And Sunday is the day of rest', "Can't find \"Odinsday\"",
"Can't find \"Thorsday\"", 'And Fridays I detest'
]))