本文整理汇总了Python中sqlalchemy.exc.SAWarning方法的典型用法代码示例。如果您正苦于以下问题:Python exc.SAWarning方法的具体用法?Python exc.SAWarning怎么用?Python exc.SAWarning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.exc
的用法示例。
在下文中一共展示了exc.SAWarning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: emits_warning_on
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def emits_warning_on(db, *messages):
"""Mark a test as emitting a warning on a specific dialect.
With no arguments, squelches all SAWarning failures. Or pass one or more
strings; these will be matched to the root of the warning description by
warnings.filterwarnings().
Note that emits_warning_on does **not** assert that the warnings
were in fact seen.
"""
@decorator
def decorate(fn, *args, **kw):
with expect_warnings_on(db, assert_=False, *messages):
return fn(*args, **kw)
return decorate
示例2: emits_warning_on
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def emits_warning_on(db, *messages):
"""Mark a test as emitting a warning on a specific dialect.
With no arguments, squelches all SAWarning failures. Or pass one or more
strings; these will be matched to the root of the warning description by
warnings.filterwarnings().
Note that emits_warning_on does **not** assert that the warnings
were in fact seen.
"""
@decorator
def decorate(fn, *args, **kw):
with expect_warnings_on(db, *messages):
return fn(*args, **kw)
return decorate
示例3: upgrade
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def upgrade(migrate_engine):
# ignore reflection warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=sa_exc.SAWarning)
metadata = MetaData()
metadata.bind = migrate_engine
harvest_source_table = Table('harvest_source', metadata, autoload=True)
package_table = Table('package', metadata, autoload=True)
harvested_document_table = Table('harvested_document', metadata,
Column('url', UnicodeText, nullable=False),
Column('guid', UnicodeText, default=u''),
Column('source_id', UnicodeText, ForeignKey('harvest_source.id')),
Column('package_id', UnicodeText, ForeignKey('package.id')),
)
harvested_document_table.c.url.drop()
harvested_document_table.c.guid.create(harvested_document_table)
harvested_document_table.c.source_id.create(harvested_document_table)
harvested_document_table.c.package_id.create(harvested_document_table)
示例4: new_test_app
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def new_test_app(options=None):
'''Create a test app.'''
config_path = '{}/testing.ini'.format(parent_dir)
if options:
tmp_cfg = configparser.ConfigParser()
tmp_cfg.read(config_path)
tmp_cfg['app:main'].update(options or {})
config_path = '{}/tmp_testing.ini'.format(parent_dir)
with open(config_path, 'w') as tmp_file:
tmp_cfg.write(tmp_file)
with warnings.catch_warnings():
# Suppress SAWarning: about Property _jsonapi_id being replaced by
# Propery _jsonapi_id every time a new app is instantiated.
warnings.simplefilter(
"ignore",
category=SAWarning
)
test_app = webtest.TestApp(get_app(config_path))
if options:
os.remove(config_path)
return test_app
示例5: expect_warnings
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def expect_warnings(*messages):
"""Context manager to expect warnings with the given messages."""
filters = [dict(action='ignore',
category=sa_exc.SAPendingDeprecationWarning)]
if not messages:
filters.append(dict(action='ignore',
category=sa_exc.SAWarning))
else:
filters.extend(dict(action='ignore',
message=message,
category=sa_exc.SAWarning)
for message in messages)
for f in filters:
warnings.filterwarnings(**f)
try:
yield
finally:
resetwarnings()
示例6: emits_warning_on
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def emits_warning_on(db, *warnings):
"""Mark a test as emitting a warning on a specific dialect.
With no arguments, squelches all SAWarning failures. Or pass one or more
strings; these will be matched to the root of the warning description by
warnings.filterwarnings().
"""
spec = db_spec(db)
@decorator
def decorate(fn, *args, **kw):
if isinstance(db, util.string_types):
if not spec(config._current):
return fn(*args, **kw)
else:
wrapped = emits_warning(*warnings)(fn)
return wrapped(*args, **kw)
else:
if not _is_excluded(*db):
return fn(*args, **kw)
else:
wrapped = emits_warning(*warnings)(fn)
return wrapped(*args, **kw)
return decorate
示例7: test_oracle_has_no_on_update_cascade
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def test_oracle_has_no_on_update_cascade(self):
bar = Table(
"bar",
self.metadata,
Column("id", Integer, primary_key=True),
Column(
"foo_id", Integer, ForeignKey("foo.id", onupdate="CASCADE")
),
)
assert_raises(exc.SAWarning, bar.create)
bat = Table(
"bat",
self.metadata,
Column("id", Integer, primary_key=True),
Column("foo_id", Integer),
ForeignKeyConstraint(["foo_id"], ["foo.id"], onupdate="CASCADE"),
)
assert_raises(exc.SAWarning, bat.create)
示例8: test_unknown_types
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def test_unknown_types(self):
from sqlalchemy.dialects.postgresql import base
ischema_names = base.PGDialect.ischema_names
base.PGDialect.ischema_names = {}
try:
m2 = MetaData(testing.db)
assert_raises(exc.SAWarning, Table, "testtable", m2, autoload=True)
@testing.emits_warning("Did not recognize type")
def warns():
m3 = MetaData(testing.db)
t3 = Table("testtable", m3, autoload=True)
assert t3.c.answer.type.__class__ == sa.types.NullType
finally:
base.PGDialect.ischema_names = ischema_names
示例9: test_notsane_warning
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def test_notsane_warning(self):
Foo = self.classes.Foo
save = testing.db.dialect.supports_sane_rowcount
testing.db.dialect.supports_sane_rowcount = False
try:
s1 = self._fixture()
f1 = Foo(value="f1")
f2 = Foo(value="f2")
s1.add_all((f1, f2))
s1.commit()
f1.value = "f1rev2"
assert_raises(sa.exc.SAWarning, s1.commit)
finally:
testing.db.dialect.supports_sane_rowcount = save
示例10: test_mismatch_version_col_warning
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def test_mismatch_version_col_warning(self):
Base, sub, base, Sub = (
self.classes.Base,
self.tables.sub,
self.tables.base,
self.classes.Sub,
)
mapper(Base, base, version_id_col=base.c.version_id)
assert_raises_message(
exc.SAWarning,
"Inheriting version_id_col 'version_id' does not "
"match inherited version_id_col 'version_id' and will not "
"automatically populate the inherited versioning column. "
"version_id_col should only be specified on "
"the base-most mapper that includes versioning.",
mapper,
Sub,
sub,
inherits=Base,
version_id_col=sub.c.version_id,
)
示例11: test_invalid_assignment_upwards
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def test_invalid_assignment_upwards(self):
"""test that we warn on assign of 'c' to a B, since we will have a
"C" row that has no joined row, which will cause object
deleted errors.
"""
B = self.classes.B
sess = Session()
b1 = B()
b1.class_name = "c"
sess.add(b1)
assert_raises_message(
sa_exc.SAWarning,
"Flushing object %s with incompatible "
"polymorphic identity 'c'; the object may not "
"refresh and/or load correctly" % instance_str(b1),
sess.flush,
)
示例12: test_entirely_oob_assignment
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def test_entirely_oob_assignment(self):
"""test warn on an unknown polymorphic identity.
"""
B = self.classes.B
sess = Session()
b1 = B()
b1.class_name = "xyz"
sess.add(b1)
assert_raises_message(
sa_exc.SAWarning,
"Flushing object %s with incompatible "
"polymorphic identity 'xyz'; the object may not "
"refresh and/or load correctly" % instance_str(b1),
sess.flush,
)
示例13: test_validate_on_upate
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def test_validate_on_upate(self):
C = self.classes.C
sess = Session()
c1 = C()
sess.add(c1)
sess.commit()
sess.expire(c1)
c1.class_name = "b"
assert_raises_message(
sa_exc.SAWarning,
"Flushing object %s with incompatible "
"polymorphic identity 'b'; the object may not "
"refresh and/or load correctly" % instance_str(c1),
sess.flush,
)
示例14: test_explicit_composite_pk
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def test_explicit_composite_pk(self):
person_mapper = mapper(Person, person_table)
mapper(
Employee,
employee_table,
inherits=person_mapper,
properties=dict(id=[employee_table.c.eid, person_table.c.id]),
primary_key=[person_table.c.id, employee_table.c.eid],
)
assert_raises_message(
sa_exc.SAWarning,
r"On mapper mapped class Employee->employees, "
"primary key column 'persons.id' is being "
"combined with distinct primary key column 'employees.eid' "
"in attribute 'id'. Use explicit properties to give "
"each column its own mapped attribute name.",
self._do_test,
True,
)
示例15: test_pk_fk_different
# 需要导入模块: from sqlalchemy import exc [as 别名]
# 或者: from sqlalchemy.exc import SAWarning [as 别名]
def test_pk_fk_different(self):
class Base(object):
pass
class Sub(Base):
pass
mapper(Base, base)
def go():
mapper(Sub, subtable_two, inherits=Base)
assert_raises_message(
sa_exc.SAWarning,
"Implicitly combining column base.base_id with "
"column subtable_two.base_id under attribute 'base_id'",
go,
)