diff --git a/test_manager/__init__.py b/test_manager/__init__.py index 3d7589bd..612a7341 100644 --- a/test_manager/__init__.py +++ b/test_manager/__init__.py @@ -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\']') @@ -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) diff --git a/test_manager/utils_test.py b/test_manager/utils_test.py index 40ff6ee0..7778f386 100644 --- a/test_manager/utils_test.py +++ b/test_manager/utils_test.py @@ -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: