Added 'make check' target, running all the available tests.

Most of the updates have been provided by James Henstridge.

Closes ticket #195.
This commit is contained in:
Daniele Varrazzo 2007-11-11 10:40:12 +00:00
parent fd1ee6fffc
commit 67afd678b0
8 changed files with 89 additions and 65 deletions

15
Makefile Normal file
View File

@ -0,0 +1,15 @@
PYTHON = python$(PYTHON_VERSION)
#PYTHON_VERSION = 2.4
TESTDB = psycopg2_test
all:
@:
check:
@echo "* Creating $(TESTDB)"
@if psql -l | grep -q " $(TESTDB) "; then \
dropdb $(TESTDB) >/dev/null; \
fi
createdb $(TESTDB)
PSYCOPG2_TESTDB=$(TESTDB) $(PYTHON) tests/__init__.py --verbose

16
tests/__init__.py Normal file → Executable file
View File

@ -1,21 +1,25 @@
#!/usr/bin/env python
import os
import unittest
dbname = os.environ.get('PSYCOPG2_TESTDB', 'test')
dbname = os.environ.get('PSYCOPG2_TESTDB', 'psycopg2_test')
import bugX000
import extras_dictcursor
import test_psycopg2_dbapi20
import test_quote
import test_transaction
import types_basic
import extras_dictcursor
def test_suite():
suite = unittest.TestSuite()
suite.addTest(bugX000.test_suite())
suite.addTest(extras_dictcursor.test_suite())
suite.addTest(test_psycopg2_dbapi20.test_suite())
suite.addTest(test_quote.test_suite())
suite.addTest(test_transaction.test_suite())
suite.addTest(types_basic.test_suite())
suite.addTest(extras_dictcursor.test_suite())
return suite
if __name__ == "__main__":
unittest.main()
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')

23
tests/bugX000.py Normal file → Executable file
View File

@ -1,10 +1,21 @@
#!/usr/bin/env python
import psycopg2
import time
import unittest
d1 = psycopg2.Date(2002,12,25)
d2 = psycopg2.DateFromTicks(time.mktime((2002,12,25,0,0,0,0,0,0)))
t1 = psycopg2.Time(13,45,30)
t2 = psycopg2.TimeFromTicks(time.mktime((2001,1,1,13,45,30,0,0,0)))
t1 = psycopg2.Timestamp(2002,12,25,13,45,30)
t2 = psycopg2.TimestampFromTicks( time.mktime((2002,12,25,13,45,30,0,0,0)))
class DateTimeAllocationBugTestCase(unittest.TestCase):
def test_date_time_allocation_bug(self):
d1 = psycopg2.Date(2002,12,25)
d2 = psycopg2.DateFromTicks(time.mktime((2002,12,25,0,0,0,0,0,0)))
t1 = psycopg2.Time(13,45,30)
t2 = psycopg2.TimeFromTicks(time.mktime((2001,1,1,13,45,30,0,0,0)))
t1 = psycopg2.Timestamp(2002,12,25,13,45,30)
t2 = psycopg2.TimestampFromTicks(
time.mktime((2002,12,25,13,45,30,0,0,0)))
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)
if __name__ == "__main__":
unittest.main()

26
tests/extras_dictcursor.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/usr/bin/env python
# extras_dictcursor - test if DictCursor extension class works
#
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
@ -14,16 +15,21 @@
import psycopg2
import psycopg2.extras
from unittest import TestCase, TestSuite, main
import unittest
import tests
class ExtrasDictCursorTests(TestCase):
class ExtrasDictCursorTests(unittest.TestCase):
"""Test if DictCursor extension class works."""
def setUp(self):
self.conn = psycopg2.connect("dbname=test")
self.conn = psycopg2.connect("dbname=%s" % tests.dbname)
curs = self.conn.cursor()
curs.execute("CREATE TABLE ExtrasDictCursorTests (foo text)")
curs.execute("CREATE TEMPORARY TABLE ExtrasDictCursorTests (foo text)")
def tearDown(self):
self.conn.close()
def testDictCursor(self):
curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
@ -33,15 +39,9 @@ class ExtrasDictCursorTests(TestCase):
self.failUnless(row['foo'] == 'bar')
self.failUnless(row[0] == 'bar')
class ExtrasDictCursorSuite(TestSuite):
"""Build a suite of all tests."""
def __init__(self):
"""Build a list of tests."""
self.tests = [x for x in dir(ExtrasDictCursorTests)
if x.startswith('test')]
TestSuite.__init__(self, map(TestModule, self.tests))
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)
if __name__ == "__main__":
main()
unittest.main()

30
tests/test_psycopg2_dbapi20.py Normal file → Executable file
View File

@ -4,32 +4,26 @@ import unittest
import psycopg2
import popen2
class test_Psycopg(dbapi20.DatabaseAPI20Test):
import tests
class Psycopg2TestCase(dbapi20.DatabaseAPI20Test):
driver = psycopg2
connect_args = ()
connect_kw_args = {'dsn': 'dbname=dbapi20_test'}
connect_kw_args = {'dsn': 'dbname=%s' % tests.dbname}
lower_func = 'lower' # For stored procedure test
def setUp(self):
# Call superclass setUp In case this does something in the
# future
dbapi20.DatabaseAPI20Test.setUp(self)
def test_setoutputsize(self):
# psycopg2's setoutputsize() is a no-op
pass
try:
con = self._connect()
con.close()
except:
cmd = "psql -c 'create database dbapi20_test' template1"
cout,cin = popen2.popen2(cmd)
cin.close()
cout.read()
def test_nextset(self):
# psycopg2 does not implement nextset()
pass
def tearDown(self):
dbapi20.DatabaseAPI20Test.tearDown(self)
def test_nextset(self): pass
def test_setoutputsize(self): pass
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)
if __name__ == '__main__':
unittest.main()

1
tests/test_quote.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/usr/bin/env python
import psycopg2
import psycopg2.extensions
import unittest

1
tests/test_transaction.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/usr/bin/env python
import psycopg2
import unittest
import tests

22
tests/types_basic.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/usr/bin/env python
# types_basic.py - tests for basic types conversions
#
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
@ -18,14 +19,16 @@ try:
except:
pass
import psycopg2
from unittest import TestCase, TestSuite, main
import unittest
import tests
class TypesBasicTests(TestCase):
class TypesBasicTests(unittest.TestCase):
"""Test presence of mandatory attributes and methods."""
def setUp(self):
self.conn = psycopg2.connect("dbname=test")
self.conn = psycopg2.connect("dbname=%s" % tests.dbname)
def execute(self, *args):
curs = self.conn.cursor()
@ -74,14 +77,9 @@ class TypesBasicTests(TestCase):
"wrong array quoting " + str(s))
class TypesBasicSuite(TestSuite):
"""Build a suite of all tests."""
def __init__(self):
"""Build a list of tests."""
self.tests = [x for x in dir(TypesBasicTests) if x.startswith('test')]
TestSuite.__init__(self, map(TestModule, self.tests))
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)
if __name__ == "__main__":
main()
unittest.main()