From 222d26679476e96321b54cf4f102e50436f42208 Mon Sep 17 00:00:00 2001 From: Matus Honek Date: Mon, 2 Dec 2019 15:49:59 +0100 Subject: [PATCH] Fix random issues - use the actual zero byte in test - fix a typo in the test's name - raise exception in Python2 case (Simon approves) - drop "if __main__" (Viktor approves) --- src/lib389/lib389/tests/utils_test.py | 11 +++-------- src/lib389/lib389/utils.py | 2 ++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lib389/lib389/tests/utils_test.py b/src/lib389/lib389/tests/utils_test.py index 7246e1f08..b17b71c28 100644 --- a/src/lib389/lib389/tests/utils_test.py +++ b/src/lib389/lib389/tests/utils_test.py @@ -176,17 +176,12 @@ def test_ds_is_newer_versions(ds_ver, cmp_ver): @pytest.mark.parametrize('input, result', [ (b'', ''), - (b'0', '\\30'), - (b'0x00', '\\30\\78\\30\\30'), + (b'\x00', '\\00'), + (b'\x01\x00', '\\01\\00'), (b'01', '\\30\\31'), (b'101', '\\31\\30\\31'), (b'101x1', '\\31\\30\\31\\78\\31'), (b'0\x82\x05s0\x82\x03[\xa0\x03\x02\x01\x02', '\\30\\82\\05\\73\\30\\82\\03\\5b\\a0\\03\\02\\01\\02'), ]) -def test_search_filter_scape_bytes(input, result): +def test_search_filter_escape_bytes(input, result): assert search_filter_escape_bytes(input) == result - - -if __name__ == "__main__": - CURRENT_FILE = os.path.realpath(__file__) - pytest.main("-s -v %s" % CURRENT_FILE) diff --git a/src/lib389/lib389/utils.py b/src/lib389/lib389/utils.py index 707497634..00ececb51 100644 --- a/src/lib389/lib389/utils.py +++ b/src/lib389/lib389/utils.py @@ -1324,3 +1324,5 @@ def search_filter_escape_bytes(bytes_value): if isinstance(bytes_value, str): bytes_value = bytearray(bytes_value, encoding='utf-8') return ''.join([('\\%02x' % int(b)) for b in bytes_value]) + else: + raise RuntimeError('Running with Python 2 is unsupported') -- 2.21.0