From 8a7335cdb3fe9e906cefa719e336a7266a9b253b Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Fri, 25 Feb 2022 12:08:02 +0300 Subject: Don't add extra key "Column" to dict if there are no changes gn3/csvcmp.py (csv_diff): If the diff is empty, don't add an extra key "Column" to the dictionary. tests/unit/test_csvcmp (test_csv_diff_only_column_change): Add test-case for the above. --- gn3/csvcmp.py | 3 ++- tests/unit/test_csvcmp.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gn3/csvcmp.py b/gn3/csvcmp.py index 453c97a..ebd323e 100644 --- a/gn3/csvcmp.py +++ b/gn3/csvcmp.py @@ -66,7 +66,8 @@ def csv_diff(base_csv, delta_csv, tmp_dir="/tmp"): "--format json")) if _r.get("code") == 0: _r = json.loads(_r.get("output")) - _r["Columns"] = max(base_csv_header, delta_csv_header) + if any(_r.values()): + _r["Columns"] = max(base_csv_header, delta_csv_header) else: _r = {} diff --git a/tests/unit/test_csvcmp.py b/tests/unit/test_csvcmp.py index 023415d..4a96f99 100644 --- a/tests/unit/test_csvcmp.py +++ b/tests/unit/test_csvcmp.py @@ -77,3 +77,25 @@ BXD15,14,x,x""" 'Deletions': [], 'Modifications': [{'Current': 'BXD12,16,x,x,1', 'Original': 'BXD12,16,x,x,x'}]}) + + +@pytest.mark.unit_test +def test_csv_diff_only_column_change(): + 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 +BXD14,15,x,x +BXD15,14,x,x +""" + assert(csv_diff(base_csv=base_csv, + delta_csv=delta_csv) == { + 'Additions': [], + 'Deletions': [], + 'Modifications': []}) -- cgit v1.2.3