~psycopg/psycopg/2.0.x

« back to all changes in this revision

Viewing changes to tests/types_basic.py

  • Committer: Federico Di Gregorio
  • Date: 2005-07-17 04:26:27 UTC
  • Revision ID: fog-6e3e8904b6e8fe037a8e67e4b490858762846618
Releasing 2.0b4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
13
# for more details.
14
14
 
15
 
import psycopg
 
15
import sys
 
16
try:
 
17
    import decimal
 
18
except:
 
19
    pass
 
20
import psycopg2
16
21
from unittest import TestCase, TestSuite, main
17
22
 
18
23
 
20
25
    """Test presence of mandatory attributes and methods."""
21
26
 
22
27
    def setUp(self):
23
 
        self.conn = psycopg.connect("dbname=test")
 
28
        self.conn = psycopg2.connect("dbname=test")
24
29
 
25
30
    def execute(self, *args):
26
31
        curs = self.conn.cursor()
42
47
        self.failUnless(s == 1971, "wrong integer quoting: " + str(s))
43
48
        s = self.execute("SELECT %s AS foo", (1971L,))
44
49
        self.failUnless(s == 1971L, "wrong integer quoting: " + str(s))
45
 
        s = self.execute("SELECT %s AS foo", (19.10,))
46
 
        self.failUnless(abs(s - 19.10) < 0.001,
47
 
                        "wrong float quoting: " + str(s))
 
50
        # Python 2.4 defaults to Decimal?
 
51
        if sys.version_info[0] >= 2 and sys.version_info[1] >= 4:
 
52
            s = self.execute("SELECT %s AS foo", (19.10,))
 
53
            self.failUnless(s - decimal.Decimal("19.10") == 0,
 
54
                            "wrong decimal quoting: " + str(s))
 
55
        else:
 
56
            s = self.execute("SELECT %s AS foo", (19.10,))
 
57
            self.failUnless(abs(s - 19.10) < 0.001,
 
58
                            "wrong float quoting: " + str(s))
48
59
 
49
60
    def testBinary(self):
50
61
        s = ''.join([chr(x) for x in range(256)])
51
 
        b = psycopg.Binary(s)
 
62
        b = psycopg2.Binary(s)
52
63
        r = str(self.execute("SELECT %s::bytea AS foo", (b,)))
53
64
        self.failUnless(r == s, "wrong binary quoting")
54
65