-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for recursive_unicode function
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |