示例#1
0
 def test_into(self):
     with filetext('1,1\n2,2', extension='.csv') as a:
         with tmpfile(extension='.csv') as b:
             A = resource(a, schema='{x: int, y: int}')
             B = resource(b, schema='{x: int, y: int}', mode='a')
             B = into(B, A)
             assert into(list, B) == [(1, 1), (2, 2)]
示例#2
0
 def test_filesystem(self):
     prefix = 'test_filesystem'
     d = {prefix + 'a.csv': '1,1\n2,2',
          prefix + 'b.csv': '1,1\n2,2'}
     with filetexts(d) as filenames:
         dd = resource(prefix + '*.csv', schema='{x: int, y: int}')
         self.assertEqual(into(list, dd),
                         [(1, 1), (2, 2), (1, 1), (2, 2)])
示例#3
0
 def test_hdf5(self):
     with tmpfile('.hdf5') as filename:
         assert isinstance(resource(filename + '::/path/to/data/',
                                    schema='2 * int'),
                           HDF5)
示例#4
0
 def test_sql(self):
     with tmpfile('.db') as filename:
         assert isinstance(resource('sqlite:///%s::tablename' % filename,
                                    schema='{x: int, y: int}'),
                           SQL)
示例#5
0
 def test_resource_gz(self):
     with filetext('1,1\n2,2', extension='.csv.gz', open=gzip.open) as fn:
         dd = resource(fn, schema='{x: int, y: int}')
         assert isinstance(dd, CSV)
         self.assertEqual(dd.open, gzip.open)
         self.assertEqual(into(list, dd), [(1, 1), (2, 2)])
示例#6
0
def test_into_xlsx_file():
    pytest.importorskip('xlrd')
    fn = os.path.join(dirname, 'accounts.xlsx')
    assert isinstance(resource(fn), Excel)
示例#7
0
def test_resource_csv():
    fn = os.path.join(dirname, 'accounts_1.csv')
    assert isinstance(resource(fn), CSV)