def test_safe_representation(): class TestObject(object): """A test object that has neither __str__ nor __repr__.""" def __str__(self): return NotImplementedError() def __repr__(self): return NotImplementedError() assert_eq("2", qcore.safe_str(2)) assert_eq("2....", qcore.safe_str("2.192842", max_length=5)) assert_is_substring("<n/a: str(...) raised", qcore.safe_str(TestObject())) assert_eq("'a'", qcore.safe_repr("a")) assert_eq("'...", qcore.safe_repr("2.192842", max_length=4)) assert_eq("<n/a: repr...", qcore.safe_repr(TestObject(), max_length=13))
def repr(source, truncate=True): return qcore.safe_repr( source, options.DEBUG_STR_REPR_MAX_LENGTH if truncate else 0)