about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBonfaceKilz2022-04-01 14:40:10 +0300
committerBonfaceKilz2022-04-01 14:47:17 +0300
commit7d898c70c94d78a7dc81acf43ccfe2cdd7c5172c (patch)
treeef13ba4bcab875a891e3582e0e45b5ca34efc0a5
parent0c6654ec8bd71297ca7d97899933f98d526b6725 (diff)
downloadgenenetwork3-7d898c70c94d78a7dc81acf43ccfe2cdd7c5172c.tar.gz
Run python-black in file
* gn3/csvcmp.py: Run "black -l 79 ..."
* tests/unit/db/test_sample_data.py: Ditto.
* tests/unit/test_csvcmp.py: Ditto.
-rw-r--r--gn3/csvcmp.py17
-rw-r--r--tests/unit/db/test_sample_data.py18
-rw-r--r--tests/unit/test_csvcmp.py54
3 files changed, 63 insertions, 26 deletions
diff --git a/gn3/csvcmp.py b/gn3/csvcmp.py
index 8db89ca..4e8cc0f 100644
--- a/gn3/csvcmp.py
+++ b/gn3/csvcmp.py
@@ -52,8 +52,7 @@ def clean_csv_text(csv_text: str) -> str:
     """Remove extra white space elements in all elements of the CSV file"""
     _csv_text = []
     for line in csv_text.strip().split("\n"):
-        _csv_text.append(
-            ",".join([el.strip() for el in line.split(",")]))
+        _csv_text.append(",".join([el.strip() for el in line.split(",")]))
     return "\n".join(_csv_text)
 
 
@@ -73,8 +72,9 @@ def csv_diff(base_csv, delta_csv, tmp_dir="/tmp") -> dict:
 
     if base_csv_header != delta_csv_header:
         if longest_header != base_csv_header:
