File: test_fixed.py

package info (click to toggle)
python-agate 1.13.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,008 kB
  • sloc: python: 8,578; makefile: 126
file content (46 lines) | stat: -rw-r--r-- 1,687 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import unittest

from agate import csv, fixed


class TestFixed(unittest.TestCase):
    def test_reader(self):
        with open('examples/testfixed_converted.csv') as f:
            csv_reader = csv.Reader(f)
            csv_header = next(csv_reader)
            csv_data = list(csv_reader)

        with open('examples/testfixed') as f:
            with open('examples/testfixed_schema.csv') as schema_f:
                fixed_reader = fixed.Reader(f, schema_f)
                fixed_data = list(fixed_reader)

        self.assertEqual(csv_header, fixed_reader.fieldnames)
        self.assertEqual(csv_data, fixed_data)

    def test_reader_func(self):
        with open('examples/testfixed_converted.csv') as f:
            csv_reader = csv.reader(f)
            csv_header = next(csv_reader)
            csv_data = list(csv_reader)

        with open('examples/testfixed') as f:
            with open('examples/testfixed_schema.csv') as schema_f:
                fixed_reader = fixed.reader(f, schema_f)
                fixed_data = list(fixed_reader)

        self.assertEqual(csv_header, fixed_reader.fieldnames)
        self.assertEqual(csv_data, fixed_data)

    def test_dict_reader(self):
        with open('examples/testfixed_converted.csv') as f:
            csv_reader = csv.DictReader(f)
            csv_data = list(csv_reader)

        with open('examples/testfixed') as f:
            with open('examples/testfixed_schema.csv') as schema_f:
                fixed_reader = fixed.DictReader(f, schema_f)
                fixed_data = list(fixed_reader)

        self.assertEqual(csv_reader.fieldnames, fixed_reader.fieldnames)
        self.assertEqual(csv_data, fixed_data)