diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2020-07-21 01:42:34 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2020-07-21 01:43:57 +0100 |
commit | 659910ee8196e04b24ce96d9b4ccb7ed93aed6ac (patch) | |
tree | 9c7b4c5a8f04c9c7283de105b69b911266f0781d /tests/testutils.py | |
parent | cecff195fc17a83d593dd62c239aa188883a844e (diff) | |
download | psycopg2-659910ee8196e04b24ce96d9b4ccb7ed93aed6ac.tar.gz |
Allow most of the async tests to pass on CockroachDB
Added function to get crdb version from a connection
Diffstat (limited to 'tests/testutils.py')
-rw-r--r-- | tests/testutils.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/testutils.py b/tests/testutils.py index 26f6cc7..42f940c 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -407,6 +407,38 @@ def skip_if_windows(cls): return decorator(cls) +def crdb_version(conn, __crdb_version=[]): + """ + Return the CockroachDB version if that's the db testing, else None. + + Return the number as an integer similar to PQserverVersion: return + v20.1.3 as 200103. + + Assume all the connections are on the same db: return a chached result on + following runs. + + """ + if __crdb_version: + return __crdb_version[0] + + with conn.cursor() as cur: + try: + cur.execute("show crdb_version") + except psycopg2.ProgrammingError: + __crdb_version.append(None) + else: + sver = cur.fetchone()[0] + m = re.search(r"\bv(\d+)\.(\d+)\.(\d+)", sver) + if not m: + raise ValueError( + "can't parse CockroachDB version from %s" % sver) + + ver = int(m.group(1)) * 10000 + int(m.group(2)) * 100 + int(m.group(3)) + __crdb_version.append(ver) + + return __crdb_version[0] + + class py3_raises_typeerror(object): def __enter__(self): pass |