Skip to content

Commit

Permalink
Explicitly test for __bytes__().
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Apr 24, 2019
1 parent 2b058db commit 145b7bf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Acquisition/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2458,7 +2458,10 @@ def __bytes__(self):
a = A()
a.b = A()
wrapper = Acquisition.ImplicitAcquisitionWrapper(a.b, a)
self.assertEqual(b'my bytes', bytes(wrapper))

self.assertEqual(b'my bytes', wrapper.__bytes__())
if PY3: # pragma: PY3
self.assertEqual(b'my bytes', bytes(wrapper))

def test_AttributeError_if_object_has_no__bytes__(self):
class A(Implicit):
Expand All @@ -2467,8 +2470,12 @@ class A(Implicit):
a = A()
a.b = A()
wrapper = Acquisition.ImplicitAcquisitionWrapper(a.b, a)
with self.assertRaises(TypeError):
bytes(wrapper)
with self.assertRaises(AttributeError):
wrapper.__bytes__()

if PY3: # pragma: PY3
with self.assertRaises(TypeError):
bytes(wrapper)


class TestOf(unittest.TestCase):
Expand Down

0 comments on commit 145b7bf

Please sign in to comment.