aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/csvcmp.py11
-rw-r--r--tests/unit/test_csvcmp.py17
2 files changed, 28 insertions, 0 deletions
diff --git a/gn3/csvcmp.py b/gn3/csvcmp.py
index 35133dc..7a4a026 100644
--- a/gn3/csvcmp.py
+++ b/gn3/csvcmp.py
@@ -67,3 +67,14 @@ def csv_diff(base_csv, delta_csv, tmp_dir="/tmp"):
if os.path.exists(file_name2):
os.remove(file_name2)
return _r
+
+
+def fill_csv(csv_text, width, value="x"):
+ data = []
+ for line in csv_text.strip().split("\n"):
+ if line.startswith("Strain") or line.startswith("#"):
+ data.append(line)
+ elif line:
+ data.append(
+ ",".join((_n:=line.split(",")) + [value] * (width - len(_n))))
+ return "\n".join(data)
diff --git a/tests/unit/test_csvcmp.py b/tests/unit/test_csvcmp.py
index f73865d..716adb5 100644
--- a/tests/unit/test_csvcmp.py
+++ b/tests/unit/test_csvcmp.py
@@ -1,10 +1,27 @@
from gn3.csvcmp import csv_diff
+from gn3.csvcmp import fill_csv
from gn3.csvcmp import remove_insignificant_edits
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
+BXD15,14,x,x
+"""
+ expected_output = """Strain Name,Value,SE,Count,Sex
+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"))
+
+@pytest.mark.unit_test
def test_remove_insignificant_data():
diff_data = {
'Additions': [],