File: testdbc7.py

package info (click to toggle)
python-contract 1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 396 kB
  • sloc: python: 1,177; makefile: 55
file content (47 lines) | stat: -rwxr-xr-x 833 bytes parent folder | download | duplicates (2)
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
45
46
47
#!/usr/bin/env python
"""
>>> c = Checked()
>>> c.method()
Traceback (most recent call last):
...
PostconditionViolationError: ('testdbc7.ToughBase.method', 3)

>>> u = Unchecked()
>>> u.method()
Traceback (most recent call last):
...
PostconditionViolationError: ('testdbc7.ToughBase.method', 3)
"""

class ToughBase:
    def method(self):
	"""
	pre: False
	post: False
	"""
	pass

class Checked(ToughBase):
    def method(self):
	"""pre: True
	post: True
	"""
	return 1

class Unchecked(ToughBase):
    def method(self):
	return 1

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

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