~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to test/base/test_inspect.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Jakub Wilk, Piotr Ożarowski
  • Date: 2013-07-06 20:53:52 UTC
  • mfrom: (1.4.23) (16.1.17 experimental)
  • Revision ID: package-import@ubuntu.com-20130706205352-ryppl1eto3illd79
Tags: 0.8.2-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Piotr Ożarowski ]
* New upstream release
* Upload to unstable
* Build depend on python3-all instead of -dev, extensions are not built for
  Python 3.X 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""test the inspection registry system."""
 
2
 
 
3
from sqlalchemy.testing import eq_, assert_raises_message
 
4
from sqlalchemy import exc, util
 
5
from sqlalchemy import inspection, inspect
 
6
from sqlalchemy.testing import fixtures
 
7
 
 
8
class TestFixture(object):
 
9
    pass
 
10
 
 
11
class TestInspection(fixtures.TestBase):
 
12
 
 
13
    def tearDown(self):
 
14
        for type_ in list(inspection._registrars):
 
15
            if issubclass(type_, TestFixture):
 
16
                del inspection._registrars[type_]
 
17
 
 
18
    def test_def_insp(self):
 
19
        class SomeFoo(TestFixture):
 
20
            pass
 
21
 
 
22
        @inspection._inspects(SomeFoo)
 
23
        def insp_somefoo(subject):
 
24
            return {"insp":subject}
 
25
 
 
26
        somefoo = SomeFoo()
 
27
        insp = inspect(somefoo)
 
28
        assert insp["insp"] is somefoo
 
29
 
 
30
    def test_no_inspect(self):
 
31
        class SomeFoo(TestFixture):
 
32
            pass
 
33
 
 
34
        assert_raises_message(
 
35
            exc.NoInspectionAvailable,
 
36
            "No inspection system is available for object of type ",
 
37
            inspect, SomeFoo
 
38
        )
 
39
 
 
40
    def test_class_insp(self):
 
41
        class SomeFoo(TestFixture):
 
42
            pass
 
43
 
 
44
        class SomeFooInspect(object):
 
45
            def __init__(self, target):
 
46
                self.target = target
 
47
        SomeFooInspect = inspection._inspects(SomeFoo)(SomeFooInspect)
 
48
 
 
49
        somefoo = SomeFoo()
 
50
        insp = inspect(somefoo)
 
51
        assert isinstance(insp, SomeFooInspect)
 
52
        assert insp.target is somefoo
 
53
 
 
54
    def test_hierarchy_insp(self):
 
55
        class SomeFoo(TestFixture):
 
56
            pass
 
57
 
 
58
        class SomeSubFoo(SomeFoo):
 
59
            pass
 
60
 
 
61
        @inspection._inspects(SomeFoo)
 
62
        def insp_somefoo(subject):
 
63
            return 1
 
64
 
 
65
        @inspection._inspects(SomeSubFoo)
 
66
        def insp_somesubfoo(subject):
 
67
            return 2
 
68
 
 
69
        somefoo = SomeFoo()
 
70
        eq_(inspect(SomeFoo()), 1)
 
71
        eq_(inspect(SomeSubFoo()), 2)