-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathend-to-end-test.py
More file actions
86 lines (73 loc) · 2.93 KB
/
Copy pathend-to-end-test.py
File metadata and controls
86 lines (73 loc) · 2.93 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
import shutil
import subprocess
import os
import unittest
class EndToEndTest(unittest.TestCase):
def setUp(self):
self.work_file_path = self.__get_test_path("test_file")
self.tearDown()
def tearDown(self):
if os.path.isfile(self.work_file_path):
os.remove(self.work_file_path)
# NOTE: result.stdout and stderr may be interesting
def __run_script(self, command):
full_command = f"python better-space.py {command}";
result = subprocess.run(full_command, text=True, capture_output=True)
if result.returncode != 0:
raise RuntimeError(f"Error code ({result.returncode}) from command: {full_command}\r{result.stderr}")
return result
def __get_test_path(self, subpath):
return os.path.join("test", subpath)
def __read_file(self, path, encoding):
with open(path, encoding=encoding) as f:
return f.read()
def __verify(self, src_file_name, expected_file_name, command, encoding):
'''
Copies source file to temp/test path, runs command on it then compares (possibly modified)
file to the expected content.
If the test fails, determining what's wrong is not easy :(
'''
src_file = self.__get_test_path(src_file_name)
shutil.copyfile(src_file, self.work_file_path)
self.__run_script(command)
expected = self.__read_file(self.__get_test_path(expected_file_name), encoding)
actual = self.__read_file(self.work_file_path, encoding)
self.assertEqual(actual, expected)
def test_default_conform_utf8(self):
self.__verify(
"a-orig-utf8.h",
"a-leading_detabbed-and-trimmed-utf8.h",
f"--update {self.work_file_path}",
"utf-8")
def test_default_conform_utf16(self):
self.__verify(
"a-orig-utf16.h",
"a-leading_detabbed-and-trimmed-utf16.h",
f"--update {self.work_file_path}",
"utf-16")
def test_trim_trailing_utf8(self):
self.__verify(
"a-orig-utf8.h",
"a-trimmed-utf8.h",
f"--update --tab-operation none {self.work_file_path}",
"utf-8")
def test_trim_trailing_utf16(self):
self.__verify(
"a-orig-utf16.h",
"a-trimmed-utf16.h",
f"--update --tab-operation none {self.work_file_path}",
"utf-16")
def test_detab_code(self):
self.__verify(
"a-orig-utf8.h",
"a-detabbed-utf8.h",
f"--update --tab-operation detab-code --leave-trailing {self.work_file_path}",
"utf-8")
def test_entab_leading(self):
self.__verify(
"a-orig-utf8.h",
"a-entabbed-leading-utf8.h",
f"--update --tab-operation entab-leading --leave-trailing {self.work_file_path}",
"utf-8")
if __name__ == '__main__':
unittest.main()