def test_iterates_csv_with_header(self): from collections import OrderedDict data = arrayfiles.read_csv(self.fp.name, header=True) header = self.lines[0].split(',') expected = [ OrderedDict(zip(header, line.split(','))) for line in self.lines[1:] ] for i, (x, y) in enumerate(zip(data, expected)): self.assertEqual(x, y) self.assertEqual(data[i], y)
def test_eager_load(self): text1 = arrayfiles.read_csv(self.fp.name, lazy=False) text2 = arrayfiles.read_csv(self.fp.name, lazy=True) for a, b in zip(text1, text2): self.assertEqual(a, b)
def test_iterates_csv_without_header(self): data = arrayfiles.read_csv(self.fp.name, header=False) expected = [line.split(',') for line in self.lines] self.assertSequenceEqual(data, expected) for x, y in zip(data, expected): self.assertEqual(x, y)
def test_loads_csv_with_header(self): data = arrayfiles.read_csv(self.fp.name, header=True) self.assertTrue(data._header)
def test_slices_items(self): data = arrayfiles.read_csv(self.fp.name) self.assertSequenceEqual(data[:len(self.lines)], data)
def test_dunder_init(self): data = arrayfiles.read_csv(self.fp.name) self.assertEqual(data._path, self.fp.name) self.assertEqual(data._encoding, 'utf-8') self.assertEqual(data._delimiter, ',') self.assertFalse(data._header)