def test_override_default_repr_of_BTree(self): # The pure-python implementation of BTrees (and buckets, and sets) # helpfully overrides __repr__ to drop the Py suffix from class names. self.assertEqual( GenericValue(OOBTree()).render(), '<BTrees.OOBTree.OOBTree with oid None>' ' (0 items)')
def test_srsly_no_crashes(self): self.assertEqual( GenericValue(ExplodingClassNameRepr()).render(), '<unrepresentable>')
def test_no_crashes(self): self.assertEqual( GenericValue(ExplodingRepr()).render(), '<unrepresentable ExplodingRepr>')
def test_conteinerish_things_do_not_explode(self): self.assertEqual( GenericValue(ExplodingLen()).render(), '<ExplodingLen>')
def test_override_default_repr_of_Persistent(self): # https://bugs.launchpad.net/zodbbrowser/+bug/1087138 self.assertEqual( GenericValue(PersistentFrobNoRepr()).render(), '<zodbbrowser.tests.test_value.PersistentFrobNoRepr' ' with oid 0x17>')
def test_conteinerish_things(self): self.assertEqual( GenericValue([1, 2, 3]).render(), "[1, 2, 3] (3 items)") self.assertEqual(GenericValue([1]).render(), "[1] (1 item)") self.assertEqual(GenericValue([]).render(), "[] (0 items)")
def test_conteinerish_things_and_truncation(self): self.assertEqual( GenericValue([1, 2, 3]).render(limit=3), '[1,<span id="tr1" class="truncated">...</span> (3 items)')
def test_truncation(self): self.assertEqual( GenericValue('a very long string').render(limit=10), """'a very lo<span id="tr1" class="truncated">...</span>""") self.assertEqual(TRUNCATIONS['tr1'], "ng string'") self.assertEqual(list(TRUNCATIONS_IN_ORDER), ['tr1'])
def test_html_quoting(self): self.assertEqual(GenericValue('<html>').render(), "'<html>'")
def test_no_dunder_repr(self): # Fixes https://github.com/mgedmin/zodbbrowser/issues/6 obj = OldStyle() self.assertEqual(GenericValue(obj)._repr(), repr(obj))
def test_simple_repr(self): for s in [None, '', 'xyzzy', b'\x17', u'\u1234']: self.assertEqual(GenericValue(s).render(), repr(s))
def test_interface_compliance(self): verifyObject(IValueRenderer, GenericValue(None))