From e3a5ae8e20ed015a816862a2806f2a4e7c6a995e Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Sun, 19 Apr 2009 16:25:49 +0200 Subject: [PATCH] Added a couple of test scripts to sandbox --- sandbox/test-psycopg2-datetime-systematic.py | 70 ++++++++++++++++++++ sandbox/test_notices.py | 12 ++++ setup.cfg | 2 +- setup.py | 2 +- 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 sandbox/test-psycopg2-datetime-systematic.py create mode 100644 sandbox/test_notices.py diff --git a/sandbox/test-psycopg2-datetime-systematic.py b/sandbox/test-psycopg2-datetime-systematic.py new file mode 100644 index 00000000..b7490d2b --- /dev/null +++ b/sandbox/test-psycopg2-datetime-systematic.py @@ -0,0 +1,70 @@ +# ======================================================================= +# $Source: /sources/gnumed/gnumed/gnumed/client/testing/test-psycopg2-datetime-systematic.py,v $ +__version__ = "$Revision: 1.1 $" +__author__ = "K.Hilbert " +__license__ = 'GPL (details at http://www.gnu.org)' +# ======================================================================= + +print "testing psycopg2 date/time parsing" + +import psycopg2 +print "psycopg2:", psycopg2.__version__ + +#dsn = u'dbname=gnumed_v10 user=any-doc password=any-doc' +dsn = u'dbname=test' +print dsn + +conn = psycopg2.connect(dsn=dsn) + +curs = conn.cursor() +cmd = u""" +select + name, + abbrev, + utc_offset::text, + case when + is_dst then 'DST' + else 'non-DST' + end +from pg_timezone_names""" +curs.execute(cmd) +rows = curs.fetchall() +curs.close() +conn.rollback() + +for row in rows: + + curs = conn.cursor() + + tz = row[0] + cmd = u"set timezone to '%s'" % tz + try: + curs.execute(cmd) + except StandardError, e: + print "cannot use time zone", row + raise e + curs.close() + conn.rollback() + continue + + cmd = u"""select '1920-01-19 23:00:00+01'::timestamp with time zone""" + try: + curs.execute(cmd) + curs.fetchone() + except StandardError, e: + print "%s (%s / %s / %s) failed:" % (tz, row[1], row[2], row[3]) + print " ", e + + curs.close() + conn.rollback() + +conn.close() + +# ======================================================================= +# $Log: test-psycopg2-datetime-systematic.py,v $ +# Revision 1.1 2009/02/10 18:45:32 ncq +# - psycopg2 cannot parse a bunch of settable time zones +# +# Revision 1.1 2009/02/10 13:57:03 ncq +# - test for psycopg2 on Ubuntu-Intrepid +# diff --git a/sandbox/test_notices.py b/sandbox/test_notices.py new file mode 100644 index 00000000..fafa9697 --- /dev/null +++ b/sandbox/test_notices.py @@ -0,0 +1,12 @@ +def test(): + import sys, os, thread, psycopg2 + def test2(): + while True: + for filename in map(lambda m: getattr(m, "__file__", None), sys.modules.values()): + os.stat("/dev/null") + connection = psycopg2.connect(database="test") + cursor = connection.cursor() + thread.start_new_thread(test2, ()) + while True: + cursor.execute("COMMIT") +test() diff --git a/setup.cfg b/setup.cfg index 6b458e01..1d6b2157 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [build_ext] -define=PSYCOPG_EXTENSIONS,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3 +define=PSYCOPG_EXTENSIONS,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3,PSYCOPG_DEBUG # PSYCOPG_EXTENSIONS enables extensions to PEP-249 (you really want this) # PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower) diff --git a/setup.py b/setup.py index cc49e30b..0561b3b8 100644 --- a/setup.py +++ b/setup.py @@ -216,7 +216,7 @@ class psycopg_build_ext(build_ext): define_macros.append(("PG_VERSION_HEX", "0x%02X%02X%02X" % (int(pgmajor), int(pgminor), int(pgpatch)))) - except Warning, w: + except (Warning, w): if self.pg_config == self.DEFAULT_PG_CONFIG: sys.stderr.write("Warning: %s" % str(w)) else: