Created
May 5, 2017 23:40
-
-
Save ivarg/b736997b32d1c1f8170a37b5717c84a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestCsvFileSource(unittest.TestCase): | |
CSV_LINES_FILE = """header1,header2,header3 | |
value1,value2,value3 | |
""" | |
def test_gzipped_csv(self): | |
out = StringIO() | |
with tempfile.NamedTemporaryFile() as f: | |
with gzip.GzipFile(filename=f.name, mode='wb') as gz: | |
gz.write(self.CSV_LINES_FILE) | |
csv = CsvFileSource( | |
f.name, | |
compression_type=CompressionTypes.GZIP) | |
# first record as a dict | |
rec = csv.read_records(f.name, None).next() | |
# make a dict from the csv lines | |
lines = self.CSV_LINES_FILE.split('\n') | |
ltup = zip(lines[0].split(','), lines[1].split(',')) | |
ldict = {header: value for (header, value) in ltup} | |
# assert both dicts are equal | |
for (header, value) in rec.iteritems(): | |
self.assertEqual(value, ldict[header]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment