File: testdbc2.py

package info (click to toggle)
python-contract 1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze
  • size: 268 kB
  • ctags: 305
  • sloc: python: 1,159; makefile: 56
file content (44 lines) | stat: -rwxr-xr-x 752 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
"""Test inner/outer classes

>>> outer.a
5
>>> o = outer()
>>> o.a, o.b
(5, 6)
>>> o.foo()
5 5 6
"""

class outer:
    a = 5

    def __init__(self):
        self.b = 6

    def foo(self):
        print outer.a, self.a, self.b

    class inner:
        """test inner classes.

        inv: self.c == 7
        """
        c = 7
        def __init__(self):
            self.d = 8

        def foo(self):
            print outer.a, self.c, self.d

def _test():
    import contract, doctest, testdbc2
    contract.checkmod(testdbc2)
    return doctest.testmod(testdbc2)

if __name__ == '__main__':
    t = _test()
    if t[0] == 0:
       print "test: %d tests succeeded" % t[1]
    else:
       print "test: %d/%d tests failed" % t