Skip to content

Commit

Permalink
Tests - assert single values in tables
Browse files Browse the repository at this point in the history
Tests - assert single values in tables

Tests - assert single values in tables

Tests - assert single values in tables

Tests - assert single values in tables

Tests - assert single values in tables

Tests - assert single values in tables

Tests - assert single values in tables

Tests - assert single values in tables

Tests - assert single values in tables
  • Loading branch information
Martin committed Nov 14, 2024
1 parent 5ff8bd1 commit 3d8c75d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
6 changes: 2 additions & 4 deletions test_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +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 is_tables_equal = hash(json.dumps(a[\'tables\'], sort_keys=True)) == hash(json.dumps(b[\'tables\'], sort_keys=True))'
f'\n assert is_tables_equal'
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 @@ -98,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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions test_manager/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@

FLASK_APP = None

def _compare_row_val(val_res:str, val_exp:str):
assert val_res[:3] == val_exp[:3]

def _compare_row(row_res, row_exp):
for idx, val_res in enumerate([str(x) for x in row_res]):
_compare_row_val(val_res, str(row_exp[idx]))

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 len(table_res['rows']) == len(tables_exp[idx]['rows'])
for row_idx, row_res in enumerate(table_res['rows']):
_compare_row(row_res,tables_exp[idx]['rows'][row_idx])


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

0 comments on commit 3d8c75d

Please sign in to comment.