Changeset 770 for trunk/tests


Ignore:
Timestamp:
Jan 20, 2016, 1:19:45 PM (4 years ago)
Author:
cito
Message:

Add methods for getting a table as a list or dict

Also added documentation and 100% test coverage.

The get_attnames() method now always returns a read-only ordered dictionary,
even under Python 2.6 or 3.0. So you can sure the columns will be returned
in the right order if you iterate over it, and that you don't accidentally
modify the dictionary (since it is cached).

Location:
trunk/tests
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/__init__.py

    r644 r770  
    22
    33You can specify your local database settings in LOCAL_PyGreSQL.py.
    4 
    54"""
    65
     
    109    import unittest
    1110
     11if not (hasattr(unittest, 'skip')
     12        and hasattr(unittest.TestCase, 'setUpClass')
     13        and hasattr(unittest.TestCase, 'skipTest')
     14        and hasattr(unittest.TestCase, 'assertIn')):
     15    raise ImportError('Please install a newer version of unittest')
     16
    1217
    1318def discover():
  • trunk/tests/test_classic_connection.py

    r744 r770  
    99
    1010These tests need a database to test against.
    11 
    1211"""
    1312
     
    871870    """Test inserttable method."""
    872871
     872    cls_set_up = False
     873
    873874    @classmethod
    874875    def setUpClass(cls):
     
    885886            "select length('À') - length('a')").getresult()[0][0] == 0
    886887        c.close()
     888        cls.cls_set_up = True
    887889
    888890    @classmethod
     
    893895
    894896    def setUp(self):
     897        self.assertTrue(self.cls_set_up)
    895898        self.c = connect()
    896899        self.c.query("set client_encoding=utf8")
     
    11021105    """Test copy command with direct socket access."""
    11031106
     1107    cls_set_up = False
     1108
    11041109    @classmethod
    11051110    def setUpClass(cls):
     
    11081113        c.query("create table test (i int, v varchar(16))")
    11091114        c.close()
     1115        cls.cls_set_up = True
    11101116
    11111117    @classmethod
     
    11161122
    11171123    def setUp(self):
     1124        self.assertTrue(self.cls_set_up)
    11181125        self.c = connect()
    11191126        self.c.query("set client_encoding=utf8")
     
    12831290    To test the effect of most of these functions, we need a database
    12841291    connection.  That's why they are covered in this test module.
    1285 
    12861292    """
    12871293
     
    16061612    in order to ensure that the tests always run under the same conditions.
    16071613    That's why these tests are included in this test module.
    1608 
    16091614    """
     1615
     1616    cls_set_up = False
    16101617
    16111618    @classmethod
     
    16151622        query('set standard_conforming_strings=off')
    16161623        query('set bytea_output=escape')
     1624        cls.cls_set_up = True
    16171625
    16181626    def testEscapeString(self):
     1627        self.assertTrue(self.cls_set_up)
    16191628        f = pg.escape_string
    16201629        r = f(b'plain')
     
    16341643
    16351644    def testEscapeBytea(self):
     1645        self.assertTrue(self.cls_set_up)
    16361646        f = pg.escape_bytea
    16371647        r = f(b'plain')
  • trunk/tests/test_classic_dbwrapper.py

    r769 r770  
    99
    1010These tests need a database to test against.
    11 
    1211"""
     12
    1313try:
    1414    import unittest2 as unittest  # for Python < 2.7
     
    2323
    2424from decimal import Decimal
     25from operator import itemgetter
    2526
    2627# We need a database to test against.  If LOCAL_PyGreSQL.py exists we will
     
    7677    db.query("set client_min_messages=warning")
    7778    return db
     79
     80
     81class TestAttrDict(unittest.TestCase):
     82    """Test the simple ordered dictionary for attribute names."""
     83
     84    cls = pg.AttrDict
     85    base = OrderedDict
     86
     87    def testInit(self):
     88        a = self.cls()
     89        self.assertIsInstance(a, self.base)
     90        self.assertEqual(a, self.base())
     91        items = [('id', 'int'), ('name', 'text')]
     92        a = self.cls(items)
     93        self.assertIsInstance(a, self.base)
     94        self.assertEqual(a, self.base(items))
     95        iteritems = iter(items)
     96        a = self.cls(iteritems)
     97        self.assertIsInstance(a, self.base)
     98        self.assertEqual(a, self.base(items))
     99
     100    def testIter(self):
     101        a = self.cls()
     102        self.assertEqual(list(a), [])
     103        keys = ['id', 'name', 'age']
     104        items = [(key, None) for key in keys]
     105        a = self.cls(items)
     106        self.assertEqual(list(a), keys)
     107
     108    def testKeys(self):
     109        a = self.cls()
     110        self.assertEqual(list(a.keys()), [])
     111        keys = ['id', 'name', 'age']
     112        items = [(key, None) for key in keys]
     113        a = self.cls(items)
     114        self.assertEqual(list(a.keys()), keys)
     115
     116    def testValues(self):
     117        a = self.cls()
     118        self.assertEqual(list(a.values()), [])
     119        items = [('id', 'int'), ('name', 'text')]
     120        values = [item[1] for item in items]
     121        a = self.cls(items)
     122        self.assertEqual(list(a.values()), values)
     123
     124    def testItems(self):
     125        a = self.cls()
     126        self.assertEqual(list(a.items()), [])
     127        items = [('id', 'int'), ('name', 'text')]
     128        a = self.cls(items)
     129        self.assertEqual(list(a.items()), items)
     130
     131    def testGet(self):
     132        a = self.cls([('id', 1)])
     133        try:
     134            self.assertEqual(a['id'], 1)
     135        except KeyError:
     136            self.fail('AttrDict should be readable')
     137
     138    def testSet(self):
     139        a = self.cls()
     140        try:
     141            a['id'] = 1
     142        except TypeError:
     143            pass
     144        else:
     145            self.fail('AttrDict should be read-only')
     146
     147    def testDel(self):
     148        a = self.cls([('id', 1)])
     149        try:
     150            del a['id']
     151        except TypeError:
     152            pass
     153        else:
     154            self.fail('AttrDict should be read-only')
     155
     156    def testWriteMethods(self):
     157        a = self.cls([('id', 1)])
     158        self.assertEqual(a['id'], 1)
     159        for method in 'clear', 'update', 'pop', 'setdefault', 'popitem':
     160            method = getattr(a, method)
     161            self.assertRaises(TypeError, method, a)
    78162
    79163
     
    100184            'escape_literal', 'escape_string',
    101185            'fileno',
    102             'get', 'get_attnames', 'get_databases',
     186            'get', 'get_as_dict', 'get_as_list',
     187            'get_attnames', 'get_databases',
    103188            'get_notice_receiver', 'get_parameter',
    104189            'get_relations', 'get_tables',
     
    284369    """Test the methods of the DB class wrapped pg connection."""
    285370
     371    cls_set_up = False
     372
    286373    @classmethod
    287374    def setUpClass(cls):
     
    295382            " select i4, v4 from test")
    296383        db.close()
     384        cls.cls_set_up = True
    297385
    298386    @classmethod
     
    303391
    304392    def setUp(self):
     393        self.assertTrue(self.cls_set_up)
    305394        self.db = DB()
    306395        query = self.db.query
     
    9381027    def testGetAttnamesIsOrdered(self):
    9391028        get_attnames = self.db.get_attnames
    940         query = self.db.query
    941         self.createTable('test_table',
     1029        r = get_attnames('test', flush=True)
     1030        self.assertIsInstance(r, OrderedDict)
     1031        self.assertEqual(r, OrderedDict([
     1032            ('i2', 'int'), ('i4', 'int'), ('i8', 'int'),
     1033            ('d', 'num'), ('f4', 'float'), ('f8', 'float'), ('m', 'money'),
     1034            ('v4', 'text'), ('c4', 'text'), ('t', 'text')]))
     1035        if OrderedDict is not dict:
     1036            r = ' '.join(list(r.keys()))
     1037            self.assertEqual(r, 'i2 i4 i8 d f4 f8 m v4 c4 t')
     1038        table = 'test table for get_attnames'
     1039        self.createTable(table,
    9421040            ' n int, alpha smallint, v varchar(3),'
    9431041            ' gamma char(5), tau text, beta bool')
    944         r = get_attnames("test_table")
     1042        r = get_attnames(table)
    9451043        self.assertIsInstance(r, OrderedDict)
    9461044        self.assertEqual(r, OrderedDict([
    9471045            ('n', 'int'), ('alpha', 'int'), ('v', 'text'),
    9481046            ('gamma', 'text'), ('tau', 'text'), ('beta', 'bool')]))
    949         if OrderedDict is dict:
     1047        if OrderedDict is not dict:
     1048            r = ' '.join(list(r.keys()))
     1049            self.assertEqual(r, 'n alpha v gamma tau beta')
     1050        else:
    9501051            self.skipTest('OrderedDict is not supported')
     1052
     1053    def testGetAttnamesIsAttrDict(self):
     1054        AttrDict = pg.AttrDict
     1055        get_attnames = self.db.get_attnames
     1056        r = get_attnames('test', flush=True)
     1057        self.assertIsInstance(r, AttrDict)
     1058        self.assertEqual(r, AttrDict([
     1059            ('i2', 'int'), ('i4', 'int'), ('i8', 'int'),
     1060            ('d', 'num'), ('f4', 'float'), ('f8', 'float'), ('m', 'money'),
     1061            ('v4', 'text'), ('c4', 'text'), ('t', 'text')]))
     1062        r = ' '.join(list(r.keys()))
     1063        self.assertEqual(r, 'i2 i4 i8 d f4 f8 m v4 c4 t')
     1064        table = 'test table for get_attnames'
     1065        self.createTable(table,
     1066            ' n int, alpha smallint, v varchar(3),'
     1067            ' gamma char(5), tau text, beta bool')
     1068        r = get_attnames(table)
     1069        self.assertIsInstance(r, AttrDict)
     1070        self.assertEqual(r, AttrDict([
     1071            ('n', 'int'), ('alpha', 'int'), ('v', 'text'),
     1072            ('gamma', 'text'), ('tau', 'text'), ('beta', 'bool')]))
    9511073        r = ' '.join(list(r.keys()))
    9521074        self.assertEqual(r, 'n alpha v gamma tau beta')
     
    18291951    def testClearWithQuotedNames(self):
    18301952        clear = self.db.clear
    1831         query = self.db.query
    18321953        table = 'test table for clear()'
    18331954        self.createTable(table, '"Prime!" smallint primary key,'
     
    22222343        self.assertEqual(r, 0)
    22232344
     2345    def testGetAsList(self):
     2346        get_as_list = self.db.get_as_list
     2347        self.assertRaises(TypeError, get_as_list)
     2348        self.assertRaises(TypeError, get_as_list, None)
     2349        query = self.db.query
     2350        table = 'test_aslist'
     2351        r = query('select 1 as colname').namedresult()[0]
     2352        self.assertIsInstance(r, tuple)
     2353        named = hasattr(r, 'colname')
     2354        names = [(1, 'Homer'), (2, 'Marge'),
     2355                (3, 'Bart'), (4, 'Lisa'), (5, 'Maggie')]
     2356        self.createTable(table,
     2357            'id smallint primary key, name varchar', values=names)
     2358        r = get_as_list(table)
     2359        self.assertIsInstance(r, list)
     2360        self.assertEqual(r, names)
     2361        for t, n in zip(r, names):
     2362            self.assertIsInstance(t, tuple)
     2363            self.assertEqual(t, n)
     2364            if named:
     2365                self.assertEqual(t.id, n[0])
     2366                self.assertEqual(t.name, n[1])
     2367                self.assertEqual(t._asdict(), dict(id=n[0], name=n[1]))
     2368        r = get_as_list(table, what='name')
     2369        self.assertIsInstance(r, list)
     2370        expected = sorted((row[1],) for row in names)
     2371        self.assertEqual(r, expected)
     2372        r = get_as_list(table, what='name, id')
     2373        self.assertIsInstance(r, list)
     2374        expected = sorted(tuple(reversed(row)) for row in names)
     2375        self.assertEqual(r, expected)
     2376        r = get_as_list(table, what=['name', 'id'])
     2377        self.assertIsInstance(r, list)
     2378        self.assertEqual(r, expected)
     2379        r = get_as_list(table, where="name like 'Ba%'")
     2380        self.assertIsInstance(r, list)
     2381        self.assertEqual(r, names[2:3])
     2382        r = get_as_list(table, what='name', where="name like 'Ma%'")
     2383        self.assertIsInstance(r, list)
     2384        self.assertEqual(r, [('Maggie',), ('Marge',)])
     2385        r = get_as_list(table, what='name',
     2386                        where=["name like 'Ma%'", "name like '%r%'"])
     2387        self.assertIsInstance(r, list)
     2388        self.assertEqual(r, [('Marge',)])
     2389        r = get_as_list(table, what='name', order='id')
     2390        self.assertIsInstance(r, list)
     2391        expected = [(row[1],) for row in names]
     2392        self.assertEqual(r, expected)
     2393        r = get_as_list(table, what=['name'], order=['id'])
     2394        self.assertIsInstance(r, list)
     2395        self.assertEqual(r, expected)
     2396        r = get_as_list(table, what=['id', 'name'], order=['id', 'name'])
     2397        self.assertIsInstance(r, list)
     2398        self.assertEqual(r, names)
     2399        r = get_as_list(table, what='id * 2 as num', order='id desc')
     2400        self.assertIsInstance(r, list)
     2401        expected = [(n,) for n in range(10, 0, -2)]
     2402        self.assertEqual(r, expected)
     2403        r = get_as_list(table, limit=2)
     2404        self.assertIsInstance(r, list)
     2405        self.assertEqual(r, names[:2])
     2406        r = get_as_list(table, offset=3)
     2407        self.assertIsInstance(r, list)
     2408        self.assertEqual(r, names[3:])
     2409        r = get_as_list(table, limit=1, offset=2)
     2410        self.assertIsInstance(r, list)
     2411        self.assertEqual(r, names[2:3])
     2412        r = get_as_list(table, scalar=True)
     2413        self.assertIsInstance(r, list)
     2414        self.assertEqual(r, list(range(1, 6)))
     2415        r = get_as_list(table, what='name', scalar=True)
     2416        self.assertIsInstance(r, list)
     2417        expected = sorted(row[1] for row in names)
     2418        self.assertEqual(r, expected)
     2419        r = get_as_list(table, what='name', limit=1, scalar=True)
     2420        self.assertIsInstance(r, list)
     2421        self.assertEqual(r, expected[:1])
     2422        query('alter table "%s" drop constraint "%s_pkey"' % (table, table))
     2423        self.assertRaises(KeyError, self.db.pkey, table, flush=True)
     2424        names.insert(1, (1, 'Snowball'))
     2425        query('insert into "%s" values ($1, $2)' % table, (1, 'Snowball'))
     2426        r = get_as_list(table)
     2427        self.assertIsInstance(r, list)
     2428        self.assertEqual(r, names)
     2429        r = get_as_list(table, what='name', where='id=1', scalar=True)
     2430        self.assertIsInstance(r, list)
     2431        self.assertEqual(r, ['Homer', 'Snowball'])
     2432        # test with unordered query
     2433        r = get_as_list(table, order=False)
     2434        self.assertIsInstance(r, list)
     2435        self.assertEqual(set(r), set(names))
     2436        # test with arbitrary from clause
     2437        from_table = '(select lower(name) as n2 from "%s") as t2' % table
     2438        r = get_as_list(from_table)
     2439        self.assertIsInstance(r, list)
     2440        r = set(row[0] for row in r)
     2441        expected = set(row[1].lower() for row in names)
     2442        self.assertEqual(r, expected)
     2443        r = get_as_list(from_table, order='n2', scalar=True)
     2444        self.assertIsInstance(r, list)
     2445        self.assertEqual(r, sorted(expected))
     2446        r = get_as_list(from_table, order='n2', limit=1)
     2447        self.assertIsInstance(r, list)
     2448        self.assertEqual(len(r), 1)
     2449        t = r[0]
     2450        self.assertIsInstance(t, tuple)
     2451        if named:
     2452            self.assertEqual(t.n2, 'bart')
     2453            self.assertEqual(t._asdict(), dict(n2='bart'))
     2454        else:
     2455            self.assertEqual(t, ('bart',))
     2456
     2457    def testGetAsDict(self):
     2458        get_as_dict = self.db.get_as_dict
     2459        self.assertRaises(TypeError, get_as_dict)
     2460        self.assertRaises(TypeError, get_as_dict, None)
     2461        # the test table has no primary key
     2462        self.assertRaises(pg.ProgrammingError, get_as_dict, 'test')
     2463        query = self.db.query
     2464        table = 'test_asdict'
     2465        r = query('select 1 as colname').namedresult()[0]
     2466        self.assertIsInstance(r, tuple)
     2467        named = hasattr(r, 'colname')
     2468        colors = [(1, '#7cb9e8', 'Aero'), (2, '#b5a642', 'Brass'),
     2469                  (3, '#b2ffff', 'Celeste'), (4, '#c19a6b', 'Desert')]
     2470        self.createTable(table,
     2471            'id smallint primary key, rgb char(7), name varchar',
     2472            values=colors)
     2473        # keyname must be string, list or tuple
     2474        self.assertRaises(KeyError, get_as_dict, table, 3)
     2475        self.assertRaises(KeyError, get_as_dict, table, dict(id=None))
     2476        # missing keyname in row
     2477        self.assertRaises(KeyError, get_as_dict, table,
     2478                          keyname='rgb', what='name')
     2479        r = get_as_dict(table)
     2480        self.assertIsInstance(r, OrderedDict)
     2481        expected = OrderedDict((row[0], row[1:]) for row in colors)
     2482        self.assertEqual(r, expected)
     2483        for key in r:
     2484            self.assertIsInstance(key, int)
     2485            self.assertIn(key, expected)
     2486            row = r[key]
     2487            self.assertIsInstance(row, tuple)
     2488            t = expected[key]
     2489            self.assertEqual(row, t)
     2490            if named:
     2491                self.assertEqual(row.rgb, t[0])
     2492                self.assertEqual(row.name, t[1])
     2493                self.assertEqual(row._asdict(), dict(rgb=t[0], name=t[1]))
     2494        if OrderedDict is not dict:  # Python > 2.6
     2495            self.assertEqual(r.keys(), expected.keys())
     2496        r = get_as_dict(table, keyname='rgb')
     2497        self.assertIsInstance(r, OrderedDict)
     2498        expected = OrderedDict((row[1], (row[0], row[2]))
     2499            for row in sorted(colors, key=itemgetter(1)))
     2500        self.assertEqual(r, expected)
     2501        for key in r:
     2502            self.assertIsInstance(key, str)
     2503            self.assertIn(key, expected)
     2504            row = r[key]
     2505            self.assertIsInstance(row, tuple)
     2506            t = expected[key]
     2507            self.assertEqual(row, t)
     2508            if named:
     2509                self.assertEqual(row.id, t[0])
     2510                self.assertEqual(row.name, t[1])
     2511                self.assertEqual(row._asdict(), dict(id=t[0], name=t[1]))
     2512        if OrderedDict is not dict:  # Python > 2.6
     2513            self.assertEqual(r.keys(), expected.keys())
     2514        r = get_as_dict(table, keyname=['id', 'rgb'])
     2515        self.assertIsInstance(r, OrderedDict)
     2516        expected = OrderedDict((row[:2], row[2:]) for row in colors)
     2517        self.assertEqual(r, expected)
     2518        for key in r:
     2519            self.assertIsInstance(key, tuple)
     2520            self.assertIsInstance(key[0], int)
     2521            self.assertIsInstance(key[1], str)
     2522            if named:
     2523                self.assertEqual(key, (key.id, key.rgb))
     2524                self.assertEqual(key._fields, ('id', 'rgb'))
     2525            row = r[key]
     2526            self.assertIsInstance(row, tuple)
     2527            self.assertIsInstance(row[0], str)
     2528            t = expected[key]
     2529            self.assertEqual(row, t)
     2530            if named:
     2531                self.assertEqual(row.name, t[0])
     2532                self.assertEqual(row._asdict(), dict(name=t[0]))
     2533        if OrderedDict is not dict:  # Python > 2.6
     2534            self.assertEqual(r.keys(), expected.keys())
     2535        r = get_as_dict(table, keyname=['id', 'rgb'], scalar=True)
     2536        self.assertIsInstance(r, OrderedDict)
     2537        expected = OrderedDict((row[:2], row[2]) for row in colors)
     2538        self.assertEqual(r, expected)
     2539        for key in r:
     2540            self.assertIsInstance(key, tuple)
     2541            row = r[key]
     2542            self.assertIsInstance(row, str)
     2543            t = expected[key]
     2544            self.assertEqual(row, t)
     2545        if OrderedDict is not dict:  # Python > 2.6
     2546            self.assertEqual(r.keys(), expected.keys())
     2547        r = get_as_dict(table, keyname='rgb', what=['rgb', 'name'], scalar=True)
     2548        self.assertIsInstance(r, OrderedDict)
     2549        expected = OrderedDict((row[1], row[2])
     2550            for row in sorted(colors, key=itemgetter(1)))
     2551        self.assertEqual(r, expected)
     2552        for key in r:
     2553            self.assertIsInstance(key, str)
     2554            row = r[key]
     2555            self.assertIsInstance(row, str)
     2556            t = expected[key]
     2557            self.assertEqual(row, t)
     2558        if OrderedDict is not dict:  # Python > 2.6
     2559            self.assertEqual(r.keys(), expected.keys())
     2560        r = get_as_dict(table, what='id, name',
     2561                        where="rgb like '#b%'", scalar=True)
     2562        self.assertIsInstance(r, OrderedDict)
     2563        expected = OrderedDict((row[0], row[2]) for row in colors[1:3])
     2564        self.assertEqual(r, expected)
     2565        for key in r:
     2566            self.assertIsInstance(key, int)
     2567            row = r[key]
     2568            self.assertIsInstance(row, str)
     2569            t = expected[key]
     2570            self.assertEqual(row, t)
     2571        if OrderedDict is not dict:  # Python > 2.6
     2572            self.assertEqual(r.keys(), expected.keys())
     2573        expected = r
     2574        r = get_as_dict(table, what=['name', 'id'],
     2575                        where=['id > 1', 'id < 4', "rgb like '#b%'",
     2576                   "name not like 'A%'", "name not like '%t'"], scalar=True)
     2577        self.assertEqual(r, expected)
     2578        r = get_as_dict(table, what='name, id', limit=2, offset=1, scalar=True)
     2579        self.assertEqual(r, expected)
     2580        r = get_as_dict(table, keyname=('id',), what=('name', 'id'),
     2581                        where=('id > 1', 'id < 4'), order=('id',), scalar=True)
     2582        self.assertEqual(r, expected)
     2583        r = get_as_dict(table, limit=1)
     2584        self.assertEqual(len(r), 1)
     2585        self.assertEqual(r[1][1], 'Aero')
     2586        r = get_as_dict(table, offset=3)
     2587        self.assertEqual(len(r), 1)
     2588        self.assertEqual(r[4][1], 'Desert')
     2589        r = get_as_dict(table, order='id desc')
     2590        expected = OrderedDict((row[0], row[1:]) for row in reversed(colors))
     2591        self.assertEqual(r, expected)
     2592        r = get_as_dict(table, where='id > 5')
     2593        self.assertIsInstance(r, OrderedDict)
     2594        self.assertEqual(len(r), 0)
     2595        # test with unordered query
     2596        expected = dict((row[0], row[1:]) for row in colors)
     2597        r = get_as_dict(table, order=False)
     2598        self.assertIsInstance(r, dict)
     2599        self.assertEqual(r, expected)
     2600        if dict is not OrderedDict:  # Python > 2.6
     2601            self.assertNotIsInstance(self, OrderedDict)
     2602        # test with arbitrary from clause
     2603        from_table = '(select id, lower(name) as n2 from "%s") as t2' % table
     2604        # primary key must be passed explicitly in this case
     2605        self.assertRaises(pg.ProgrammingError, get_as_dict, from_table)
     2606        r = get_as_dict(from_table, 'id')
     2607        self.assertIsInstance(r, OrderedDict)
     2608        expected = OrderedDict((row[0], (row[2].lower(),)) for row in colors)
     2609        self.assertEqual(r, expected)
     2610        # test without a primary key
     2611        query('alter table "%s" drop constraint "%s_pkey"' % (table, table))
     2612        self.assertRaises(KeyError, self.db.pkey, table, flush=True)
     2613        self.assertRaises(pg.ProgrammingError, get_as_dict, table)
     2614        r = get_as_dict(table, keyname='id')
     2615        expected = OrderedDict((row[0], row[1:]) for row in colors)
     2616        self.assertIsInstance(r, dict)
     2617        self.assertEqual(r, expected)
     2618        r = (1, '#007fff', 'Azure')
     2619        query('insert into "%s" values ($1, $2, $3)' % table, r)
     2620        # the last entry will win
     2621        expected[1] = r[1:]
     2622        r = get_as_dict(table, keyname='id')
     2623        self.assertEqual(r, expected)
     2624
    22242625    def testTransaction(self):
    22252626        query = self.db.query
     
    25062907    """Test correct handling of schemas (namespaces)."""
    25072908
     2909    cls_set_up = False
     2910
    25082911    @classmethod
    25092912    def setUpClass(cls):
     
    25292932                  % (schema, num_schema, num_schema))
    25302933        db.close()
     2934        cls.cls_set_up = True
    25312935
    25322936    @classmethod
     
    25452949
    25462950    def setUp(self):
     2951        self.assertTrue(self.cls_set_up)
    25472952        self.db = DB()
    25482953
  • trunk/tests/test_classic_functions.py

    r729 r770  
    99
    1010These tests do not need a database to test against.
    11 
    1211"""
    13 
    1412
    1513try:
  • trunk/tests/test_classic_largeobj.py

    r648 r770  
    99
    1010These tests need a database to test against.
    11 
    1211"""
    1312
  • trunk/tests/test_dbapi20_copy.py

    r697 r770  
    99
    1010These tests need a database to test against.
    11 
    1211"""
    1312
     
    124123class TestCopy(unittest.TestCase):
    125124
     125    cls_set_up = False
     126
    126127    @staticmethod
    127128    def connect():
     
    140141        con.commit()
    141142        con.close()
     143        cls.cls_set_up = True
    142144
    143145    @classmethod
     
    151153
    152154    def setUp(self):
     155        self.assertTrue(self.cls_set_up)
    153156        self.con = self.connect()
    154157        self.cursor = self.con.cursor()
Note: See TracChangeset for help on using the changeset viewer.