Skip to content

Commit

Permalink
Add tests for recursive_unicode function
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Jan 23, 2024
1 parent 15c6c16 commit fc9e9e9
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/tribler/core/utilities/tests/test_unicode.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fc9e9e9

Please sign in to comment.