Changeset 796 for trunk/tests


Ignore:
Timestamp:
Jan 28, 2016, 4:25:36 PM (4 years ago)
Author:
cito
Message:

Enrich type_code strings in the DB API 2

The type codes now carry e.g. the information whether a type is a record.
This allows to provide a RECORD type object that compares equal to all
kinds of records, similar to the already existing ARRAY type object.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/test_dbapi20.py

    r792 r796  
    298298        type_info = type_cache['numeric']
    299299        self.assertIn('numeric', type_cache)
     300        self.assertEqual(type_info, 'numeric')
    300301        self.assertEqual(type_info.oid, 1700)
    301         self.assertEqual(type_info.name, 'numeric')
    302302        self.assertEqual(type_info.type, 'b')  # base
    303303        self.assertEqual(type_info.category, 'N')  # numeric
     
    312312        self.assertEqual(cols[0].name, 'typname')
    313313        typname = type_cache[cols[0].type]
    314         self.assertEqual(typname.name, 'name')
     314        self.assertEqual(typname, 'name')
    315315        self.assertEqual(typname.type, 'b')  # base
    316316        self.assertEqual(typname.category, 'S')  # string
    317317        self.assertEqual(cols[3].name, 'typlen')
    318318        typlen = type_cache[cols[3].type]
    319         self.assertEqual(typlen.name, 'int2')
     319        self.assertEqual(typlen, 'int2')
    320320        self.assertEqual(typlen.type, 'b')  # base
    321321        self.assertEqual(typlen.category, 'N')  # numeric
     
    425425            self.assertEqual(cur.description[0].type_code, pgdb.FLOAT)
    426426            self.assertNotEqual(cur.description[0].type_code, pgdb.ARRAY)
     427            self.assertNotEqual(cur.description[0].type_code, pgdb.RECORD)
    427428        finally:
    428429            con.close()
     
    462463            self.assertEqual(cur.description[0].type_code, pgdb.DATETIME)
    463464            self.assertNotEqual(cur.description[0].type_code, pgdb.ARRAY)
     465            self.assertNotEqual(cur.description[0].type_code, pgdb.RECORD)
    464466        finally:
    465467            con.close()
     
    489491                " (%%d,%%s::int[],%%s::text[][])" % table, params)
    490492            cur.execute("select i, t from %s order by n" % table)
    491             self.assertEqual(cur.description[0].type_code, pgdb.ARRAY)
    492             self.assertEqual(cur.description[0].type_code, pgdb.NUMBER)
    493             self.assertEqual(cur.description[0].type_code, pgdb.INTEGER)
    494             self.assertEqual(cur.description[1].type_code, pgdb.ARRAY)
    495             self.assertEqual(cur.description[1].type_code, pgdb.STRING)
     493            d = cur.description
     494            self.assertEqual(d[0].type_code, pgdb.ARRAY)
     495            self.assertNotEqual(d[0].type_code, pgdb.RECORD)
     496            self.assertEqual(d[0].type_code, pgdb.NUMBER)
     497            self.assertEqual(d[0].type_code, pgdb.INTEGER)
     498            self.assertEqual(d[1].type_code, pgdb.ARRAY)
     499            self.assertNotEqual(d[1].type_code, pgdb.RECORD)
     500            self.assertEqual(d[1].type_code, pgdb.STRING)
    496501            rows = cur.fetchall()
    497502        finally:
     
    526531            type_code = cur.description[0].type_code
    527532            self.assertEqual(type_code, record)
     533            self.assertEqual(type_code, pgdb.RECORD)
     534            self.assertNotEqual(type_code, pgdb.ARRAY)
    528535            columns = con.type_cache.columns(type_code)
    529536            self.assertEqual(columns[0].name, 'name')
    530537            self.assertEqual(columns[1].name, 'age')
    531             self.assertEqual(con.type_cache[columns[0].type].name, 'varchar')
    532             self.assertEqual(con.type_cache[columns[1].type].name, 'int4')
     538            self.assertEqual(con.type_cache[columns[0].type], 'varchar')
     539            self.assertEqual(con.type_cache[columns[1].type], 'int4')
    533540            rows = cur.fetchall()
    534541        finally:
     
    879886        self.assertEqual('_char', pgdb.ARRAY)
    880887        self.assertNotEqual('char', pgdb.ARRAY)
     888        self.assertEqual(pgdb.RECORD, pgdb.RECORD)
     889        self.assertNotEqual(pgdb.RECORD, pgdb.STRING)
     890        self.assertNotEqual(pgdb.RECORD, pgdb.ARRAY)
     891        self.assertEqual('record', pgdb.RECORD)
     892        self.assertNotEqual('_record', pgdb.RECORD)
    881893
    882894
Note: See TracChangeset for help on using the changeset viewer.