mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 10:23:43 +03:00
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:
parent
fd1ee6fffc
commit
67afd678b0
15
Makefile
Normal file
15
Makefile
Normal 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
16
tests/__init__.py
Normal file → Executable file
|
@ -1,21 +1,25 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
import os
|
import os
|
||||||
import unittest
|
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_psycopg2_dbapi20
|
||||||
|
import test_quote
|
||||||
import test_transaction
|
import test_transaction
|
||||||
import types_basic
|
import types_basic
|
||||||
import extras_dictcursor
|
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
suite.addTest(bugX000.test_suite())
|
||||||
|
suite.addTest(extras_dictcursor.test_suite())
|
||||||
suite.addTest(test_psycopg2_dbapi20.test_suite())
|
suite.addTest(test_psycopg2_dbapi20.test_suite())
|
||||||
|
suite.addTest(test_quote.test_suite())
|
||||||
suite.addTest(test_transaction.test_suite())
|
suite.addTest(test_transaction.test_suite())
|
||||||
suite.addTest(types_basic.test_suite())
|
suite.addTest(types_basic.test_suite())
|
||||||
suite.addTest(extras_dictcursor.test_suite())
|
|
||||||
return suite
|
return suite
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main(defaultTest='test_suite')
|
||||||
|
|
||||||
|
|
13
tests/bugX000.py
Normal file → Executable file
13
tests/bugX000.py
Normal file → Executable file
|
@ -1,10 +1,21 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import time
|
import time
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
class DateTimeAllocationBugTestCase(unittest.TestCase):
|
||||||
|
def test_date_time_allocation_bug(self):
|
||||||
d1 = psycopg2.Date(2002,12,25)
|
d1 = psycopg2.Date(2002,12,25)
|
||||||
d2 = psycopg2.DateFromTicks(time.mktime((2002,12,25,0,0,0,0,0,0)))
|
d2 = psycopg2.DateFromTicks(time.mktime((2002,12,25,0,0,0,0,0,0)))
|
||||||
t1 = psycopg2.Time(13,45,30)
|
t1 = psycopg2.Time(13,45,30)
|
||||||
t2 = psycopg2.TimeFromTicks(time.mktime((2001,1,1,13,45,30,0,0,0)))
|
t2 = psycopg2.TimeFromTicks(time.mktime((2001,1,1,13,45,30,0,0,0)))
|
||||||
t1 = psycopg2.Timestamp(2002,12,25,13,45,30)
|
t1 = psycopg2.Timestamp(2002,12,25,13,45,30)
|
||||||
t2 = psycopg2.TimestampFromTicks( time.mktime((2002,12,25,13,45,30,0,0,0)))
|
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
26
tests/extras_dictcursor.py
Normal file → Executable file
|
@ -1,3 +1,4 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
# extras_dictcursor - test if DictCursor extension class works
|
# extras_dictcursor - test if DictCursor extension class works
|
||||||
#
|
#
|
||||||
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
|
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
|
||||||
|
@ -14,16 +15,21 @@
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import psycopg2.extras
|
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."""
|
"""Test if DictCursor extension class works."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.conn = psycopg2.connect("dbname=test")
|
self.conn = psycopg2.connect("dbname=%s" % tests.dbname)
|
||||||
curs = self.conn.cursor()
|
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):
|
def testDictCursor(self):
|
||||||
curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||||
|
@ -33,15 +39,9 @@ class ExtrasDictCursorTests(TestCase):
|
||||||
self.failUnless(row['foo'] == 'bar')
|
self.failUnless(row['foo'] == 'bar')
|
||||||
self.failUnless(row[0] == '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__":
|
if __name__ == "__main__":
|
||||||
main()
|
unittest.main()
|
||||||
|
|
30
tests/test_psycopg2_dbapi20.py
Normal file → Executable file
30
tests/test_psycopg2_dbapi20.py
Normal file → Executable file
|
@ -4,32 +4,26 @@ import unittest
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import popen2
|
import popen2
|
||||||
|
|
||||||
class test_Psycopg(dbapi20.DatabaseAPI20Test):
|
import tests
|
||||||
|
|
||||||
|
class Psycopg2TestCase(dbapi20.DatabaseAPI20Test):
|
||||||
driver = psycopg2
|
driver = psycopg2
|
||||||
connect_args = ()
|
connect_args = ()
|
||||||
connect_kw_args = {'dsn': 'dbname=dbapi20_test'}
|
connect_kw_args = {'dsn': 'dbname=%s' % tests.dbname}
|
||||||
|
|
||||||
lower_func = 'lower' # For stored procedure test
|
lower_func = 'lower' # For stored procedure test
|
||||||
|
|
||||||
def setUp(self):
|
def test_setoutputsize(self):
|
||||||
# Call superclass setUp In case this does something in the
|
# psycopg2's setoutputsize() is a no-op
|
||||||
# future
|
pass
|
||||||
dbapi20.DatabaseAPI20Test.setUp(self)
|
|
||||||
|
|
||||||
try:
|
def test_nextset(self):
|
||||||
con = self._connect()
|
# psycopg2 does not implement nextset()
|
||||||
con.close()
|
pass
|
||||||
except:
|
|
||||||
cmd = "psql -c 'create database dbapi20_test' template1"
|
|
||||||
cout,cin = popen2.popen2(cmd)
|
|
||||||
cin.close()
|
|
||||||
cout.read()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
dbapi20.DatabaseAPI20Test.tearDown(self)
|
|
||||||
|
|
||||||
def test_nextset(self): pass
|
def test_suite():
|
||||||
def test_setoutputsize(self): pass
|
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
1
tests/test_quote.py
Normal file → Executable file
1
tests/test_quote.py
Normal file → Executable file
|
@ -1,3 +1,4 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import psycopg2.extensions
|
import psycopg2.extensions
|
||||||
import unittest
|
import unittest
|
||||||
|
|
1
tests/test_transaction.py
Normal file → Executable file
1
tests/test_transaction.py
Normal file → Executable file
|
@ -1,3 +1,4 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import unittest
|
import unittest
|
||||||
import tests
|
import tests
|
||||||
|
|
22
tests/types_basic.py
Normal file → Executable file
22
tests/types_basic.py
Normal file → Executable file
|
@ -1,3 +1,4 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
# types_basic.py - tests for basic types conversions
|
# types_basic.py - tests for basic types conversions
|
||||||
#
|
#
|
||||||
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
|
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
|
||||||
|
@ -18,14 +19,16 @@ try:
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
import psycopg2
|
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."""
|
"""Test presence of mandatory attributes and methods."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.conn = psycopg2.connect("dbname=test")
|
self.conn = psycopg2.connect("dbname=%s" % tests.dbname)
|
||||||
|
|
||||||
def execute(self, *args):
|
def execute(self, *args):
|
||||||
curs = self.conn.cursor()
|
curs = self.conn.cursor()
|
||||||
|
@ -74,14 +77,9 @@ class TypesBasicTests(TestCase):
|
||||||
"wrong array quoting " + str(s))
|
"wrong array quoting " + str(s))
|
||||||
|
|
||||||
|
|
||||||
class TypesBasicSuite(TestSuite):
|
def test_suite():
|
||||||
"""Build a suite of all tests."""
|
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user