def test_interval_in(con, cursor): con.register_in_adapter(INTERVAL, pg_interval_in) cursor.execute("SELECT '1 month 16 days 12 hours 32 minutes 64 seconds'::interval") expected_value = PGInterval( microseconds=(12 * 60 * 60 * 1000 * 1000) + (32 * 60 * 1000 * 1000) + (64 * 1000 * 1000), days=16, months=1, ) assert cursor.fetchall()[0][0] == expected_value
def test_pg_interval_in(con): con.register_in_adapter(1186, pg_interval_in) retval = con.run( "SELECT CAST('1 month 16 days 12 hours 32 minutes 64 seconds' as INTERVAL)" ) expected_value = PGInterval( microseconds=(12 * 60 * 60 * 1000 * 1000) + (32 * 60 * 1000 * 1000) + (64 * 1000 * 1000), days=16, months=1, ) assert retval[0][0] == expected_value
def test_pg_interval_in_1_year(): assert pg_interval_in("1 year") == PGInterval(years=1)
def test_PGInterval_str(): v = PGInterval(microseconds=123456789, days=2, months=24, millennia=2) assert str(v) == "2 millennia 24 months 2 days 123456789 microseconds"
def test_PGInterval_repr(): v = PGInterval(microseconds=123456789, days=2, months=24) assert repr(v) == "<PGInterval 24 months 2 days 123456789 microseconds>"
def test_PGInterval_init(): i = PGInterval(days=1) assert i.months is None assert i.days == 1 assert i.microseconds is None
def test_interval_roundtrip(con): con.register_in_adapter(INTERVAL, pg_interval_in) con.register_out_adapter(PGInterval, INTERVAL, pg_interval_out) v = PGInterval(microseconds=123456789, days=2, months=24) retval = con.run("SELECT cast(:v as interval)", v=v) assert retval[0][0] == v
def test_pg_interval_roundtrip(con, cursor): con.register_in_adapter(INTERVAL, pg_interval_in) con.register_out_adapter(PGInterval, pg_interval_out) v = PGInterval(microseconds=123456789, days=2, months=24) cursor.execute("SELECT cast(%s as interval)", (v,)) assert cursor.fetchall()[0][0] == v
def test_pg_interval_str(): v = PGInterval(microseconds=123456789, days=2, months=24) assert str(v) == "24 months 2 days 123456789 microseconds"