"""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)

@@ -884,47 +884,8 @@
 ss%0A%0A
-        @inspection._inspects(SomeFoo)%0A
     
@@ -994,16 +994,87 @@
 = target
+%0A        SomeFooInspect = inspection._inspects(SomeFoo)(SomeFooInspect)
 %0A%0A      

fix 2.5 failure