From fc9e9e93c61f326879694464e040b8dccb6ed8b4 Mon Sep 17 00:00:00 2001 From: drew2a Date: Tue, 23 Jan 2024 14:36:01 +0700 Subject: [PATCH] Add tests for recursive_unicode function --- .../core/utilities/tests/test_unicode.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/tribler/core/utilities/tests/test_unicode.py diff --git a/src/tribler/core/utilities/tests/test_unicode.py b/src/tribler/core/utilities/tests/test_unicode.py new file mode 100644 index 00000000000..93c8bdde029 --- /dev/null +++ b/src/tribler/core/utilities/tests/test_unicode.py @@ -0,0 +1,46 @@ +from tribler.core.utilities.unicode import recursive_unicode + + +def test_recursive_unicode_empty(): + # Test that recursive_unicode works on empty items + assert recursive_unicode({}) == {} + assert recursive_unicode([]) == [] + assert recursive_unicode(b'') == '' + assert recursive_unicode('') == '' + assert recursive_unicode(None) is None + + +def test_recursive_unicode_complex_object(): + # Test that recursive_unicode works on a complex object + obj = { + 'list': [ + b'binary', + {} + ], + 'sub dict': { + 'sub list': [ + 1, + b'binary', + { + '': b'' + }, + ] + } + } + + expected = { + 'list': [ + 'binary', + {} + ], + 'sub dict': { + 'sub list': [ + 1, + 'binary', + { + '': '' + }, + ] + } + } + assert recursive_unicode(obj) == expected