From 0c1a6fb91b8bf9cf2b68ba54d8905e4c6acfd341 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Fri, 25 Feb 2022 11:37:00 +0300 Subject: Test edges cases for csv files when running csvdiff * tests/unit/test_csvcmp.py (test_csv_diff): Delete it. (test_csv_diff_same_columns): Test csv_diff against csv texts with the same columns. (test_csv_diff_different_columns): Test csv texts against csv texts with different varying columns. --- tests/integration/test_partial_correlations.py | 1 + tests/unit/test_csvcmp.py | 41 +++++++++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/tests/integration/test_partial_correlations.py b/tests/integration/test_partial_correlations.py index d249b42..4bf352a 100644 --- a/tests/integration/test_partial_correlations.py +++ b/tests/integration/test_partial_correlations.py @@ -212,6 +212,7 @@ def test_partial_correlation_api_with_non_existent_control_traits(client, post_d # difficult to test for these without a temp database with the temp # traits data set to something we are in control of ) + def test_part_corr_api_with_mix_of_existing_and_non_existing_control_traits( db_conn, primary, controls, method, target): """ diff --git a/tests/unit/test_csvcmp.py b/tests/unit/test_csvcmp.py index 716adb5..023415d 100644 --- a/tests/unit/test_csvcmp.py +++ b/tests/unit/test_csvcmp.py @@ -46,13 +46,34 @@ def test_remove_insignificant_data(): @pytest.mark.unit_test -def test_csv_diff(): - test_results = csv_diff(base_csv="a,b\n1,2\n", - delta_csv="a,b\n1,3") - _json = { - 'Additions': [], - 'Deletions': [], - 'Modifications': [{'Current': '1,3', 'Original': '1,2'}] - } - assert(test_results.get("code") == 0 and - test_results.get("output") == _json) +def test_csv_diff_same_columns(): + assert(csv_diff(base_csv="a,b\n1,2\n", + delta_csv="a,b\n1,3") == { + 'Additions': [], + 'Deletions': [], + 'Columns': '', + 'Modifications': [{'Current': '1,3', + 'Original': '1,2'}]}) + + +@pytest.mark.unit_test +def test_csv_diff_different_columns(): + base_csv = """ +Strain Name,Value,SE,Count +BXD1,18,x,0 +BXD12,16,x,x +BXD14,15,x,x +BXD15,14,x,x +""" + delta_csv = """Strain Name,Value,SE,Count,Sex +BXD1,18,x,0 +BXD12,16,x,x,1 +BXD14,15,x,x +BXD15,14,x,x""" + assert(csv_diff(base_csv=base_csv, + delta_csv=delta_csv) == { + 'Additions': [], + 'Columns': 'Strain Name,Value,SE,Count,Sex', + 'Deletions': [], + 'Modifications': [{'Current': 'BXD12,16,x,x,1', + 'Original': 'BXD12,16,x,x,x'}]}) -- cgit v1.2.3