forked from allejo/jekyll-toc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
33 lines (26 loc) · 925 Bytes
/
tests.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
import os
import re
import unittest
import xml.etree.ElementTree as ET
class TestSequense(unittest.TestCase):
pass
def test_generator(a, b):
def test(self):
self.assertEqual(a, b)
return test
def normalize_xml(xml):
tree = ET.fromstring(xml)
return re.sub('\\n\s+', '', ET.tostring(tree))
if __name__ == '__main__':
test_path = os.path.join(os.getcwd(), '_site', 'tests')
for test_file in os.listdir(test_path):
path = os.path.join(test_path, test_file)
with open(path, 'r') as file:
actual, expected = file.read().split('<!-- /// -->')
actual = normalize_xml(actual)
expected = normalize_xml(expected)
# Add the unit test to our TestSequense
test_name = 'test_{}'.format(test_file)
test = test_generator(actual, expected)
setattr(TestSequense, test_name, test)
unittest.main()