aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/test_data_helpers.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-11-01 07:09:26 +0300
committerBonfaceKilz2021-11-04 12:45:57 +0300
commitff23701bbfd90799f04fdf21c482f113bb408e34 (patch)
tree333f0def96018bfa3a315f22d24cea267a9da013 /tests/unit/test_data_helpers.py
parent4a6be7e1b6514f3c7db8c672970b27e27ecde305 (diff)
downloadgenenetwork3-ff23701bbfd90799f04fdf21c482f113bb408e34.tar.gz
Parse single line from CSV file
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * gn3/data_helpers.py: New function (parse_csv_line) * tests/unit/test_data_helpers.py: Add tests for new function (parse_csv_line) Add a function to parse a single line from a CSV file.
Diffstat (limited to 'tests/unit/test_data_helpers.py')
-rw-r--r--tests/unit/test_data_helpers.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/unit/test_data_helpers.py b/tests/unit/test_data_helpers.py
index 1eec3cc..39aea45 100644
--- a/tests/unit/test_data_helpers.py
+++ b/tests/unit/test_data_helpers.py
@@ -4,7 +4,7 @@ Test functions in gn3.data_helpers
from unittest import TestCase
-from gn3.data_helpers import partition_all
+from gn3.data_helpers import partition_all, parse_csv_line
class TestDataHelpers(TestCase):
"""
@@ -35,3 +35,27 @@ class TestDataHelpers(TestCase):
((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), ))):
with self.subTest(n=count, items=items):
self.assertEqual(partition_all(count, items), expected)
+
+ def test_parse_csv_line(self):
+ """
+ Test parsing a single line from a CSV file
+
+ Given:
+ - `line`: a line read from a csv file
+ - `delimiter`: the expected delimiter in the csv file
+ - `quoting`: the quoting enclosing each column in the csv file
+ When:
+ - `line` is parsed with the `parse_csv_file` with the given
+ parameters
+ Then:
+ - return a tuple of the columns in the CSV file, without the
+ delimiter and quoting
+ """
+ for line, delimiter, quoting, expected in (
+ ('"this","is","a","test"', ",", '"', ("this", "is", "a", "test")),
+ ('"this","is","a","test"', ",", None, ('"this"', '"is"', '"a"', '"test"'))):
+ with self.subTest(line=line, delimiter=delimiter, quoting=quoting):
+ self.assertEqual(
+ parse_csv_line(
+ line=line, delimiter=delimiter, quoting=quoting),
+ expected)