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
·83 lines (58 loc) · 1.91 KB
/
Copy pathtest.py
File metadata and controls
executable file
·83 lines (58 loc) · 1.91 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
#!/usr/bin/env python3
"""tests for scrambler.py"""
import os
import re
from subprocess import getstatusoutput, getoutput
prg = './scrambler.py'
fox = '../inputs/fox.txt'
bustle = '../inputs/the-bustle.txt'
spiders = '../inputs/spiders.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_text1():
"""Text"""
out = getoutput(f'{prg} foobar -s 1')
assert out.strip() == 'faobor'
# --------------------------------------------------
def test_text2():
"""Text"""
text = 'The quick brown fox jumps over the lazy dog.'
expected = 'The qicuk bworn fox jpmus over the lzay dog.'
out = getoutput(f'{prg} "{text}" -s 2')
assert out.strip() == expected
# --------------------------------------------------
def test_file_bustle():
"""File input"""
expected = """
The blutse in a hosue
The mrinong afetr daeth
Is seosnmelt of iinuetdrss
Etecand upon etrah,--
The sweenipg up the herat,
And pniuttg lvoe away
We slahl not want to use again
Unitl eettnriy.
""".strip()
out = getoutput(f'{prg} --seed 3 {bustle}')
assert out.strip() == expected.strip()
# --------------------------------------------------
def test_file_fox():
"""File input"""
out = getoutput(f'{prg} --seed 4 {fox}')
assert out.strip() == 'The qciuk bworn fox jpums oevr the lzay dog.'
# --------------------------------------------------
def test_file_spiders():
"""File input"""
out = getoutput(f'{prg} --seed 9 {spiders}')
expected = "Do'nt wrory, sedrpis,\nI keep hsoue\ncalusaly."
assert out.strip() == expected