Here are the examples of the python api sqlalchemy.orm.instrumentation.register_class taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
179 Examples
3
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_null_instrumentation(self):
class Foo(MyBaseClass):
pass
register_class(Foo)
attributes.register_attribute(
Foo, "name", uselist=False, useobject=False
)
attributes.register_attribute(
Foo, "bars", uselist=True, trackparent=True, useobject=True
)
assert Foo.name == attributes.manager_of_class(Foo)["name"]
assert Foo.bars == attributes.manager_of_class(Foo)["bars"]
def test_alternate_finders(self):
3
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_standard(self):
class A(object):
pass
register_class(A)
eq_(type(manager_of_class(A)), instrumentation.ClassManager)
def test_nativeext_interfaceexact(self):
3
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_nativeext_interfaceexact(self):
class A(object):
__sa_instrumentation_manager__ = (
instrumentation.InstrumentationManager
)
register_class(A)
ne_(type(manager_of_class(A)), instrumentation.ClassManager)
def test_nativeext_submanager(self):
3
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_nativeext_submanager(self):
class Mine(instrumentation.ClassManager):
pass
class A(object):
__sa_instrumentation_manager__ = Mine
register_class(A)
eq_(type(manager_of_class(A)), Mine)
@modifies_instrumentation_finders
3
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_customfinder_greedy(self):
class Mine(instrumentation.ClassManager):
pass
class A(object):
pass
def find(cls):
return Mine
instrumentation.instrumentation_finders.insert(0, find)
register_class(A)
eq_(type(manager_of_class(A)), Mine)
@modifies_instrumentation_finders
3
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_customfinder_pass(self):
class A(object):
pass
def find(cls):
return None
instrumentation.instrumentation_finders.insert(0, find)
register_class(A)
eq_(type(manager_of_class(A)), instrumentation.ClassManager)
class InstrumentationCollisionTest(_ExtBase, fixtures.ORMTest):
3
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_subclassed(self):
class MyEvents(events.InstanceEvents):
pass
class MyClassManager(instrumentation.ClassManager):
dispatch = event.dispatcher(MyEvents)
instrumentation.instrumentation_finders.insert(
0, lambda cls: MyClassManager
)
class A(object):
pass
register_class(A)
manager = instrumentation.manager_of_class(A)
assert issubclass(manager.dispatch._events, MyEvents)
3
Source : test_attributes.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _scalar_obj_fixture(self):
class A(object):
pass
class B(object):
pass
instrumentation.register_class(A)
instrumentation.register_class(B)
attributes.register_attribute(A, "b", uselist=False, useobject=True)
return A, B
def _collection_obj_fixture(self):
3
Source : test_attributes.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _collection_obj_fixture(self):
class A(object):
pass
class B(object):
pass
instrumentation.register_class(A)
instrumentation.register_class(B)
attributes.register_attribute(A, "b", uselist=True, useobject=True)
return A, B
def test_scalar_obj_remove_invalid(self):
3
Source : test_attributes.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_state_gc(self):
"""test that InstanceState always has a dict, even after host
object gc'ed."""
class Foo(object):
pass
instrumentation.register_class(Foo)
f = Foo()
state = attributes.instance_state(f)
f.bar = "foo"
eq_(state.dict, {"bar": "foo", state.manager.STATE_ATTR: state})
del f
gc_collect()
assert state.obj() is None
assert state.dict == {}
@testing.requires.predictable_gc
3
Source : test_attributes.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_descriptorattributes(self):
"""changeset: 1633 broke ability to use ORM to map classes with
unusual descriptor attributes (for example, classes that inherit
from ones implementing zope.interface.Interface). This is a
simple regression test to prevent that defect. """
class des(object):
def __get__(self, instance, owner):
raise AttributeError("fake attribute")
class Foo(object):
A = des()
instrumentation.register_class(Foo)
instrumentation.unregister_class(Foo)
def test_collectionclasses(self):
3
Source : test_attributes.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _fixture(self, uselist, useobject, active_history, **kw):
class Foo(fixtures.BasicEntity):
pass
instrumentation.register_class(Foo)
attributes.register_attribute(
Foo,
"someattr",
uselist=uselist,
useobject=useobject,
active_history=active_history,
**kw
)
return Foo
def _two_obj_fixture(self, uselist, active_history=False):
3
Source : test_attributes.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_flag_modified(self):
canary = Mock()
class Foo(object):
pass
instrumentation.register_class(Foo)
attributes.register_attribute(Foo, "bar")
event.listen(Foo.bar, "modified", canary)
f1 = Foo()
f1.bar = "hi"
attributes.flag_modified(f1, "bar")
eq_(
canary.mock_calls,
[call(f1, attributes.Event(Foo.bar.impl, attributes.OP_MODIFIED))],
)
def test_none_init_scalar(self):
3
Source : test_attributes.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_none_init_scalar(self):
canary = Mock()
class Foo(object):
pass
instrumentation.register_class(Foo)
attributes.register_attribute(Foo, "bar")
event.listen(Foo.bar, "set", canary)
f1 = Foo()
eq_(f1.bar, None)
# reversal of approach in #3061
eq_(canary.mock_calls, [])
def test_none_init_object(self):
3
Source : test_attributes.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_none_init_object(self):
canary = Mock()
class Foo(object):
pass
instrumentation.register_class(Foo)
attributes.register_attribute(Foo, "bar", useobject=True)
event.listen(Foo.bar, "set", canary)
f1 = Foo()
eq_(f1.bar, None)
# reversal of approach in #3061
eq_(canary.mock_calls, [])
def test_none_init_collection(self):
3
Source : test_attributes.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_none_init_collection(self):
canary = Mock()
class Foo(object):
pass
instrumentation.register_class(Foo)
attributes.register_attribute(Foo, "bar", useobject=True, uselist=True)
event.listen(Foo.bar, "set", canary)
f1 = Foo()
eq_(f1.bar, [])
# reversal of approach in #3061
eq_(canary.mock_calls, [])
class EventPropagateTest(fixtures.TestBase):
3
Source : test_attributes.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def setUp(self):
class A(object):
pass
class B(object):
pass
self.A = A
self.B = B
instrumentation.register_class(A)
instrumentation.register_class(B)
attributes.register_attribute(A, "bs", uselist=True, useobject=True)
def test_expired(self):
3
Source : test_collection.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_referenced_by_owner(self):
class Foo(object):
pass
instrumentation.register_class(Foo)
attributes.register_attribute(
Foo, "attr", uselist=True, useobject=True
)
f1 = Foo()
f1.attr.append(3)
adapter = collections.collection_adapter(f1.attr)
assert adapter._referenced_by_owner
f1.attr = []
assert not adapter._referenced_by_owner
3
Source : test_instrumentation.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def register(self, cls, canary):
original_init = cls.__init__
instrumentation.register_class(cls)
ne_(cls.__init__, original_init)
manager = instrumentation.manager_of_class(cls)
def init(state, args, kwargs):
canary.append((cls, "init", state.class_))
event.listen(manager, "init", init, raw=True)
def test_ai(self):
3
Source : test_instrumentation.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _instrument(self, cls):
manager = instrumentation.register_class(cls)
canary = []
def check(target, args, kwargs):
canary.append((args, kwargs))
event.listen(manager, "init", check)
return cls, canary
def test_kw_only_args(self):
3
Source : test_instrumentation.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_uninstrument(self):
class A(object):
pass
manager = instrumentation.register_class(A)
attributes.register_attribute(A, "x", uselist=False, useobject=False)
assert instrumentation.manager_of_class(A) is manager
instrumentation.unregister_class(A)
assert instrumentation.manager_of_class(A) is None
assert not hasattr(A, "x")
# I prefer 'is' here but on pypy
# it seems only == works
assert A.__init__ == object.__init__
def test_compileonattr_rel_backref_a(self):
3
Source : test_extendedattr.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_standard(self):
class A:
pass
register_class(A)
eq_(type(manager_of_class(A)), instrumentation.ClassManager)
def test_nativeext_interfaceexact(self):
3
Source : test_extendedattr.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_nativeext_interfaceexact(self):
class A:
__sa_instrumentation_manager__ = (
instrumentation.InstrumentationManager
)
register_class(A)
ne_(type(manager_of_class(A)), instrumentation.ClassManager)
def test_nativeext_submanager(self):
3
Source : test_extendedattr.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_nativeext_submanager(self):
class Mine(instrumentation.ClassManager):
pass
class A:
__sa_instrumentation_manager__ = Mine
register_class(A)
eq_(type(manager_of_class(A)), Mine)
@modifies_instrumentation_finders
3
Source : test_extendedattr.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_customfinder_greedy(self):
class Mine(instrumentation.ClassManager):
pass
class A:
pass
def find(cls):
return Mine
instrumentation.instrumentation_finders.insert(0, find)
register_class(A)
eq_(type(manager_of_class(A)), Mine)
@modifies_instrumentation_finders
3
Source : test_extendedattr.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_customfinder_pass(self):
class A:
pass
def find(cls):
return None
instrumentation.instrumentation_finders.insert(0, find)
register_class(A)
eq_(type(manager_of_class(A)), instrumentation.ClassManager)
class InstrumentationCollisionTest(_ExtBase, fixtures.ORMTest):
3
Source : test_extendedattr.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_subclassed(self):
class MyEvents(events.InstanceEvents):
pass
class MyClassManager(instrumentation.ClassManager):
dispatch = event.dispatcher(MyEvents)
instrumentation.instrumentation_finders.insert(
0, lambda cls: MyClassManager
)
class A:
pass
register_class(A)
manager = instrumentation.manager_of_class(A)
assert issubclass(manager.dispatch._events, MyEvents)
3
Source : test_attributes.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _scalar_obj_fixture(self):
class A:
pass
class B:
pass
instrumentation.register_class(A)
instrumentation.register_class(B)
attributes.register_attribute(A, "b", uselist=False, useobject=True)
return A, B
def _collection_obj_fixture(self):
3
Source : test_attributes.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _collection_obj_fixture(self):
class A:
pass
class B:
pass
instrumentation.register_class(A)
instrumentation.register_class(B)
attributes.register_attribute(A, "b", uselist=True, useobject=True)
return A, B
def test_scalar_obj_remove_invalid(self):
3
Source : test_attributes.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_state_gc(self):
"""test that InstanceState always has a dict, even after host
object gc'ed."""
class Foo:
pass
instrumentation.register_class(Foo)
f = Foo()
state = attributes.instance_state(f)
f.bar = "foo"
eq_(state.dict, {"bar": "foo", state.manager.STATE_ATTR: state})
del f
gc_collect()
assert state.obj() is None
assert state.dict == {}
@testing.requires.predictable_gc
3
Source : test_attributes.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_descriptorattributes(self):
"""changeset: 1633 broke ability to use ORM to map classes with
unusual descriptor attributes (for example, classes that inherit
from ones implementing zope.interface.Interface). This is a
simple regression test to prevent that defect."""
class des:
def __get__(self, instance, owner):
raise AttributeError("fake attribute")
class Foo:
A = des()
instrumentation.register_class(Foo)
instrumentation.unregister_class(Foo)
def test_collectionclasses(self):
3
Source : test_attributes.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def _fixture(self, uselist, useobject, active_history, **kw):
class Foo(fixtures.BasicEntity):
pass
instrumentation.register_class(Foo)
attributes.register_attribute(
Foo,
"someattr",
uselist=uselist,
useobject=useobject,
active_history=active_history,
**kw,
)
return Foo
def _two_obj_fixture(self, uselist, active_history=False):
3
Source : test_attributes.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_flag_modified(self):
canary = Mock()
class Foo:
pass
instrumentation.register_class(Foo)
attributes.register_attribute(Foo, "bar")
event.listen(Foo.bar, "modified", canary)
f1 = Foo()
f1.bar = "hi"
attributes.flag_modified(f1, "bar")
eq_(
canary.mock_calls,
[call(f1, attributes.Event(Foo.bar.impl, attributes.OP_MODIFIED))],
)
def test_none_init_scalar(self):
3
Source : test_attributes.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_none_init_scalar(self):
canary = Mock()
class Foo:
pass
instrumentation.register_class(Foo)
attributes.register_attribute(Foo, "bar")
event.listen(Foo.bar, "set", canary)
f1 = Foo()
eq_(f1.bar, None)
# reversal of approach in #3061
eq_(canary.mock_calls, [])
def test_none_init_object(self):
3
Source : test_attributes.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_none_init_object(self):
canary = Mock()
class Foo:
pass
instrumentation.register_class(Foo)
attributes.register_attribute(Foo, "bar", useobject=True)
event.listen(Foo.bar, "set", canary)
f1 = Foo()
eq_(f1.bar, None)
# reversal of approach in #3061
eq_(canary.mock_calls, [])
def test_none_init_collection(self):
3
Source : test_attributes.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def setup_test(self):
class A:
pass
class B:
pass
self.A = A
self.B = B
instrumentation.register_class(A)
instrumentation.register_class(B)
attributes.register_attribute(A, "bs", uselist=True, useobject=True)
def test_bulk_replace_resets_empty(self):
3
Source : test_attributes.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def setup_test(self):
class A:
pass
class B:
pass
self.A = A
self.B = B
instrumentation.register_class(A)
instrumentation.register_class(B)
attributes.register_attribute(A, "bs", uselist=True, useobject=True)
def test_expired(self):
3
Source : test_collection.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_referenced_by_owner(self):
class Foo:
pass
instrumentation.register_class(Foo)
attributes.register_attribute(
Foo, "attr", uselist=True, useobject=True
)
f1 = Foo()
f1.attr.append(3)
adapter = collections.collection_adapter(f1.attr)
assert adapter._referenced_by_owner
f1.attr = []
assert not adapter._referenced_by_owner
3
Source : test_instrumentation.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_uninstrument(self):
class A:
pass
manager = instrumentation.register_class(A)
attributes.register_attribute(A, "x", uselist=False, useobject=False)
assert instrumentation.manager_of_class(A) is manager
instrumentation.unregister_class(A)
assert instrumentation.manager_of_class(A) is None
assert not hasattr(A, "x")
assert A.__init__ == object.__init__
def test_compileonattr_rel_backref_a(self):
0
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_instance_dict(self):
class User(MyClass):
pass
register_class(User)
attributes.register_attribute(
User, "user_id", uselist=False, useobject=False
)
attributes.register_attribute(
User, "user_name", uselist=False, useobject=False
)
attributes.register_attribute(
User, "email_address", uselist=False, useobject=False
)
u = User()
u.user_id = 7
u.user_name = "john"
u.email_address = "[email protected]"
eq_(
u.__dict__,
{
"_my_state": u._my_state,
"_goofy_dict": {
"user_id": 7,
"user_name": "john",
"email_address": "[email protected]",
},
},
)
def test_basic(self):
0
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_basic(self):
for base in (object, MyBaseClass, MyClass):
class User(base):
pass
register_class(User)
attributes.register_attribute(
User, "user_id", uselist=False, useobject=False
)
attributes.register_attribute(
User, "user_name", uselist=False, useobject=False
)
attributes.register_attribute(
User, "email_address", uselist=False, useobject=False
)
u = User()
u.user_id = 7
u.user_name = "john"
u.email_address = "[email protected]"
eq_(u.user_id, 7)
eq_(u.user_name, "john")
eq_(u.email_address, "[email protected]")
attributes.instance_state(u)._commit_all(
attributes.instance_dict(u)
)
eq_(u.user_id, 7)
eq_(u.user_name, "john")
eq_(u.email_address, "[email protected]")
u.user_name = "heythere"
u.email_address = "[email protected]"
eq_(u.user_id, 7)
eq_(u.user_name, "heythere")
eq_(u.email_address, "[email protected]")
def test_deferred(self):
0
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_deferred(self):
for base in (object, MyBaseClass, MyClass):
class Foo(base):
pass
data = {"a": "this is a", "b": 12}
def loader(state, keys):
for k in keys:
state.dict[k] = data[k]
return attributes.ATTR_WAS_SET
manager = register_class(Foo)
manager.deferred_scalar_loader = loader
attributes.register_attribute(
Foo, "a", uselist=False, useobject=False
)
attributes.register_attribute(
Foo, "b", uselist=False, useobject=False
)
if base is object:
assert Foo not in (
instrumentation._instrumentation_factory._state_finders
)
else:
assert Foo in (
instrumentation._instrumentation_factory._state_finders
)
f = Foo()
attributes.instance_state(f)._expire(
attributes.instance_dict(f), set()
)
eq_(f.a, "this is a")
eq_(f.b, 12)
f.a = "this is some new a"
attributes.instance_state(f)._expire(
attributes.instance_dict(f), set()
)
eq_(f.a, "this is a")
eq_(f.b, 12)
attributes.instance_state(f)._expire(
attributes.instance_dict(f), set()
)
f.a = "this is another new a"
eq_(f.a, "this is another new a")
eq_(f.b, 12)
attributes.instance_state(f)._expire(
attributes.instance_dict(f), set()
)
eq_(f.a, "this is a")
eq_(f.b, 12)
del f.a
eq_(f.a, None)
eq_(f.b, 12)
attributes.instance_state(f)._commit_all(
attributes.instance_dict(f)
)
eq_(f.a, None)
eq_(f.b, 12)
def test_inheritance(self):
0
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_inheritance(self):
"""tests that attributes are polymorphic"""
for base in (object, MyBaseClass, MyClass):
class Foo(base):
pass
class Bar(Foo):
pass
register_class(Foo)
register_class(Bar)
def func1(state, passive):
return "this is the foo attr"
def func2(state, passive):
return "this is the bar attr"
def func3(state, passive):
return "this is the shared attr"
attributes.register_attribute(
Foo, "element", uselist=False, callable_=func1, useobject=True
)
attributes.register_attribute(
Foo, "element2", uselist=False, callable_=func3, useobject=True
)
attributes.register_attribute(
Bar, "element", uselist=False, callable_=func2, useobject=True
)
x = Foo()
y = Bar()
assert x.element == "this is the foo attr"
assert y.element == "this is the bar attr", y.element
assert x.element2 == "this is the shared attr"
assert y.element2 == "this is the shared attr"
def test_collection_with_backref(self):
0
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_collection_with_backref(self):
for base in (object, MyBaseClass, MyClass):
class Post(base):
pass
class Blog(base):
pass
register_class(Post)
register_class(Blog)
attributes.register_attribute(
Post,
"blog",
uselist=False,
backref="posts",
trackparent=True,
useobject=True,
)
attributes.register_attribute(
Blog,
"posts",
uselist=True,
backref="blog",
trackparent=True,
useobject=True,
)
b = Blog()
(p1, p2, p3) = (Post(), Post(), Post())
b.posts.append(p1)
b.posts.append(p2)
b.posts.append(p3)
self.assert_(b.posts == [p1, p2, p3])
self.assert_(p2.blog is b)
p3.blog = None
self.assert_(b.posts == [p1, p2])
p4 = Post()
p4.blog = b
self.assert_(b.posts == [p1, p2, p4])
p4.blog = b
p4.blog = b
self.assert_(b.posts == [p1, p2, p4])
# assert no failure removing None
p5 = Post()
p5.blog = None
del p5.blog
def test_history(self):
0
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_history(self):
for base in (object, MyBaseClass, MyClass):
class Foo(base):
pass
class Bar(base):
pass
register_class(Foo)
register_class(Bar)
attributes.register_attribute(
Foo, "name", uselist=False, useobject=False
)
attributes.register_attribute(
Foo, "bars", uselist=True, trackparent=True, useobject=True
)
attributes.register_attribute(
Bar, "name", uselist=False, useobject=False
)
f1 = Foo()
f1.name = "f1"
eq_(
attributes.get_state_history(
attributes.instance_state(f1), "name"
),
(["f1"], (), ()),
)
b1 = Bar()
b1.name = "b1"
f1.bars.append(b1)
eq_(
attributes.get_state_history(
attributes.instance_state(f1), "bars"
),
([b1], [], []),
)
attributes.instance_state(f1)._commit_all(
attributes.instance_dict(f1)
)
attributes.instance_state(b1)._commit_all(
attributes.instance_dict(b1)
)
eq_(
attributes.get_state_history(
attributes.instance_state(f1), "name"
),
((), ["f1"], ()),
)
eq_(
attributes.get_state_history(
attributes.instance_state(f1), "bars"
),
((), [b1], ()),
)
f1.name = "f1mod"
b2 = Bar()
b2.name = "b2"
f1.bars.append(b2)
eq_(
attributes.get_state_history(
attributes.instance_state(f1), "name"
),
(["f1mod"], (), ["f1"]),
)
eq_(
attributes.get_state_history(
attributes.instance_state(f1), "bars"
),
([b2], [b1], []),
)
f1.bars.remove(b1)
eq_(
attributes.get_state_history(
attributes.instance_state(f1), "bars"
),
([b2], [], [b1]),
)
def test_null_instrumentation(self):
0
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_alternate_finders(self):
"""Ensure the generic finder front-end deals with edge cases."""
class Unknown(object):
pass
class Known(MyBaseClass):
pass
register_class(Known)
k, u = Known(), Unknown()
assert instrumentation.manager_of_class(Unknown) is None
assert instrumentation.manager_of_class(Known) is not None
assert instrumentation.manager_of_class(None) is None
assert attributes.instance_state(k) is not None
assert_raises((AttributeError, KeyError), attributes.instance_state, u)
assert_raises(
(AttributeError, KeyError), attributes.instance_state, None
)
def test_unmapped_not_type_error(self):
0
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_none(self):
class A(object):
pass
register_class(A)
def mgr_factory(cls):
return instrumentation.ClassManager(cls)
class B(object):
__sa_instrumentation_manager__ = staticmethod(mgr_factory)
register_class(B)
class C(object):
__sa_instrumentation_manager__ = instrumentation.ClassManager
register_class(C)
def test_single_down(self):
0
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_single_down(self):
class A(object):
pass
register_class(A)
def mgr_factory(cls):
return instrumentation.ClassManager(cls)
class B(A):
__sa_instrumentation_manager__ = staticmethod(mgr_factory)
assert_raises_message(
TypeError,
"multiple instrumentation implementations",
register_class,
B,
)
def test_single_up(self):
0
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_single_up(self):
class A(object):
pass
# delay registration
def mgr_factory(cls):
return instrumentation.ClassManager(cls)
class B(A):
__sa_instrumentation_manager__ = staticmethod(mgr_factory)
register_class(B)
assert_raises_message(
TypeError,
"multiple instrumentation implementations",
register_class,
A,
)
def test_diamond_b1(self):
0
Source : test_extendedattr.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_diamond_b2(self):
def mgr_factory(cls):
return instrumentation.ClassManager(cls)
class A(object):
pass
class B1(A):
pass
class B2(A):
__sa_instrumentation_manager__ = staticmethod(mgr_factory)
class C(object):
pass
register_class(B2)
assert_raises_message(
TypeError,
"multiple instrumentation implementations",
register_class,
B1,
)
def test_diamond_c_b(self):
See More Examples