Beispiel #1
0
def test_repr_on_newstyle():
    class Function(object):
        def __repr__(self):
            return "<%s>" % (self.name)

    try:
        s = safe_repr._repr(Function())
    except Exception, e:
        py.test.fail("saferepr failed for newstyle class")
Beispiel #2
0
 def repr_locals(self, f_locals):
     if self.config.option.showlocals:
         self.out.sep('- ', 'locals')
         for name, value in f_locals.items():
             if name == '__builtins__': 
                 self.out.line("__builtins__ = <builtins>")
             else:
                 # This formatting could all be handled by the _repr() function, which is 
                 # only repr.Repr in disguise, so is very configurable.
                 str_repr = safe_repr._repr(value)
                 if len(str_repr) < 70 or not isinstance(value,
                                             (list, tuple, dict)):
                     self.out.line("%-10s = %s" %(name, str_repr))
                 else:
                     self.out.line("%-10s =\\" % (name,))
                     py.std.pprint.pprint(value, stream=self.out)
Beispiel #3
0
 def __repr__(self):
     if self.err:
         return "<CompilationError err=%s>" % safe_repr._repr(self.err)
     else:
         return "<CompilationError out=%s>" % safe_repr._repr(self.out)
Beispiel #4
0
 def _saferepr(self, obj):
     return safe_repr._repr(obj)
Beispiel #5
0
def test_simple_repr():
    assert safe_repr._repr(1) == '1'
    assert safe_repr._repr(None) == 'None'
Beispiel #6
0
def test_big_repr():
    assert len(safe_repr._repr(range(1000))) <= \
           len('[' + safe_repr.SafeRepr().maxlist * "1000" + ']')
Beispiel #7
0
def test_string_exception():
    if py.std.sys.version_info < (2, 6):
        assert 'unknown' in safe_repr._repr(BrokenRepr("string"))
    else:
        assert 'TypeError' in safe_repr._repr(BrokenRepr("string"))
Beispiel #8
0
 def __repr__(self):
     if self.err:
         return "<CompilationError err=%s>" % safe_repr._repr(self.err)
     else:
         return "<CompilationError out=%s>" % safe_repr._repr(self.out)
Beispiel #9
0
def test_exception():
    assert 'Exception' in safe_repr._repr(BrokenRepr(Exception("broken")))
Beispiel #10
0
def test_simple_repr():
    assert safe_repr._repr(1) == '1'
    assert safe_repr._repr(None) == 'None'
Beispiel #11
0
def test_big_repr():
    assert len(safe_repr._repr(range(1000))) <= \
           len('[' + safe_repr.SafeRepr().maxlist * "1000" + ']')
Beispiel #12
0
def test_string_exception():
    if py.std.sys.version_info < (2,6):
        assert 'unknown' in safe_repr._repr(BrokenRepr("string"))
    else:
        assert 'TypeError' in safe_repr._repr(BrokenRepr("string"))
Beispiel #13
0
def test_broken_exception():
    assert 'Exception' in safe_repr._repr(BrokenRepr(BrokenReprException("really broken")))
Beispiel #14
0
def test_exception():
    assert 'Exception' in safe_repr._repr(BrokenRepr(Exception("broken")))
Beispiel #15
0
def test_broken_exception():
    assert 'Exception' in safe_repr._repr(
        BrokenRepr(BrokenReprException("really broken")))
 def _saferepr(self, obj):
     return safe_repr._repr(obj)
Beispiel #17
0
def test_string_exception():
    assert 'unknown' in safe_repr._repr(BrokenRepr("string"))