-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
66 lines (58 loc) · 1.69 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
import unittest
import os
from rt import main as prog
class TestRt(unittest.TestCase):
INPUTS = [
"""
hello A hello B
hello C
HeLlO W
""",
"""
🐞
goodbye 👽
""",
""
]
OUTPUTS = [
"""
goodbye A goodbye B
goodbye C
HeLlO W
""",
"""
🐞
replaced 👽
""",
""
]
def setUp(self):
for i, txt in enumerate(self.INPUTS, start=1):
with open(f'/tmp/in{i}.txt','w') as f:
f.write(txt)
def test_defaults(self):
p = prog("--input-file /tmp/in1.txt --output-file /tmp/out1.txt".split())
with open('/tmp/out1.txt') as f:
self.assertEqual(f.read(), self.OUTPUTS[0])
os.remove('/tmp/out1.txt')
def test_custom(self):
p = prog("--input-file /tmp/in2.txt --output-file /tmp/out2.txt --search goodbye --replace replaced".split())
with open('/tmp/out2.txt') as f:
self.assertEqual(f.read(), self.OUTPUTS[1])
os.remove('/tmp/out2.txt')
def test_empy(self):
p = prog("--input-file /tmp/in3.txt --output-file /tmp/out3.txt".split())
with open('/tmp/out3.txt') as f:
self.assertEqual(f.read(), self.OUTPUTS[2])
os.remove('/tmp/out3.txt')
def test_delete(self):
with open(f'/tmp/in0.txt','w') as f:
f.write(self.INPUTS[0])
p = prog("--input-file /tmp/in0.txt --output-file /tmp/out0.txt --delete".split())
self.assertFalse(os.path.exists('/tmp/in0.txt'))
os.remove('/tmp/out0.txt')
def tearDown(self):
for i in range(1,len(self.INPUTS)+1):
os.remove(f'/tmp/in{i}.txt')
if __name__ == "__main__":
unittest.main()