def test_timedelta_sql_discovery_hour_minute(freq): # these always compare equal to a seconds timedelta, because no data loss # will occur with this heuristic. this implies that the sa.Table was # constructed with day_precision == 0 and second_precision == 0 ds = '{name: string, amount: int, duration: timedelta[unit="%s"]}' % freq t = dshape_to_table('td_bank', ds) assert discover(t).measure['duration'] == datashape.TimeDelta('s')
def test_dshape_to_table_with_timedelta(freq, secp, dayp): ds = '{name: string, amount: int, duration: timedelta[unit="%s"]}' % freq t = dshape_to_table('td_bank', ds) assert isinstance(t, sa.Table) assert t.name == 'td_bank' assert isinstance(t.c.duration.type, sa.types.Interval) assert t.c.duration.type.second_precision == secp assert t.c.duration.type.day_precision == dayp
def test_into_table_iterator(): engine = sa.create_engine('sqlite:///:memory:') metadata = sa.MetaData(engine) t = dshape_to_table('points', '{x: int, y: int}', metadata=metadata) t.create() data = [(1, 1), (2, 4), (3, 9)] append(t, data) assert convert(list, t) == data assert isinstance(convert(list, t)[0], tuple) t2 = dshape_to_table('points2', '{x: int, y: int}', metadata=metadata) t2.create() data2 = [{'x': 1, 'y': 1}, {'x': 2, 'y': 4}, {'x': 3, 'y': 9}] append(t2, data2) assert convert(list, t2) == data
def test_into_table_iterator(): engine = sa.create_engine("sqlite:///:memory:") metadata = sa.MetaData(engine) t = dshape_to_table("points", "{x: int, y: int}", metadata=metadata) t.create() data = [(1, 1), (2, 4), (3, 9)] append(t, data) assert convert(list, t) == data assert isinstance(convert(list, t)[0], tuple) t2 = dshape_to_table("points2", "{x: int, y: int}", metadata=metadata) t2.create() data2 = [{"x": 1, "y": 1}, {"x": 2, "y": 4}, {"x": 3, "y": 9}] append(t2, data2) assert convert(list, t2) == data
def test_timedelta_sql_discovery(freq): ds = '{name: string, amount: int, duration: timedelta[unit="%s"]}' % freq t = dshape_to_table('td_bank', ds) assert discover(t).measure['duration'] == datashape.TimeDelta(freq)
def test_dshape_to_table_year(): ds = '{name: string, amount: int, duration: timedelta[unit="Y"]}' dshape_to_table('td_bank', ds)
def test_dshape_to_table(): t = dshape_to_table('bank', '{name: string, amount: int}') assert isinstance(t, sa.Table) assert t.name == 'bank' assert [c.name for c in t.c] == ['name', 'amount']
def test_dshape_to_table_month(): ds = '{name: string, amount: int, duration: timedelta[unit="M"]}' dshape_to_table("td_bank", ds)
def test_dshape_to_table(): t = dshape_to_table("bank", "{name: string, amount: int}") assert isinstance(t, sa.Table) assert t.name == "bank" assert [c.name for c in t.c] == ["name", "amount"]