Skip to content

Commit

Permalink
add test for legacy _create_function()
Browse files Browse the repository at this point in the history
  • Loading branch information
leogama committed May 17, 2022
1 parent 1476818 commit 9433c89
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import functools
import dill
import sys
from dill._dill import _create_function
dill.settings['recurse'] = True


Expand Down Expand Up @@ -102,5 +103,26 @@ def test_functions():
assert dill.loads(dumped_func_e)(1, 2, 3, e2=4) == 12
assert dill.loads(dumped_func_e)(1, 2, 3, e2=4, e3=5) == 15''')

def test_legacy_constructor():
if is_py3():
fields = ('__code__', '__globals__', '__name__', '__defaults__',
'__closure__', '__dict__', '__kwdefaults__')
else:
fields = ('func_code', 'func_globals', 'func_name', 'func_defaults',
'func_closure', '__dict__')
members = [getattr(function_d, f) for f in fields]

# Old pickle.
old_func = _create_function(*members)
# Recent pickle (dill>=0.3.5).
new_func = _create_function(*members[:5])
setattr(new_func, fields[5], members[5])
if is_py3():
setattr(new_func, fields[6], members[6])

for field in fields:
assert getattr(old_func, field) == getattr(new_func, field)

if __name__ == '__main__':
test_functions()
test_legacy_constructor()

0 comments on commit 9433c89

Please sign in to comment.