Skip to content

Commit

Permalink
Added 'make check' target, running all the available tests.
Browse files Browse the repository at this point in the history
Most of the updates have been provided by James Henstridge.

Closes ticket psycopg#195.
  • Loading branch information
dvarrazzo committed Nov 11, 2007
1 parent fd1ee6f commit 67afd67
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 68 deletions.
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
34 changes: 19 additions & 15 deletions tests/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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 test_psycopg2_dbapi20
import test_transaction
import types_basic
import extras_dictcursor

def test_suite():
suite = unittest.TestSuite()
suite.addTest(test_psycopg2_dbapi20.test_suite())
suite.addTest(test_transaction.test_suite())
suite.addTest(types_basic.test_suite())
suite.addTest(extras_dictcursor.test_suite())
return suite
import bugX000
import extras_dictcursor
import test_psycopg2_dbapi20
import test_quote
import test_transaction
import types_basic

if __name__ == "__main__":
unittest.main()
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())
return suite

if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
23 changes: 17 additions & 6 deletions tests/bugX000.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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()
28 changes: 14 additions & 14 deletions tests/extras_dictcursor.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -14,17 +15,22 @@

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)
curs.execute("INSERT INTO ExtrasDictCursorTests VALUES ('bar')")
Expand All @@ -33,15 +39,9 @@ def testDictCursor(self):
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()
36 changes: 15 additions & 21 deletions tests/test_psycopg2_dbapi20.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,26 @@
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)

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 tearDown(self):
dbapi20.DatabaseAPI20Test.tearDown(self)

def test_nextset(self): pass
def test_setoutputsize(self): pass
def test_setoutputsize(self):
# psycopg2's setoutputsize() is a no-op
pass

def test_nextset(self):
# psycopg2 does not implement nextset()
pass


def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)

if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions tests/test_quote.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
import psycopg2
import psycopg2.extensions
import unittest
Expand Down
1 change: 1 addition & 0 deletions tests/test_transaction.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
import psycopg2
import unittest
import tests
Expand Down
22 changes: 10 additions & 12 deletions tests/types_basic.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -18,14 +19,16 @@
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()
Expand Down Expand Up @@ -74,14 +77,9 @@ def testArray(self):
"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()

0 comments on commit 67afd67

Please sign in to comment.