-            base_csv = base_csv.replace("Strain Name,Value,SE,Count",
-                                        longest_header, 1)
+            base_csv = base_csv.replace(
+                "Strain Name,Value,SE,Count", longest_header, 1
+            )
         else:
             delta_csv = delta_csv.replace(
                 "Strain Name,Value,SE,Count", longest_header, 1
@@ -89,9 +89,9 @@ def csv_diff(base_csv, delta_csv, tmp_dir="/tmp") -> dict:
         _f.write(fill_csv(delta_csv, width=_l))
 
     # Now we can run the diff!
-    _r = run_cmd(cmd=('"csvdiff '
-                      f"{file_name1} {file_name2} "
-                      '--format json"'))
+    _r = run_cmd(
+        cmd=('"csvdiff ' f"{file_name1} {file_name2} " '--format json"')
+    )
     if _r.get("code") == 0:
         _r = json.loads(_r.get("output", ""))
         if any(_r.values()):
@@ -127,8 +127,7 @@ def get_allowable_sampledata_headers(conn: Any) -> List:
     attributes = ["Strain Name", "Value", "SE", "Count"]
     with conn.cursor() as cursor:
         cursor.execute("SELECT Name from CaseAttribute")
-        attributes += [attributes[0] for attributes in
-                       cursor.fetchall()]
+        attributes += [attributes[0] for attributes in cursor.fetchall()]
     return attributes
 
 
diff --git a/tests/unit/db/test_sample_data.py b/tests/unit/db/test_sample_data.py
index 2524e07..607b278 100644
--- a/tests/unit/db/test_sample_data.py
+++ b/tests/unit/db/test_sample_data.py
@@ -34,11 +34,13 @@ def test_insert_sample_data(mocker):
         )
         calls = [
             mocker.call(
-                "SELECT Id FROM PublishData where Id = %s " "AND StrainId = %s",
+                "SELECT Id FROM PublishData where Id = %s "
+                "AND StrainId = %s",
                 (data_id, strain_id),
             ),
             mocker.call(
-                "INSERT INTO PublishData " "(StrainId, Id, value) VALUES (%s, %s, %s)",
+                "INSERT INTO PublishData "
+                "(StrainId, Id, value) VALUES (%s, %s, %s)",
                 (strain_id, data_id, "18"),
             ),
             mocker.call(
@@ -47,10 +49,13 @@ def test_insert_sample_data(mocker):
                 (strain_id, data_id, "3"),
             ),
             mocker.call(
-                "INSERT INTO NStrain " "(StrainId, DataId, count) VALUES (%s, %s, %s)",
+                "INSERT INTO NStrain "
+                "(StrainId, DataId, count) VALUES (%s, %s, %s)",
                 (strain_id, data_id, "0"),
             ),
-            mocker.call("SELECT Id FROM CaseAttribute WHERE Name = %s", ("Sex",)),
+            mocker.call(
+                "SELECT Id FROM CaseAttribute WHERE Name = %s", ("Sex",)
+            ),
             mocker.call(
                 "SELECT StrainId FROM CaseAttributeXRefNew "
                 "WHERE StrainId = %s AND "
@@ -135,7 +140,10 @@ def test_extract_actions():
     ) == {
         "delete": None,
         "insert": {"data": "BXD1,2,F", "csv_header": "Strain Name,SE,Sex"},
-        "update": {"data": "BXD1,19,1", "csv_header": "Strain Name,Value,Count"},
+        "update": {
+            "data": "BXD1,19,1",
+            "csv_header": "Strain Name,Value,Count",
+        },
     }
 
 
diff --git a/tests/unit/test_csvcmp.py b/tests/unit/test_csvcmp.py
index c2fda6b..0843bef 100644
--- a/tests/unit/test_csvcmp.py
+++ b/tests/unit/test_csvcmp.py
@@ -82,7 +82,9 @@ BXD15,14,x,x"""
         "Additions": [],
         "Columns": "Strain Name,Value,SE,Count,Sex",
         "Deletions": [],
-        "Modifications": [{"Current": "BXD12,16,x,x,1", "Original": "BXD12,16,x,x,x"}],
+        "Modifications": [
+            {"Current": "BXD12,16,x,x,1", "Original": "BXD12,16,x,x,x"}
+        ],
     }
 
 
@@ -113,7 +115,9 @@ BXD15,14,x,x
 def test_extract_strain_name():
     """Test that the strain's name is extracted given a csv header"""
     assert (
-        extract_strain_name(csv_header="Strain Name,Value,SE,Count", data="BXD1,18,x,0")
+        extract_strain_name(
+            csv_header="Strain Name,Value,SE,Count", data="BXD1,18,x,0"
+        )
         == "BXD1"
     )
 
@@ -123,27 +127,53 @@ def test_get_allowable_csv_headers(mocker):
     """Test that all the csv headers are fetched properly"""
     mock_conn = mocker.MagicMock()
     expected_values = [
-        "Strain Name", "Value", "SE", "Count",
-        "Condition", "Tissue", "Sex", "Age",
-        "Ethn.", "PMI (hrs)", "pH", "Color",
+        "Strain Name",
+        "Value",
+        "SE",
+        "Count",
+        "Condition",
+        "Tissue",
+        "Sex",
+        "Age",
+        "Ethn.",
+        "PMI (hrs)",
+        "pH",
+        "Color",
     ]
     with mock_conn.cursor() as cursor:
         cursor.fetchall.return_value = (
-            ('Condition',), ('Tissue',), ('Sex',),
-            ('Age',), ('Ethn.',), ('PMI (hrs)',), ('pH',), ('Color',))
+            ("Condition",),
+            ("Tissue",),
+            ("Sex",),
+            ("Age",),
+            ("Ethn.",),
+            ("PMI (hrs)",),
+            ("pH",),
+            ("Color",),
+        )
         assert get_allowable_sampledata_headers(mock_conn) == expected_values
         cursor.execute.assert_called_once_with(
-            "SELECT Name from CaseAttribute")
+            "SELECT Name from CaseAttribute"
+        )
 
 
 @pytest.mark.unit_test
 def test_extract_invalid_csv_headers_with_some_wrong_headers():
     """Test that invalid column headers are extracted correctly from a csv
-string"""
+    string"""
     allowed_headers = [
-        "Strain Name", "Value", "SE", "Count",
-        "Condition", "Tissue", "Sex", "Age",
-        "Ethn.", "PMI (hrs)", "pH", "Color",
+        "Strain Name",
+        "Value",
+        "SE",
+        "Count",
+        "Condition",
+        "Tissue",
+        "Sex",
+        "Age",
+        "Ethn.",
+        "PMI (hrs)",
+        "pH",
+        "Color",
     ]
 
     csv_text = "Strain Name, Value, SE, Colour"