diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-04-23 12:03:54 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-04-23 12:03:54 -0400 |
| commit | 54017d9de202ed67072a352ce2f6dbfd74bf48f3 (patch) | |
| tree | a632045bd8a5e7d5932d69d5f436bc27f1b9788d /test/base | |
| parent | 8f35f7a803c67f4ab0620686592a021a24e4b331 (diff) | |
| parent | f7bb3b17e6df09caa56c20c722364fc52edf7afc (diff) | |
| download | sqlalchemy-54017d9de202ed67072a352ce2f6dbfd74bf48f3.tar.gz | |
merge patch for [ticket:2208]. This still needs documentation.
Diffstat (limited to 'test/base')
| -rw-r--r-- | test/base/test_inspect.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/base/test_inspect.py b/test/base/test_inspect.py new file mode 100644 index 000000000..b95b7d8c5 --- /dev/null +++ b/test/base/test_inspect.py @@ -0,0 +1,62 @@ +"""test the inspection registry system.""" + +from test.lib.testing import eq_, assert_raises +from sqlalchemy import exc, util +from sqlalchemy import inspection, inspect +from test.lib import fixtures + +class TestFixture(object): + pass + +class TestEvents(fixtures.TestBase): + """Test class- and instance-level event registration.""" + + def tearDown(self): + for type_ in list(inspection._registrars): + if issubclass(type_, TestFixture): + del inspection._registrars[type_] + + def test_def_insp(self): + class SomeFoo(TestFixture): + pass + + @inspection._inspects(SomeFoo) + def insp_somefoo(subject): + return {"insp":subject} + + somefoo = SomeFoo() + insp = inspect(somefoo) + assert insp["insp"] is somefoo + + def test_class_insp(self): + class SomeFoo(TestFixture): + pass + + @inspection._inspects(SomeFoo) + class SomeFooInspect(object): + def __init__(self, target): + self.target = target + + somefoo = SomeFoo() + insp = inspect(somefoo) + assert isinstance(insp, SomeFooInspect) + assert insp.target is somefoo + + def test_hierarchy_insp(self): + class SomeFoo(TestFixture): + pass + + class SomeSubFoo(SomeFoo): + pass + + @inspection._inspects(SomeFoo) + def insp_somefoo(subject): + return 1 + + @inspection._inspects(SomeSubFoo) + def insp_somesubfoo(subject): + return 2 + + somefoo = SomeFoo() + eq_(inspect(SomeFoo()), 1) + eq_(inspect(SomeSubFoo()), 2) |
