-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtest.py
executable file
·95 lines (69 loc) · 2.5 KB
/
test.py
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
#!/usr/bin/env python3
"""tests for ransom.py"""
import os
import re
import random
from subprocess import getstatusoutput
prg = './ransom.py'
fox = '../inputs/fox.txt'
now = '../inputs/now.txt'
# --------------------------------------------------
def seed_flag():
return '-s' if random.randint(0, 1) else '--seed'
# --------------------------------------------------
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_text1():
"""Test"""
in_text = 'The quick brown fox jumps over the lazy dog.'
tests = [('1', 'thE QUICk BrOWn Fox jumpS OveR tHe LAzY dOg.'),
('3', 'thE quICk BROwn Fox jUmPS OVEr the lAZY DOG.')]
for seed, expected in tests:
rv, out = getstatusoutput(f'{prg} {seed_flag()} {seed} "{in_text}"')
assert rv == 0
assert out.strip() == expected
# --------------------------------------------------
def test_text2():
"""Test"""
in_text = 'Now is the time for all good men to come to the aid of the party.'
tests = [
('2',
'now iS the TIME fOR ALl good meN TO COMe To THE AID oF THE PArTY.'),
('5',
'NOw is tHE Time FOr all good men To coME TO tHe AiD OF THe ParTy.')
]
for seed, expected in tests:
rv, out = getstatusoutput(f'{prg} {seed_flag()} {seed} "{in_text}"')
assert rv == 0
assert out.strip() == expected
# --------------------------------------------------
def test_file1():
"""Test"""
tests = [('1', 'thE QUICk BrOWn Fox jumpS OveR tHe LAzY dOg.'),
('3', 'thE quICk BROwn Fox jUmPS OVEr the lAZY DOG.')]
for seed, expected in tests:
rv, out = getstatusoutput(f'{prg} {seed_flag()} {seed} {fox}')
assert rv == 0
assert out.strip() == expected
# --------------------------------------------------
def test_file2():
"""Test"""
tests = [
('2',
'now iS the TIME fOR ALl good meN TO COMe To THE AID oF THE PArTY.'),
('5',
'NOw is tHE Time FOr all good men To coME TO tHe AiD OF THe ParTy.')
]
for seed, expected in tests:
rv, out = getstatusoutput(f'{prg} {seed_flag()} {seed} {now}')
assert rv == 0
assert out.strip() == expected