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
·79 lines (58 loc) · 1.79 KB
/
test.py
File metadata and controls
executable file
·79 lines (58 loc) · 1.79 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
#!/usr/bin/env python3
"""tests for gematria.py"""
import os
import re
from subprocess import getstatusoutput, getoutput
prg = './gematria.py'
spiders = '../inputs/spiders.txt'
fox = '../inputs/fox.txt'
sonnet = '../inputs/sonnet-29.txt'
# --------------------------------------------------
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 re.match("usage", out, re.IGNORECASE)
# --------------------------------------------------
def test_text():
"""Text"""
out = getoutput(f'{prg} "foo bar baz"')
assert out.strip() == '324 309 317'
# --------------------------------------------------
def test_fox():
"""File"""
out = getoutput(f'{prg} {fox}')
assert out.strip() == '289 541 552 333 559 444 321 448 314'
# --------------------------------------------------
def test_spiders():
"""File"""
out = getoutput(f'{prg} {spiders}')
assert out.strip() == '405 579 762\n73 421 548\n862'
# --------------------------------------------------
def test_sonnet():
"""File"""
out = getoutput(f'{prg} {sonnet}')
expected = """
631 107
719 1132
402 215 834 444 771 307 435 438
73 313 527 632 230 771 545
275 765 400 631 444 230 875 534
275 437 450 656 307 546 230 416
729 210 421 227 322 435 422 215 428
816 421 318 421 318 444 747 985
821 440 431 327 307 433 431 538
412 436 73 451 549 964 537
306 215 537 886 656 656 966
510 73 542 221 422 307 431 230 545
389 227 321 426 213 517 213 318 749
404 659 532 548 559 213 746 417
295 341 552 438 1048 435 645 645
401 431 73 549 227 614 230 545 444 540
""".strip()
assert out.strip() == expected