File: assertion.py

package info (click to toggle)
codespeak-lib 0.9.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,212 kB
  • ctags: 5,409
  • sloc: python: 33,390; ansic: 961; xml: 582; makefile: 90
file content (31 lines) | stat: -rw-r--r-- 1,034 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
import __builtin__, sys
import py
from py.__.magic import exprinfo

BuiltinAssertionError = __builtin__.AssertionError

class AssertionError(BuiltinAssertionError):
    def __init__(self, *args):
        BuiltinAssertionError.__init__(self, *args)
        if args: 
            self.msg = str(args[0])
        else: 
            f = sys._getframe(1)
            try:
                source = py.code.Frame(f).statement
                source = str(source.deindent()).strip()
            except py.error.ENOENT:
                source = None
                # this can also occur during reinterpretation, when the
                # co_filename is set to "<run>".
            if source:
                self.msg = exprinfo.interpret(source, f, should_fail=True)
                if not self.args:
                    self.args = (self.msg,)
            else:
                self.msg = None

def invoke():
    py.magic.patch(__builtin__, 'AssertionError', AssertionError)
def revoke():
    py.magic.revert(__builtin__, 'AssertionError')