Skip to content

Commit

Permalink
Merge pull request #79 from davesque/try-finally
Browse files Browse the repository at this point in the history
Fix lack of cleanup for stateful tests
  • Loading branch information
davesque authored Jun 6, 2018
2 parents ef16ff3 + df9f778 commit b61a36d
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions tests/test_integration/test_custom_registrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ def decode(self, stream):
def test_register_and_use_callables():
registry.register('null', encode_null, decode_null)

assert encode_single('null', None) == NULL_ENCODING
assert decode_single('null', NULL_ENCODING) is None
try:
assert encode_single('null', None) == NULL_ENCODING
assert decode_single('null', NULL_ENCODING) is None

encoded_tuple = encode_single('(int,null)', (1, None))
encoded_tuple = encode_single('(int,null)', (1, None))

assert encoded_tuple == b'\x00' * 31 + b'\x01' + NULL_ENCODING
assert decode_single('(int,null)', encoded_tuple) == (1, None)

registry.unregister('null')
assert encoded_tuple == b'\x00' * 31 + b'\x01' + NULL_ENCODING
assert decode_single('(int,null)', encoded_tuple) == (1, None)
finally:
registry.unregister('null')


def test_register_and_use_coder_classes():
Expand All @@ -88,12 +89,13 @@ def test_register_and_use_coder_classes():
label='null',
)

assert encode_single('null2', None) == NULL_ENCODING * 2
assert decode_single('null2', NULL_ENCODING * 2) is None

encoded_tuple = encode_single('(int,null2)', (1, None))
try:
assert encode_single('null2', None) == NULL_ENCODING * 2
assert decode_single('null2', NULL_ENCODING * 2) is None

assert encoded_tuple == b'\x00' * 31 + b'\x01' + NULL_ENCODING * 2
assert decode_single('(int,null2)', encoded_tuple) == (1, None)
encoded_tuple = encode_single('(int,null2)', (1, None))

registry.unregister('null')
assert encoded_tuple == b'\x00' * 31 + b'\x01' + NULL_ENCODING * 2
assert decode_single('(int,null2)', encoded_tuple) == (1, None)
finally:
registry.unregister('null')

0 comments on commit b61a36d

Please sign in to comment.