summaryrefslogtreecommitdiff
path: root/test/dialect/test_postgresql.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-11-18 18:57:33 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-11-18 18:57:33 -0500
commitfd4f39648aa7949e2c64626982e401fcbc928e1f (patch)
treea9560d579187be26727e6d2958951cc10f704893 /test/dialect/test_postgresql.py
parent39fddb8bda933eb0e7835eed09656f6992b3ac58 (diff)
parent2336b1cebfcb2f304e09cbc2a0e8bb3fb3a9ceeb (diff)
downloadsqlalchemy-fd4f39648aa7949e2c64626982e401fcbc928e1f.tar.gz
merge tip
Diffstat (limited to 'test/dialect/test_postgresql.py')
-rw-r--r--test/dialect/test_postgresql.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py
index 3bc22f2a3..2b6642349 100644
--- a/test/dialect/test_postgresql.py
+++ b/test/dialect/test_postgresql.py
@@ -456,7 +456,25 @@ class EnumTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL):
assert t2.c.value2.type.schema == 'test_schema'
finally:
metadata.drop_all()
+
+class NumericInterpretationTest(TestBase):
+
+
+ def test_numeric_codes(self):
+ from sqlalchemy.dialects.postgresql import pg8000, psycopg2, base
+ from decimal import Decimal
+ for dialect in (pg8000.dialect(), psycopg2.dialect()):
+
+ typ = Numeric().dialect_impl(dialect)
+ for code in base._INT_TYPES + base._FLOAT_TYPES + \
+ base._DECIMAL_TYPES:
+ proc = typ.result_processor(dialect, code)
+ val = 23.7
+ if proc is not None:
+ val = proc(val)
+ assert val in (23.7, Decimal("23.7"))
+
class InsertTest(TestBase, AssertsExecutionResults):
__only_on__ = 'postgresql'
@@ -1866,6 +1884,64 @@ class SpecialTypesTest(TestBase, ComparesTables):
assert t.c.plain_interval.type.precision is None
assert t.c.precision_interval.type.precision == 3
+class UUIDTest(TestBase):
+ """Test the bind/return values of the UUID type."""
+
+ __only_on__ = 'postgresql'
+
+ @testing.fails_on('postgresql+pg8000', 'No support for UUID type')
+ def test_uuid_string(self):
+ import uuid
+ self._test_round_trip(
+ Table('utable', MetaData(),
+ Column('data', postgresql.UUID())
+ ),
+ str(uuid.uuid4()),
+ str(uuid.uuid4())
+ )
+
+ @testing.fails_on('postgresql+pg8000', 'No support for UUID type')
+ def test_uuid_uuid(self):
+ import uuid
+ self._test_round_trip(
+ Table('utable', MetaData(),
+ Column('data', postgresql.UUID(as_uuid=True))
+ ),
+ uuid.uuid4(),
+ uuid.uuid4()
+ )
+
+ def test_no_uuid_available(self):
+ from sqlalchemy.dialects.postgresql import base
+ uuid_type = base._python_UUID
+ base._python_UUID = None
+ try:
+ assert_raises(
+ NotImplementedError,
+ postgresql.UUID, as_uuid=True
+ )
+ finally:
+ base._python_UUID = uuid_type
+
+ def setup(self):
+ self.conn = testing.db.connect()
+ trans = self.conn.begin()
+
+ def teardown(self):
+ self.conn.close()
+
+ def _test_round_trip(self, utable, value1, value2):
+ utable.create(self.conn)
+ self.conn.execute(utable.insert(), {'data':value1})
+ self.conn.execute(utable.insert(), {'data':value2})
+ r = self.conn.execute(
+ select([utable.c.data]).
+ where(utable.c.data != value1)
+ )
+ eq_(r.fetchone()[0], value2)
+ eq_(r.fetchone(), None)
+
+
class MatchTest(TestBase, AssertsCompiledSQL):
__only_on__ = 'postgresql'