aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-11-01 07:09:26 +0300
committerFrederick Muriuki Muriithi2021-11-01 07:09:26 +0300
commit21c8c341956bb3c9cac427ab5b951976d70f4245 (patch)
tree7d4a67cc8639a2ae3bc06add0793a9f36fac98db /tests/unit
parent1a7b59a4d58c21759c265e5b5f413a533c1a2293 (diff)
downloadgenenetwork3-21c8c341956bb3c9cac427ab5b951976d70f4245.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')
-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)