Skip to content

Commit 5b2d3b2

Browse files
jarofgreenBjwebb
authored andcommitted
tests: Seperate a big test out to individual tests
This means if one part only fails, you can rerun just that part - much faster!
1 parent d33dbc2 commit 5b2d3b2

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

flattentool/tests/test_docs.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,41 @@
33
import subprocess
44
import sys
55
import uuid
6+
import pytest
67

78
from os.path import join, getsize
89

910

10-
def test_examples_in_docs():
11+
examples_in_docs_data = []
1112

13+
def _get_examples_in_docs_data():
14+
global examples_in_docs_data
15+
examples_in_docs_data = []
16+
for root, dirs, files in os.walk('examples'):
17+
for filename in files:
18+
if 'xlsx' in root and sys.version_info[:2] < (3,4):
19+
continue
20+
if 'cmd.txt' in filename:
21+
examples_in_docs_data.append((root, filename))
22+
23+
_get_examples_in_docs_data()
24+
25+
26+
def test_examples_receipt():
1227
with open('examples/receipt/source-map/expected.json', 'rb') as fp:
1328
expected = fp.read()
1429
for expected_filename in [
1530
'normalised/expected.json',
1631
'combine-table-into-cafe/expected.json',
1732
'combine-table-into-cafe-2/expected.json',
1833
]:
19-
with open('examples/receipt/'+expected_filename, 'rb') as fp2:
20-
assert fp2.read() == expected, "Files differ: examples/receipt/source-map/expected.json, examples/receipt/{}".format(expected_filename)
21-
tests_passed = 0
22-
for root, dirs, files in os.walk('examples'):
23-
for filename in files:
24-
if 'xlsx' in root and sys.version_info[:2] < (3,4):
25-
continue
26-
if 'cmd.txt' in filename:
34+
with open('examples/receipt/' + expected_filename, 'rb') as fp2:
35+
assert fp2.read() == expected, "Files differ: examples/receipt/source-map/expected.json, examples/receipt/{}".format(
36+
expected_filename)
37+
38+
39+
@pytest.mark.parametrize("root, filename", examples_in_docs_data)
40+
def test_example_in_doc(root, filename):
2741
if os.path.exists(join(root, 'actual')) and os.path.isdir(join(root, 'actual')):
2842
os.rename(join(root, 'actual'), join(root, 'actual.'+str(uuid.uuid4())))
2943
os.mkdir(join(root, 'actual'))
@@ -95,9 +109,11 @@ def test_examples_in_docs():
95109
else:
96110
expected_stderr += b'\n'
97111
assert _simplify_warnings(_strip(actual_stderr)) == _simplify_warnings(_strip(expected_stderr)), "Different stderr: {}".format(cmds)
98-
tests_passed += 1
99-
# Check that the number of tests were run that we expected
100-
assert tests_passed == 56
112+
113+
114+
def test_expected_number_of_examples_in_docs_data():
115+
assert len(examples_in_docs_data) == 56
116+
101117

102118
def _simplify_warnings(lines):
103119
return '\n'.join([_simplify_line(line) for line in lines.split('\n')])
@@ -117,4 +133,6 @@ def _strip(output):
117133

118134
# Useful for a coverage check - see developer docs for how to run the check
119135
if __name__ == '__main__':
120-
test_examples_in_docs()
136+
test_examples_receipt()
137+
for root, filename in examples_in_docs_data:
138+
test_example_in_doc(root, filename)

0 commit comments

Comments
 (0)