示例#1
0
 def test_bom_from_csv(self):
     path = os.path.join(self.tempdir, 'input.csv')
     with open(path, 'wb') as fp:
         fp.write(SAMPLE_CSV_BOM_DATA.encode('utf-8'))
     tbl = agate_helper.from_csv(path)
     self.assertEqual(len(tbl), len(EXPECTED))
     for idx, row in enumerate(tbl):
         self.assertEqual(list(row), EXPECTED[idx])
示例#2
0
 def test_from_csv_all_reserved(self):
     path = os.path.join(self.tempdir, 'input.csv')
     with open(path, 'wb') as fp:
         fp.write(SAMPLE_CSV_DATA.encode('utf-8'))
     tbl = agate_helper.from_csv(path, tuple('abcdefg'))
     self.assertEqual(len(tbl), len(EXPECTED_STRINGS))
     for expected, row in zip(EXPECTED_STRINGS, tbl):
         self.assertEqual(list(row), expected)
示例#3
0
 def test_datetime_formats(self):
     path = os.path.join(self.tempdir, 'input.csv')
     datetimes = [
         '20180806T11:33:29.000Z',
         '20180806T11:33:29Z',
         '20180806T113329Z',
     ]
     expected = datetime(2018, 8, 6, 11, 33, 29, 0, tzinfo=tzinfo.Utc())
     for dt in datetimes:
         with open(path, 'wb') as fp:
             fp.write('a\n{}'.format(dt).encode('utf-8'))
         tbl = agate_helper.from_csv(path, ())
         self.assertEqual(tbl[0][0], expected)
示例#4
0
 def load_agate_table(self) -> agate.Table:
     if not isinstance(self.model, (ParsedSeedNode, CompiledSeedNode)):
         raise_compiler_error(
             'can only load_agate_table for seeds (got a {})'.format(
                 self.model.resource_type))
     path = os.path.join(self.model.root_path,
                         self.model.original_file_path)
     column_types = self.model.config.column_types
     try:
         table = agate_helper.from_csv(path, text_columns=column_types)
     except ValueError as e:
         raise_compiler_error(str(e))
     table.original_abspath = os.path.abspath(path)
     return table