Skip to content

Commit

Permalink
Tests - assert single values in tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin committed Nov 14, 2024
1 parent 09bc69d commit d8dfc67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 2 additions & 6 deletions test_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ def generate_test(src_path, file, res_path, _unused):
f'\n assert a == {{}}'
f'\n return'
f'\n all_reader.add(a[\'metadata\'][\'reader\'])'
f'\n assert len(a[\'tables\']) == len(b[\'tables\'])'
f'\n for idx, table in enumerate(a[\'tables\']):'
f'\n for key in [\'header\', \'metadata\', \'columns\',\'rows\']:'
f'\n assert table[key] == b[\'tables\'][idx][key]'
f'\n compare_tables(a[\'tables\'], b[\'tables\'])'
f'\n assert a[\'metadata\'][\'extension\'] == b[\'metadata\'][\'extension\']'
f'\n assert a[\'metadata\'][\'reader\'] == b[\'metadata\'][\'reader\']'
f'\n assert a[\'metadata\'][\'mime_type\'] == b[\'metadata\'][\'mime_type\']')
Expand All @@ -100,8 +97,7 @@ def generate_test(src_path, file, res_path, _unused):
TEST_DICT = {}
with open(TEST_FILE, 'w+', encoding='utf8') as fp:
fp.write("import pytest\n"
"import json\n"
"from .utils_test import compare_reader_result\n"
"from .utils_test import compare_reader_result, compare_tables\n"
"from converter_app.readers import READERS as registry\n"
"\nall_reader = set()\n")
basic_walk(generate_test)
Expand Down
10 changes: 10 additions & 0 deletions test_manager/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@

FLASK_APP = None

def compare_tables(tables_res, tables_exp):
assert len(tables_res) == len(tables_exp)
for idx, table_res in enumerate(tables_res):
assert '\n'.join(table_res['header']) == '\n'.join(tables_exp[idx]['header'])
for key, value_res in table_res['metadata'].items():
assert value_res == tables_exp[idx]['metadata'][key]
assert table_res['columns'] == tables_exp[idx]['columns']
assert hash(json.dumps(table_res['rows'], sort_keys=True)) == hash(json.dumps(tables_exp[idx]['rows'], sort_keys=True))


def compare_reader_result(src_path, res_path, file):
expected_result = {}
try:
Expand Down

0 comments on commit d8dfc67

Please sign in to comment.