summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2020-07-21 01:55:22 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2020-07-21 22:21:24 +0100
commitee34198bf6a16080bb71d8ab68b354380745b3a8 (patch)
tree56cc6824c319bedc20fc2676fe530416e1b3da92
parent659910ee8196e04b24ce96d9b4ccb7ed93aed6ac (diff)
downloadpsycopg2-ee34198bf6a16080bb71d8ab68b354380745b3a8.tar.gz
All the sync tests pass on CockroachDB
Added decorator to skip tests on crdb
-rwxr-xr-xtests/test_async.py15
-rw-r--r--tests/testutils.py13
2 files changed, 23 insertions, 5 deletions
diff --git a/tests/test_async.py b/tests/test_async.py
index 6738c07..fbb5809 100755
--- a/tests/test_async.py
+++ b/tests/test_async.py
@@ -34,7 +34,7 @@ import psycopg2.errors
from psycopg2 import extensions as ext
from .testutils import (ConnectingTestCase, StringIO, skip_before_postgres,
- crdb_version, slow)
+ skip_if_crdb, crdb_version, slow)
class PollableStub(object):
@@ -114,7 +114,6 @@ class AsyncTests(ConnectingTestCase):
self.wait(cur)
self.assertFalse(self.conn.isexecuting())
- self.assertEquals(cur.fetchall()[0][0], '')
@slow
def test_async_after_async(self):
@@ -355,6 +354,7 @@ class AsyncTests(ConnectingTestCase):
self.assertEquals(cur.fetchone()[0], 1)
@slow
+ @skip_if_crdb
def test_notify(self):
cur = self.conn.cursor()
sync_cur = self.sync_conn.cursor()
@@ -399,11 +399,12 @@ class AsyncTests(ConnectingTestCase):
self.assertRaises(psycopg2.IntegrityError, self.wait, cur)
cur.execute("insert into table1 values (%s); "
"insert into table1 values (%s)", (2, 2))
- # this should fail as well
+ # this should fail as well (Postgres behaviour)
self.assertRaises(psycopg2.IntegrityError, self.wait, cur)
# but this should work
- cur.execute("insert into table1 values (%s)", (2, ))
- self.wait(cur)
+ if crdb_version(self.sync_conn) is None:
+ cur.execute("insert into table1 values (%s)", (2, ))
+ self.wait(cur)
# and the cursor should be usable afterwards
cur.execute("insert into table1 values (%s)", (3, ))
self.wait(cur)
@@ -431,6 +432,7 @@ class AsyncTests(ConnectingTestCase):
self.wait(cur2)
self.assertEquals(cur2.fetchone()[0], 1)
+ @skip_if_crdb
def test_notices(self):
del self.conn.notices[:]
cur = self.conn.cursor()
@@ -455,6 +457,7 @@ class AsyncTests(ConnectingTestCase):
self.wait(self.conn)
self.assertEqual(cur.fetchone(), (42,))
+ @skip_if_crdb
def test_async_connection_error_message(self):
try:
cnn = psycopg2.connect('dbname=thisdatabasedoesntexist', async_=True)
@@ -472,6 +475,7 @@ class AsyncTests(ConnectingTestCase):
self.assertRaises(psycopg2.ProgrammingError, self.wait, self.conn)
@slow
+ @skip_if_crdb
@skip_before_postgres(9, 0)
def test_non_block_after_notification(self):
from select import select
@@ -505,6 +509,7 @@ class AsyncTests(ConnectingTestCase):
def test_poll_noop(self):
self.conn.poll()
+ @skip_if_crdb
@skip_before_postgres(9, 0)
def test_poll_conn_for_notification(self):
with self.conn.cursor() as cur:
diff --git a/tests/testutils.py b/tests/testutils.py
index 42f940c..a23457e 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -439,6 +439,19 @@ def crdb_version(conn, __crdb_version=[]):
return __crdb_version[0]
+@decorate_all_tests
+def skip_if_crdb(f):
+ """Skip a test or test class if we are testing against CockroachDB."""
+
+ @wraps(f)
+ def skip_if_crdb_(self):
+ if crdb_version(self.connect()) is not None:
+ self.skipTest("not supported on CockroachDB")
+ return f(self)
+
+ return skip_if_crdb_
+
+
class py3_raises_typeerror(object):
def __enter__(self):
pass