Skip to content

Commit

Permalink
Unskip tests that work on CockroachDB v22.1
Browse files Browse the repository at this point in the history
CockroachDB supports named cursors in v22.1, so more tests pass.
  • Loading branch information
rafiss authored and dvarrazzo committed Mar 28, 2022
1 parent 6260783 commit 3c58e96
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
6 changes: 3 additions & 3 deletions tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def test_async_fetch_wrong_cursor(self):
# fetching from the correct cursor works
self.assertEquals(cur1.fetchone()[0], 1)

@skip_if_crdb("batch statements", version="< 22.1")
def test_error(self):
cur = self.conn.cursor()
cur.execute("insert into table1 values (%s)", (1, ))
Expand All @@ -402,9 +403,8 @@ def test_error(self):
# this should fail as well (Postgres behaviour)
self.assertRaises(psycopg2.IntegrityError, self.wait, cur)
# but this should work
if crdb_version(self.sync_conn) is None:
cur.execute("insert into table1 values (%s)", (2, ))
self.wait(cur)
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)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def test_pgresult_ptr(self):
self.assert_(curs.pgresult_ptr is None)


@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
class NamedCursorTests(ConnectingTestCase):
def test_invalid_name(self):
curs = self.conn.cursor()
Expand All @@ -436,6 +436,7 @@ def _create_withhold_table(self):
curs.execute("insert into withhold values (%s)", (i,))
curs.close()

@skip_if_crdb("cursor with hold")
def test_withhold(self):
self.assertRaises(psycopg2.ProgrammingError, self.conn.cursor,
withhold=True)
Expand All @@ -460,6 +461,7 @@ def test_withhold(self):
curs.execute("drop table withhold")
self.conn.commit()

@skip_if_crdb("cursor with hold")
def test_withhold_no_begin(self):
self._create_withhold_table()
curs = self.conn.cursor("w", withhold=True)
Expand All @@ -484,6 +486,7 @@ def test_withhold_no_begin(self):
self.assertEqual(self.conn.info.transaction_status,
psycopg2.extensions.TRANSACTION_STATUS_IDLE)

@skip_if_crdb("cursor with hold")
def test_withhold_autocommit(self):
self._create_withhold_table()
self.conn.commit()
Expand All @@ -506,6 +509,7 @@ def test_withhold_autocommit(self):
self.assertEqual(self.conn.info.transaction_status,
psycopg2.extensions.TRANSACTION_STATUS_IDLE)

@skip_if_crdb("scroll cursor")
def test_scrollable(self):
self.assertRaises(psycopg2.ProgrammingError, self.conn.cursor,
scrollable=True)
Expand Down Expand Up @@ -679,6 +683,7 @@ def test_scroll(self):
self.assertRaises((IndexError, psycopg2.ProgrammingError),
cur.scroll, 1)

@skip_if_crdb("scroll cursor")
@skip_before_postgres(8, 0)
def test_scroll_named(self):
cur = self.conn.cursor('tmp', scrollable=True)
Expand Down
28 changes: 14 additions & 14 deletions tests/test_extras_dictcursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _testNamedCursorNotGreedy(self, curs):
class ExtrasDictCursorTests(_DictCursorBase):
"""Test if DictCursor extension class works."""

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
def testDictConnCursorArgs(self):
self.conn.close()
self.conn = self.connect(connection_factory=psycopg2.extras.DictConnection)
Expand Down Expand Up @@ -132,19 +132,19 @@ def getter(curs):
return row
self._testWithNamedCursor(getter)

@skip_if_crdb("named cursor")
@skip_if_crdb("greedy cursor")
@skip_before_postgres(8, 2)
def testDictCursorWithNamedCursorNotGreedy(self):
curs = self.conn.cursor('tmp', cursor_factory=psycopg2.extras.DictCursor)
self._testNamedCursorNotGreedy(curs)

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
@skip_before_postgres(8, 0)
def testDictCursorWithNamedCursorIterRowNumber(self):
curs = self.conn.cursor('tmp', cursor_factory=psycopg2.extras.DictCursor)
self._testIterRowNumber(curs)

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
def _testWithNamedCursor(self, getter):
curs = self.conn.cursor('aname', cursor_factory=psycopg2.extras.DictCursor)
curs.execute("SELECT * FROM ExtrasDictCursorTests")
Expand Down Expand Up @@ -285,19 +285,19 @@ def getter(curs):
return row
self._testWithNamedCursorReal(getter)

