aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/csvcmp.py6
-rw-r--r--tests/unit/test_csvcmp.py10
2 files changed, 10 insertions, 6 deletions
diff --git a/gn3/csvcmp.py b/gn3/csvcmp.py
index 360a101..eef64b5 100644
--- a/gn3/csvcmp.py
+++ b/gn3/csvcmp.py
@@ -92,6 +92,10 @@ def fill_csv(csv_text, width, value="x"):
if line.startswith("Strain") or line.startswith("#"):
data.append(line)
elif line:
+ _n = line.split(",")
+ for i, val in enumerate(_n):
+ if not val.strip():
+ _n[i] = value
data.append(
- ",".join((_n:=line.split(",")) + [value] * (width - len(_n))))
+ ",".join(_n + [value] * (width - len(_n))))
return "\n".join(data)
diff --git a/tests/unit/test_csvcmp.py b/tests/unit/test_csvcmp.py
index fd7aa28..3c9ba33 100644
--- a/tests/unit/test_csvcmp.py
+++ b/tests/unit/test_csvcmp.py
@@ -9,10 +9,10 @@ import pytest
@pytest.mark.unit_test
def test_fill_csv():
test_input = """
-Strain Name,Value,SE,Count
-BXD1,18,x,0
-BXD12,16,x,x
-BXD14,15,x,x
+Strain Name,Value,SE,Count,Sex
+BXD1,18,x,0,
+BXD12,16,x,x,
+BXD14,15,x,x,
BXD15,14,x,x
"""
expected_output = """Strain Name,Value,SE,Count,Sex
@@ -20,7 +20,7 @@ BXD1,18,x,0,x
BXD12,16,x,x,x
BXD14,15,x,x,x
BXD15,14,x,x,x"""
- assert(fill_csv(test_input, width=5, value="x"))
+ assert(fill_csv(test_input, width=5, value="x") == expected_output)
@pytest.mark.unit_test
def test_remove_insignificant_data():