def test_get_data_rows(self):
     actual_result_A = csv_utils.CSVUtils(csv_A_path).get_data_rows()
     expected_result_A = test_utils.parse_csv_file(data_rows_A_path)
     actual_result_B = csv_utils.CSVUtils(csv_B_path).get_data_rows()
     expected_result_B = test_utils.parse_csv_file(data_rows_B_path)
     self.assertListEqual(actual_result_A, expected_result_A)
     self.assertListEqual(actual_result_B, expected_result_B)
 def test_get_column_names(self):
     csv_utils.CSVUtils(column_names_A_path)
     actual_result_A = csv_utils.CSVUtils(csv_A_path).get_column_names()
     expected_result_A = test_utils.parse_csv_file(column_names_A_path)[0]
     actual_result_B = csv_utils.CSVUtils(csv_B_path).get_column_names()
     expected_result_B = test_utils.parse_csv_file(column_names_B_path)[0]
     self.assertListEqual(actual_result_B, expected_result_B)
     self.assertListEqual(actual_result_A, expected_result_A)
Example #3
0
import os
import unittest
from hone.utils import csv_utils

dirname = os.path.dirname(__file__)
csv_A_path = os.path.join(dirname, "data", "small_cats_dataset.csv")
csv_B_path = os.path.join(dirname, "data", "comma_test.csv")
small_csv = csv_utils.CSVUtils(csv_A_path)
comma_csv = csv_utils.CSVUtils(csv_B_path)


class TestCSVUtils(unittest.TestCase):
    def test_get_column_names(self):
        self.assertListEqual(small_csv.get_column_names(), [
            'name', 'age (years)', 'weight (kg)', 'birth day', 'birth month',
            'birth year', 'adopted', 'adopted_since'
        ])
        self.assertListEqual(comma_csv.get_column_names(),
                             ['test"",""ing', 'beep'])

    def test_get_data_rows(self):
        self.assertListEqual(
            small_csv.get_data_rows(),
            [['Tommy', '5', '3.6', '11', 'April', '2011', 'TRUE', '2012'],
             ['Clara', '2', '8.2', '6', 'May', '2015', 'FALSE', 'N/A'],
             ['Catnip', '6', '3.3', '21', 'August', '2011', 'TRUE', '2017'],
             ['Ciel', '3', '3.1', '18', 'January', '2015', 'TRUE', '2018']])
        self.assertListEqual(comma_csv.get_data_rows(), [['1', '2']])


if __name__ == '__main__':
 def __init__(self, delimiters=DEFAULT_DELIMITERS):
     self.delimiters = delimiters
     self.csv_filepath = None
     self.csv = csv_utils.CSVUtils(self.csv_filepath)
Example #5
0
 def __init__(self):
     self.delimit_chars = [",", "_", " "]
     self.csv_filepath = None
     self.csv = csv_utils.CSVUtils(self.csv_filepath)