github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/acceptance/testdata/python/test.py (about) 1 import decimal 2 import sys 3 import psycopg2 4 5 conn = psycopg2.connect('') 6 cur = conn.cursor() 7 cur.execute("SELECT 1, 2+{}".format(sys.argv[1])) 8 v = cur.fetchall() 9 assert v == [(1, 5)] 10 11 # Verify #6597 (timestamp format) is fixed. 12 cur = conn.cursor() 13 cur.execute("SELECT now()") 14 v = cur.fetchall() 15 16 # Verify round-trip of strings containing backslashes. 17 # https://github.com/cockroachdb/cockroachdb-python/issues/23 18 s = ('\\\\',) 19 cur.execute("SELECT %s", s) 20 v = cur.fetchall() 21 assert v == [s], (v, s) 22 23 # Verify decimals with exponents can be parsed. 24 cur = conn.cursor() 25 cur.execute("SELECT 1e1::decimal") 26 v = cur.fetchall() 27 d = v[0][0] 28 assert type(d) is decimal.Decimal 29 # Use of compare_total here guarantees that we didn't just get '10' back, we got '1e1'. 30 assert d.compare_total(decimal.Decimal('1e1')) == 0 31 32 # Verify arrays with strings can be parsed. 33 cur = conn.cursor() 34 cur.execute("SELECT ARRAY['foo','bar','baz']") 35 v = cur.fetchall() 36 d = v[0][0] 37 assert d == ["foo","bar","baz"] 38 39 # Verify JSON values come through properly. 40 cur = conn.cursor() 41 cur.execute("SELECT '{\"a\":\"b\"}'::JSONB") 42 v = cur.fetchall() 43 d = v[0][0] 44 assert d == {"a": "b"}