def _prep_testing_database(options, file_config): from testlib import engines from sqlalchemy import schema try: # also create alt schemas etc. here? if options.dropfirst: e = engines.utf8_engine() existing = e.table_names() if existing: if not options.quiet: print "Dropping existing tables in database: " + db_url try: print "Tables: %s" % ', '.join(existing) except: pass print "Abort within 5 seconds..." time.sleep(5) md = schema.MetaData(e, reflect=True) md.drop_all() e.dispose() except (KeyboardInterrupt, SystemExit): raise except Exception, e: if not options.quiet: warnings.warn( RuntimeWarning("Error checking for existing tables in testing " "database: %s" % e))
def test_basic(self): try: # the 'convert_unicode' should not get in the way of the reflection # process. reflecttable for oracle, postgres (others?) expect non-unicode # strings in result sets/bind params bind = engines.utf8_engine(options={'convert_unicode':True}) metadata = MetaData(bind) if testing.against('sybase', 'maxdb', 'oracle'): names = set(['plain']) else: names = set([u'plain', u'Unit\u00e9ble', u'\u6e2c\u8a66']) for name in names: Table(name, metadata, Column('id', Integer, Sequence(name + "_id_seq"), primary_key=True)) metadata.create_all() reflected = set(bind.table_names()) if not names.issubset(reflected): # Python source files in the utf-8 coding seem to normalize # literals as NFC (and the above are explicitly NFC). Maybe # this database normalizes NFD on reflection. nfc = set([unicodedata.normalize('NFC', n) for n in names]) self.assert_(nfc == names) # Yep. But still ensure that bulk reflection and create/drop # work with either normalization. r = MetaData(bind, reflect=True) r.drop_all() r.create_all() finally: metadata.drop_all() bind.dispose()
def _prep_testing_database(options, file_config): from testlib import engines from sqlalchemy import schema try: # also create alt schemas etc. here? if options.dropfirst: e = engines.utf8_engine() existing = e.table_names() if existing: if not options.quiet: print "Dropping existing tables in database: " + db_url try: print "Tables: %s" % ', '.join(existing) except: pass print "Abort within 5 seconds..." time.sleep(5) md = schema.MetaData(e, reflect=True) md.drop_all() e.dispose() except (KeyboardInterrupt, SystemExit): raise except Exception, e: if not options.quiet: warnings.warn(RuntimeWarning( "Error checking for existing tables in testing " "database: %s" % e))
def test_basic(self): try: # the 'convert_unicode' should not get in the way of the reflection # process. reflecttable for oracle, postgres (others?) expect non-unicode # strings in result sets/bind params bind = engines.utf8_engine(options={'convert_unicode':True}) metadata = MetaData(bind) if testing.against('sybase', 'maxdb', 'oracle', 'mssql'): names = set(['plain']) else: names = set([u'plain', u'Unit\u00e9ble', u'\u6e2c\u8a66']) for name in names: Table(name, metadata, Column('id', sa.Integer, sa.Sequence(name + "_id_seq"), primary_key=True)) metadata.create_all() reflected = set(bind.table_names()) if not names.issubset(reflected): # Python source files in the utf-8 coding seem to normalize # literals as NFC (and the above are explicitly NFC). Maybe # this database normalizes NFD on reflection. nfc = set([unicodedata.normalize('NFC', n) for n in names]) self.assert_(nfc == names) # Yep. But still ensure that bulk reflection and create/drop # work with either normalization. r = MetaData(bind, reflect=True) r.drop_all() r.create_all() finally: metadata.drop_all() bind.dispose()
def setUpAll(self): global unicode_bind, metadata, t1, t2, t3 unicode_bind = utf8_engine() metadata = MetaData(unicode_bind) t1 = Table( 'unitable1', metadata, Column(u'méil', Integer, primary_key=True), Column(u'\u6e2c\u8a66', Integer), test_needs_fk=True, ) t2 = Table( u'Unitéble2', metadata, Column(u'méil', Integer, primary_key=True, key="a"), Column(u'\u6e2c\u8a66', Integer, ForeignKey(u'unitable1.méil'), key="b"), test_needs_fk=True, ) # Few DBs support Unicode foreign keys if testing.against('sqlite'): t3 = Table( u'\u6e2c\u8a66', metadata, Column(u'\u6e2c\u8a66_id', Integer, primary_key=True, autoincrement=False), Column(u'unitable1_\u6e2c\u8a66', Integer, ForeignKey(u'unitable1.\u6e2c\u8a66')), Column(u'Unitéble2_b', Integer, ForeignKey(u'Unitéble2.b')), Column(u'\u6e2c\u8a66_self', Integer, ForeignKey(u'\u6e2c\u8a66.\u6e2c\u8a66_id')), test_needs_fk=True, ) else: t3 = Table( u'\u6e2c\u8a66', metadata, Column(u'\u6e2c\u8a66_id', Integer, primary_key=True, autoincrement=False), Column(u'unitable1_\u6e2c\u8a66', Integer), Column(u'Unitéble2_b', Integer), Column(u'\u6e2c\u8a66_self', Integer), test_needs_fk=True, ) metadata.create_all()
def setUpAll(self): global unicode_bind, metadata, t1, t2, t3 unicode_bind = utf8_engine() metadata = MetaData(unicode_bind) t1 = Table('unitable1', metadata, Column(u'méil', Integer, primary_key=True), Column(u'\u6e2c\u8a66', Integer), test_needs_fk=True, ) t2 = Table(u'Unitéble2', metadata, Column(u'méil', Integer, primary_key=True, key="a"), Column(u'\u6e2c\u8a66', Integer, ForeignKey(u'unitable1.méil'), key="b" ), test_needs_fk=True, ) # Few DBs support Unicode foreign keys if testing.against('sqlite'): t3 = Table(u'\u6e2c\u8a66', metadata, Column(u'\u6e2c\u8a66_id', Integer, primary_key=True, autoincrement=False), Column(u'unitable1_\u6e2c\u8a66', Integer, ForeignKey(u'unitable1.\u6e2c\u8a66') ), Column(u'Unitéble2_b', Integer, ForeignKey(u'Unitéble2.b') ), Column(u'\u6e2c\u8a66_self', Integer, ForeignKey(u'\u6e2c\u8a66.\u6e2c\u8a66_id') ), test_needs_fk=True, ) else: t3 = Table(u'\u6e2c\u8a66', metadata, Column(u'\u6e2c\u8a66_id', Integer, primary_key=True, autoincrement=False), Column(u'unitable1_\u6e2c\u8a66', Integer), Column(u'Unitéble2_b', Integer), Column(u'\u6e2c\u8a66_self', Integer), test_needs_fk=True, ) metadata.create_all()
def setUpAll(self): global unicode_bind, metadata, t1, t2, t3 unicode_bind = utf8_engine() metadata = MetaData(unicode_bind) t1 = Table( "unitable1", metadata, Column(u"méil", Integer, primary_key=True), Column(u"\u6e2c\u8a66", Integer), test_needs_fk=True, ) t2 = Table( u"Unitéble2", metadata, Column(u"méil", Integer, primary_key=True, key="a"), Column(u"\u6e2c\u8a66", Integer, ForeignKey(u"unitable1.méil"), key="b"), test_needs_fk=True, ) # Few DBs support Unicode foreign keys if testing.against("sqlite"): t3 = Table( u"\u6e2c\u8a66", metadata, Column(u"\u6e2c\u8a66_id", Integer, primary_key=True, autoincrement=False), Column(u"unitable1_\u6e2c\u8a66", Integer, ForeignKey(u"unitable1.\u6e2c\u8a66")), Column(u"Unitéble2_b", Integer, ForeignKey(u"Unitéble2.b")), Column(u"\u6e2c\u8a66_self", Integer, ForeignKey(u"\u6e2c\u8a66.\u6e2c\u8a66_id")), test_needs_fk=True, ) else: t3 = Table( u"\u6e2c\u8a66", metadata, Column(u"\u6e2c\u8a66_id", Integer, primary_key=True, autoincrement=False), Column(u"unitable1_\u6e2c\u8a66", Integer), Column(u"Unitéble2_b", Integer), Column(u"\u6e2c\u8a66_self", Integer), test_needs_fk=True, ) metadata.create_all()