aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBonfaceKilz2022-02-24 09:00:49 +0300
committerBonfaceKilz2022-03-12 15:33:09 +0300
commita4ae3a4d1bb680f8a0d38d37f8ceffe0f3a1b2a9 (patch)
treea0ea343627038cbcb246a86e0d75965e04f18f61 /tests
parent83bfe825ece64807a96280fda9cb4ef3e8ac0587 (diff)
downloadgenenetwork3-a4ae3a4d1bb680f8a0d38d37f8ceffe0f3a1b2a9.tar.gz
Add methods for working with csv data
gn3/csvcmp.py: New file (create_dirs_if_not_exists): From a list of dirs, create them if they don't exist. (remove_insignificant_edits): Given a dict with a "Modification" key, remove edits with "delta < ε". (csv_diff): Generate a csv_diff using the "csvdiff" tool packaged in guix. tests/unit/test_csvcmp.py: Add some tests for "gn3/csvcmp.py"
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_csvcmp.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/unit/test_csvcmp.py b/tests/unit/test_csvcmp.py
new file mode 100644
index 0000000..f73865d
--- /dev/null
+++ b/tests/unit/test_csvcmp.py
@@ -0,0 +1,41 @@
+from gn3.csvcmp import csv_diff
+from gn3.csvcmp import remove_insignificant_edits
+
+import pytest
+
+
+@pytest.mark.unit_test
+def test_remove_insignificant_data():
+ diff_data = {
+ 'Additions': [],
+ 'Deletions': [],
+ 'Modifications': [
+ {'Current': '1.000001,3', 'Original': '1,3'},
+ {'Current': '1,3', 'Original': '1.000001,3'},
+ {'Current': '2.000001,3', 'Original': '2,2'},
+ {'Current': '1.01,3', 'Original': '1,2'}
+ ]
+ }
+ expected_json = {
+ 'Additions': [],
+ 'Deletions': [],
+ 'Modifications': [
+ {'Current': '2,3', 'Original': '2,2'},
+ {'Current': '1.01,3', 'Original': '1,2'}
+ ]
+ }
+ assert (remove_insignificant_edits(diff_data) ==
+ expected_json)
+
+
+@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)