def test_interval_in(con): con.register_in_adapter(1186, pg8000.converters.pginterval_in) retval = con.run( "SELECT '1 month 16 days 12 hours 32 minutes 64 seconds'::interval") expected_value = pg8000.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_interval_in(con, cursor): con.register_in_adapter(1186, pg8000.converters.pginterval_in) cursor.execute( "SELECT '1 month 16 days 12 hours 32 minutes 64 seconds'::interval") expected_value = pg8000.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_interval_roundtrip(con): con.register_in_adapter(1186, converters.pginterval_in) v = pg8000.PGInterval(microseconds=123456789, days=2, months=24) retval = con.run("SELECT cast(:v as interval)", v=v) assert retval[0][0] == v
def test_interval_in_1_year(): assert converters.pginterval_in('1 year') == pg8000.PGInterval(years=1)
def test_interval_repr(): v = pg8000.PGInterval(microseconds=123456789, days=2, months=24) assert repr(v) == '<PGInterval 24 months 2 days 123456789 microseconds>'
def test_interval_roundtrip(con, cursor): con.register_in_adapter(1186, converters.pginterval_in) v = pg8000.PGInterval(microseconds=123456789, days=2, months=24) cursor.execute("SELECT cast(%s as interval)", (v, )) assert cursor.fetchall()[0][0] == v