@skip_if_crdb("named cursor")
@skip_if_crdb("greedy cursor")
@skip_before_postgres(8, 2)
def testDictCursorRealWithNamedCursorNotGreedy(self):
curs = self.conn.cursor('tmp', cursor_factory=psycopg2.extras.RealDictCursor)
self._testNamedCursorNotGreedy(curs)

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
@skip_before_postgres(8, 0)
def testDictCursorRealWithNamedCursorIterRowNumber(self):
curs = self.conn.cursor('tmp', cursor_factory=psycopg2.extras.RealDictCursor)
self._testIterRowNumber(curs)

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
def _testWithNamedCursorReal(self, getter):
curs = self.conn.cursor('aname',
cursor_factory=psycopg2.extras.RealDictCursor)
Expand Down Expand Up @@ -376,7 +376,7 @@ def setUp(self):
curs.execute("INSERT INTO nttest VALUES (3, 'baz')")
self.conn.commit()

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
def test_cursor_args(self):
cur = self.conn.cursor('foo', cursor_factory=psycopg2.extras.DictCursor)
self.assertEqual(cur.name, 'foo')
Expand Down Expand Up @@ -533,7 +533,7 @@ def f_patched(self_):
finally:
NamedTupleCursor._make_nt = f_orig

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
@skip_before_postgres(8, 0)
def test_named(self):
curs = self.conn.cursor('tmp')
Expand All @@ -544,28 +544,28 @@ def test_named(self):
recs.extend(curs.fetchall())
self.assertEqual(list(range(10)), [t.i for t in recs])

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
def test_named_fetchone(self):
curs = self.conn.cursor('tmp')
curs.execute("""select 42 as i""")
t = curs.fetchone()
self.assertEqual(t.i, 42)

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
def test_named_fetchmany(self):
curs = self.conn.cursor('tmp')
curs.execute("""select 42 as i""")
recs = curs.fetchmany(10)
self.assertEqual(recs[0].i, 42)

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
def test_named_fetchall(self):
curs = self.conn.cursor('tmp')
curs.execute("""select 42 as i""")
recs = curs.fetchall()
self.assertEqual(recs[0].i, 42)

@skip_if_crdb("named cursor")
@skip_if_crdb("greedy cursor")
@skip_before_postgres(8, 2)
def test_not_greedy(self):
curs = self.conn.cursor('tmp')
Expand All @@ -580,7 +580,7 @@ def test_not_greedy(self):
self.assert_(recs[1].ts - recs[0].ts < timedelta(seconds=0.005))
self.assert_(recs[2].ts - recs[1].ts > timedelta(seconds=0.0099))

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
@skip_before_postgres(8, 0)
def test_named_rownumber(self):
curs = self.conn.cursor('tmp')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_green.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_errors_on_query(self):

self.fail("you should have had a success or an error by now")

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
def test_errors_named_cursor(self):
for i in range(100):
self.to_error = None
Expand Down
4 changes: 2 additions & 2 deletions tests/test_with.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def close(self):
self.assert_(curs.closed)
self.assert_(closes)

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
def test_exception_swallow(self):
# bug #262: __exit__ calls cur.close() that hides the exception
# with another error.
Expand All @@ -304,7 +304,7 @@ def test_exception_swallow(self):
else:
self.fail("where is my exception?")

@skip_if_crdb("named cursor")
@skip_if_crdb("named cursor", version="< 22.1")
@skip_before_postgres(8, 2)
def test_named_with_noop(self):
with self.conn.cursor('named'):
Expand Down
3 changes: 3 additions & 0 deletions tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,13 @@ def skip_if_crdb__(self, *args, **kwargs):
crdb_reasons = {
"2-phase commit": 22329,
"backend pid": 35897,
"batch statements": 44803,
"cancel": 41335,
"cast adds tz": 51692,
"cidr": 18846,
"composite": 27792,
"copy": 41608,
"cursor with hold": 77101,
"deferrable": 48307,
"encoding": 35882,
"hstore": 41284,
Expand All @@ -483,6 +485,7 @@ def skip_if_crdb__(self, *args, **kwargs):
"notify": 41522,
"password_encryption": 42519,
"range": 41282,
"scroll cursor": 77102,
"stored procedure": 1751,
}

Expand Down

0 comments on commit 3c58e96

Please sign in to comment.