Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/__diff.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/__info__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/__init__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/_dill.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/_objects.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/_shims.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/detect.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/logger.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/objtypes.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/pointers.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/session.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/settings.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/source.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/__pycache__/temp.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__init__.py +22 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/__main__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_check.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_classdef.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_detect.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_dictviews.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_diff.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_fglobals.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_file.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_functions.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_functors.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_logger.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_mixins.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_nested.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_objects.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_properties.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_pycapsule.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_recursive.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_registered.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_restricted.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_session.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_source.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_temp.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_weakref.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/test_dataclasses.py +35 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/test_diff.py +107 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/test_file.py +500 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/test_module.py +84 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/test_objects.py +63 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/test_properties.py +62 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/test_recursive.py +177 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/test_temp.py +103 -0
- env-llmeval/lib/python3.10/site-packages/dill/tests/test_weakref.py +72 -0
- env-llmeval/lib/python3.10/site-packages/numexpr/__init__.py +68 -0
- env-llmeval/lib/python3.10/site-packages/numexpr/__pycache__/__init__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/numexpr/__pycache__/cpuinfo.cpython-310.pyc +0 -0
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/__diff.cpython-310.pyc
ADDED
Binary file (5.85 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/__info__.cpython-310.pyc
ADDED
Binary file (10.7 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (3.66 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/_dill.cpython-310.pyc
ADDED
Binary file (57.4 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/_objects.cpython-310.pyc
ADDED
Binary file (14.3 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/_shims.cpython-310.pyc
ADDED
Binary file (6.58 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/detect.cpython-310.pyc
ADDED
Binary file (8.28 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/logger.cpython-310.pyc
ADDED
Binary file (8.87 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/objtypes.cpython-310.pyc
ADDED
Binary file (532 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/pointers.cpython-310.pyc
ADDED
Binary file (3.42 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/session.cpython-310.pyc
ADDED
Binary file (18.9 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/settings.cpython-310.pyc
ADDED
Binary file (348 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/source.cpython-310.pyc
ADDED
Binary file (25.9 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/__pycache__/temp.cpython-310.pyc
ADDED
Binary file (7.23 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__init__.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
#
|
3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
4 |
+
# Copyright (c) 2018-2024 The Uncertainty Quantification Foundation.
|
5 |
+
# License: 3-clause BSD. The full license text is available at:
|
6 |
+
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
|
7 |
+
"""
|
8 |
+
to run this test suite, first build and install `dill`.
|
9 |
+
|
10 |
+
$ python -m pip install ../..
|
11 |
+
|
12 |
+
|
13 |
+
then run the tests with:
|
14 |
+
|
15 |
+
$ python -m dill.tests
|
16 |
+
|
17 |
+
|
18 |
+
or, if `nose` is installed:
|
19 |
+
|
20 |
+
$ nosetests
|
21 |
+
|
22 |
+
"""
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/__main__.cpython-310.pyc
ADDED
Binary file (755 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_check.cpython-310.pyc
ADDED
Binary file (1.48 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_classdef.cpython-310.pyc
ADDED
Binary file (11.6 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_detect.cpython-310.pyc
ADDED
Binary file (5.1 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_dictviews.cpython-310.pyc
ADDED
Binary file (1.24 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_diff.cpython-310.pyc
ADDED
Binary file (1.54 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_fglobals.cpython-310.pyc
ADDED
Binary file (1.88 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_file.cpython-310.pyc
ADDED
Binary file (7.07 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_functions.cpython-310.pyc
ADDED
Binary file (4.55 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_functors.cpython-310.pyc
ADDED
Binary file (969 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_logger.cpython-310.pyc
ADDED
Binary file (1.95 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_mixins.cpython-310.pyc
ADDED
Binary file (4.69 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_nested.cpython-310.pyc
ADDED
Binary file (3.61 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_objects.cpython-310.pyc
ADDED
Binary file (1.89 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_properties.cpython-310.pyc
ADDED
Binary file (1.59 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_pycapsule.cpython-310.pyc
ADDED
Binary file (1.06 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_recursive.cpython-310.pyc
ADDED
Binary file (5.65 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_registered.cpython-310.pyc
ADDED
Binary file (1.5 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_restricted.cpython-310.pyc
ADDED
Binary file (980 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_session.cpython-310.pyc
ADDED
Binary file (8.19 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_source.cpython-310.pyc
ADDED
Binary file (5.32 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_temp.cpython-310.pyc
ADDED
Binary file (3.12 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/__pycache__/test_weakref.cpython-310.pyc
ADDED
Binary file (1.74 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dill/tests/test_dataclasses.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
#
|
3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
4 |
+
# Author: Anirudh Vegesana ([email protected])
|
5 |
+
# Copyright (c) 2022-2024 The Uncertainty Quantification Foundation.
|
6 |
+
# License: 3-clause BSD. The full license text is available at:
|
7 |
+
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
|
8 |
+
"""
|
9 |
+
test pickling a dataclass
|
10 |
+
"""
|
11 |
+
|
12 |
+
import dill
|
13 |
+
import dataclasses
|
14 |
+
|
15 |
+
def test_dataclasses():
|
16 |
+
# Issue #500
|
17 |
+
@dataclasses.dataclass
|
18 |
+
class A:
|
19 |
+
x: int
|
20 |
+
y: str
|
21 |
+
|
22 |
+
@dataclasses.dataclass
|
23 |
+
class B:
|
24 |
+
a: A
|
25 |
+
|
26 |
+
a = A(1, "test")
|
27 |
+
before = B(a)
|
28 |
+
save = dill.dumps(before)
|
29 |
+
after = dill.loads(save)
|
30 |
+
assert before != after # classes don't match
|
31 |
+
assert before == B(A(**dataclasses.asdict(after.a)))
|
32 |
+
assert dataclasses.asdict(before) == dataclasses.asdict(after)
|
33 |
+
|
34 |
+
if __name__ == '__main__':
|
35 |
+
test_dataclasses()
|
env-llmeval/lib/python3.10/site-packages/dill/tests/test_diff.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
#
|
3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
4 |
+
# Copyright (c) 2008-2016 California Institute of Technology.
|
5 |
+
# Copyright (c) 2016-2024 The Uncertainty Quantification Foundation.
|
6 |
+
# License: 3-clause BSD. The full license text is available at:
|
7 |
+
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
|
8 |
+
|
9 |
+
from dill import __diff as diff
|
10 |
+
|
11 |
+
import sys
|
12 |
+
IS_PYPY = not hasattr(sys, 'getrefcount')
|
13 |
+
|
14 |
+
class A:
|
15 |
+
pass
|
16 |
+
|
17 |
+
def test_diff():
|
18 |
+
a = A()
|
19 |
+
b = A()
|
20 |
+
c = A()
|
21 |
+
a.a = b
|
22 |
+
b.a = c
|
23 |
+
diff.memorise(a)
|
24 |
+
assert not diff.has_changed(a)
|
25 |
+
c.a = 1
|
26 |
+
assert diff.has_changed(a)
|
27 |
+
diff.memorise(c, force=True)
|
28 |
+
assert not diff.has_changed(a)
|
29 |
+
c.a = 2
|
30 |
+
assert diff.has_changed(a)
|
31 |
+
changed = diff.whats_changed(a)
|
32 |
+
assert list(changed[0].keys()) == ["a"]
|
33 |
+
assert not changed[1]
|
34 |
+
|
35 |
+
a2 = []
|
36 |
+
b2 = [a2]
|
37 |
+
c2 = [b2]
|
38 |
+
diff.memorise(c2)
|
39 |
+
assert not diff.has_changed(c2)
|
40 |
+
a2.append(1)
|
41 |
+
assert diff.has_changed(c2)
|
42 |
+
changed = diff.whats_changed(c2)
|
43 |
+
assert changed[0] == {}
|
44 |
+
assert changed[1]
|
45 |
+
|
46 |
+
a3 = {}
|
47 |
+
b3 = {1: a3}
|
48 |
+
c3 = {1: b3}
|
49 |
+
diff.memorise(c3)
|
50 |
+
assert not diff.has_changed(c3)
|
51 |
+
a3[1] = 1
|
52 |
+
assert diff.has_changed(c3)
|
53 |
+
changed = diff.whats_changed(c3)
|
54 |
+
assert changed[0] == {}
|
55 |
+
assert changed[1]
|
56 |
+
|
57 |
+
if not IS_PYPY:
|
58 |
+
import abc
|
59 |
+
# make sure the "_abc_invaldation_counter" doesn't make test fail
|
60 |
+
diff.memorise(abc.ABCMeta, force=True)
|
61 |
+
assert not diff.has_changed(abc)
|
62 |
+
abc.ABCMeta.zzz = 1
|
63 |
+
assert diff.has_changed(abc)
|
64 |
+
changed = diff.whats_changed(abc)
|
65 |
+
assert list(changed[0].keys()) == ["ABCMeta"]
|
66 |
+
assert not changed[1]
|
67 |
+
|
68 |
+
'''
|
69 |
+
import Queue
|
70 |
+
diff.memorise(Queue, force=True)
|
71 |
+
assert not diff.has_changed(Queue)
|
72 |
+
Queue.Queue.zzz = 1
|
73 |
+
assert diff.has_changed(Queue)
|
74 |
+
changed = diff.whats_changed(Queue)
|
75 |
+
assert list(changed[0].keys()) == ["Queue"]
|
76 |
+
assert not changed[1]
|
77 |
+
|
78 |
+
import math
|
79 |
+
diff.memorise(math, force=True)
|
80 |
+
assert not diff.has_changed(math)
|
81 |
+
math.zzz = 1
|
82 |
+
assert diff.has_changed(math)
|
83 |
+
changed = diff.whats_changed(math)
|
84 |
+
assert list(changed[0].keys()) == ["zzz"]
|
85 |
+
assert not changed[1]
|
86 |
+
'''
|
87 |
+
|
88 |
+
a = A()
|
89 |
+
b = A()
|
90 |
+
c = A()
|
91 |
+
a.a = b
|
92 |
+
b.a = c
|
93 |
+
diff.memorise(a)
|
94 |
+
assert not diff.has_changed(a)
|
95 |
+
c.a = 1
|
96 |
+
assert diff.has_changed(a)
|
97 |
+
diff.memorise(c, force=True)
|
98 |
+
assert not diff.has_changed(a)
|
99 |
+
del c.a
|
100 |
+
assert diff.has_changed(a)
|
101 |
+
changed = diff.whats_changed(a)
|
102 |
+
assert list(changed[0].keys()) == ["a"]
|
103 |
+
assert not changed[1]
|
104 |
+
|
105 |
+
|
106 |
+
if __name__ == '__main__':
|
107 |
+
test_diff()
|
env-llmeval/lib/python3.10/site-packages/dill/tests/test_file.py
ADDED
@@ -0,0 +1,500 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
#
|
3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
4 |
+
# Copyright (c) 2008-2016 California Institute of Technology.
|
5 |
+
# Copyright (c) 2016-2024 The Uncertainty Quantification Foundation.
|
6 |
+
# License: 3-clause BSD. The full license text is available at:
|
7 |
+
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
|
8 |
+
|
9 |
+
import os
|
10 |
+
import sys
|
11 |
+
import string
|
12 |
+
import random
|
13 |
+
|
14 |
+
import dill
|
15 |
+
|
16 |
+
|
17 |
+
dill.settings['recurse'] = True
|
18 |
+
|
19 |
+
fname = "_test_file.txt"
|
20 |
+
rand_chars = list(string.ascii_letters) + ["\n"] * 40 # bias newline
|
21 |
+
|
22 |
+
buffer_error = ValueError("invalid buffer size")
|
23 |
+
dne_error = FileNotFoundError("[Errno 2] No such file or directory: '%s'" % fname)
|
24 |
+
|
25 |
+
|
26 |
+
def write_randomness(number=200):
|
27 |
+
f = open(fname, "w")
|
28 |
+
for i in range(number):
|
29 |
+
f.write(random.choice(rand_chars))
|
30 |
+
f.close()
|
31 |
+
f = open(fname, "r")
|
32 |
+
contents = f.read()
|
33 |
+
f.close()
|
34 |
+
return contents
|
35 |
+
|
36 |
+
|
37 |
+
def trunc_file():
|
38 |
+
open(fname, "w").close()
|
39 |
+
|
40 |
+
|
41 |
+
def throws(op, args, exc):
|
42 |
+
try:
|
43 |
+
op(*args)
|
44 |
+
except type(exc):
|
45 |
+
return sys.exc_info()[1].args == exc.args
|
46 |
+
else:
|
47 |
+
return False
|
48 |
+
|
49 |
+
|
50 |
+
def teardown_module():
|
51 |
+
if os.path.exists(fname):
|
52 |
+
os.remove(fname)
|
53 |
+
|
54 |
+
|
55 |
+
def bench(strictio, fmode, skippypy):
|
56 |
+
import platform
|
57 |
+
if skippypy and platform.python_implementation() == 'PyPy':
|
58 |
+
# Skip for PyPy...
|
59 |
+
return
|
60 |
+
|
61 |
+
# file exists, with same contents
|
62 |
+
# read
|
63 |
+
|
64 |
+
write_randomness()
|
65 |
+
|
66 |
+
f = open(fname, "r")
|
67 |
+
_f = dill.loads(dill.dumps(f, fmode=fmode))#, strictio=strictio))
|
68 |
+
assert _f.mode == f.mode
|
69 |
+
assert _f.tell() == f.tell()
|
70 |
+
assert _f.read() == f.read()
|
71 |
+
f.close()
|
72 |
+
_f.close()
|
73 |
+
|
74 |
+
# write
|
75 |
+
|
76 |
+
f = open(fname, "w")
|
77 |
+
f.write("hello")
|
78 |
+
f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
|
79 |
+
f1mode = f.mode
|
80 |
+
ftell = f.tell()
|
81 |
+
f.close()
|
82 |
+
f2 = dill.loads(f_dumped) #FIXME: fails due to pypy/issues/1233
|
83 |
+
# TypeError: expected py_object instance instead of str
|
84 |
+
f2mode = f2.mode
|
85 |
+
f2tell = f2.tell()
|
86 |
+
f2name = f2.name
|
87 |
+
f2.write(" world!")
|
88 |
+
f2.close()
|
89 |
+
|
90 |
+
if fmode == dill.HANDLE_FMODE:
|
91 |
+
assert open(fname).read() == " world!"
|
92 |
+
assert f2mode == f1mode
|
93 |
+
assert f2tell == 0
|
94 |
+
elif fmode == dill.CONTENTS_FMODE:
|
95 |
+
assert open(fname).read() == "hello world!"
|
96 |
+
assert f2mode == f1mode
|
97 |
+
assert f2tell == ftell
|
98 |
+
assert f2name == fname
|
99 |
+
elif fmode == dill.FILE_FMODE:
|
100 |
+
assert open(fname).read() == "hello world!"
|
101 |
+
assert f2mode == f1mode
|
102 |
+
assert f2tell == ftell
|
103 |
+
else:
|
104 |
+
raise RuntimeError("Unknown file mode '%s'" % fmode)
|
105 |
+
|
106 |
+
# append
|
107 |
+
|
108 |
+
trunc_file()
|
109 |
+
|
110 |
+
f = open(fname, "a")
|
111 |
+
f.write("hello")
|
112 |
+
f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
|
113 |
+
f1mode = f.mode
|
114 |
+
ftell = f.tell()
|
115 |
+
f.close()
|
116 |
+
f2 = dill.loads(f_dumped)
|
117 |
+
f2mode = f2.mode
|
118 |
+
f2tell = f2.tell()
|
119 |
+
f2.write(" world!")
|
120 |
+
f2.close()
|
121 |
+
|
122 |
+
assert f2mode == f1mode
|
123 |
+
if fmode == dill.CONTENTS_FMODE:
|
124 |
+
assert open(fname).read() == "hello world!"
|
125 |
+
assert f2tell == ftell
|
126 |
+
elif fmode == dill.HANDLE_FMODE:
|
127 |
+
assert open(fname).read() == "hello world!"
|
128 |
+
assert f2tell == ftell
|
129 |
+
elif fmode == dill.FILE_FMODE:
|
130 |
+
assert open(fname).read() == "hello world!"
|
131 |
+
assert f2tell == ftell
|
132 |
+
else:
|
133 |
+
raise RuntimeError("Unknown file mode '%s'" % fmode)
|
134 |
+
|
135 |
+
# file exists, with different contents (smaller size)
|
136 |
+
# read
|
137 |
+
|
138 |
+
write_randomness()
|
139 |
+
|
140 |
+
f = open(fname, "r")
|
141 |
+
fstr = f.read()
|
142 |
+
f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
|
143 |
+
f1mode = f.mode
|
144 |
+
ftell = f.tell()
|
145 |
+
f.close()
|
146 |
+
_flen = 150
|
147 |
+
_fstr = write_randomness(number=_flen)
|
148 |
+
|
149 |
+
if strictio: # throw error if ftell > EOF
|
150 |
+
assert throws(dill.loads, (f_dumped,), buffer_error)
|
151 |
+
else:
|
152 |
+
f2 = dill.loads(f_dumped)
|
153 |
+
assert f2.mode == f1mode
|
154 |
+
if fmode == dill.CONTENTS_FMODE:
|
155 |
+
assert f2.tell() == _flen
|
156 |
+
assert f2.read() == ""
|
157 |
+
f2.seek(0)
|
158 |
+
assert f2.read() == _fstr
|
159 |
+
assert f2.tell() == _flen # 150
|
160 |
+
elif fmode == dill.HANDLE_FMODE:
|
161 |
+
assert f2.tell() == 0
|
162 |
+
assert f2.read() == _fstr
|
163 |
+
assert f2.tell() == _flen # 150
|
164 |
+
elif fmode == dill.FILE_FMODE:
|
165 |
+
assert f2.tell() == ftell # 200
|
166 |
+
assert f2.read() == ""
|
167 |
+
f2.seek(0)
|
168 |
+
assert f2.read() == fstr
|
169 |
+
assert f2.tell() == ftell # 200
|
170 |
+
else:
|
171 |
+
raise RuntimeError("Unknown file mode '%s'" % fmode)
|
172 |
+
f2.close()
|
173 |
+
|
174 |
+
# write
|
175 |
+
|
176 |
+
write_randomness()
|
177 |
+
|
178 |
+
f = open(fname, "w")
|
179 |
+
f.write("hello")
|
180 |
+
f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
|
181 |
+
f1mode = f.mode
|
182 |
+
ftell = f.tell()
|
183 |
+
f.close()
|
184 |
+
fstr = open(fname).read()
|
185 |
+
|
186 |
+
f = open(fname, "w")
|
187 |
+
f.write("h")
|
188 |
+
_ftell = f.tell()
|
189 |
+
f.close()
|
190 |
+
|
191 |
+
if strictio: # throw error if ftell > EOF
|
192 |
+
assert throws(dill.loads, (f_dumped,), buffer_error)
|
193 |
+
else:
|
194 |
+
f2 = dill.loads(f_dumped)
|
195 |
+
f2mode = f2.mode
|
196 |
+
f2tell = f2.tell()
|
197 |
+
f2.write(" world!")
|
198 |
+
f2.close()
|
199 |
+
if fmode == dill.CONTENTS_FMODE:
|
200 |
+
assert open(fname).read() == "h world!"
|
201 |
+
assert f2mode == f1mode
|
202 |
+
assert f2tell == _ftell
|
203 |
+
elif fmode == dill.HANDLE_FMODE:
|
204 |
+
assert open(fname).read() == " world!"
|
205 |
+
assert f2mode == f1mode
|
206 |
+
assert f2tell == 0
|
207 |
+
elif fmode == dill.FILE_FMODE:
|
208 |
+
assert open(fname).read() == "hello world!"
|
209 |
+
assert f2mode == f1mode
|
210 |
+
assert f2tell == ftell
|
211 |
+
else:
|
212 |
+
raise RuntimeError("Unknown file mode '%s'" % fmode)
|
213 |
+
f2.close()
|
214 |
+
|
215 |
+
# append
|
216 |
+
|
217 |
+
trunc_file()
|
218 |
+
|
219 |
+
f = open(fname, "a")
|
220 |
+
f.write("hello")
|
221 |
+
f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
|
222 |
+
f1mode = f.mode
|
223 |
+
ftell = f.tell()
|
224 |
+
f.close()
|
225 |
+
fstr = open(fname).read()
|
226 |
+
|
227 |
+
f = open(fname, "w")
|
228 |
+
f.write("h")
|
229 |
+
_ftell = f.tell()
|
230 |
+
f.close()
|
231 |
+
|
232 |
+
if strictio: # throw error if ftell > EOF
|
233 |
+
assert throws(dill.loads, (f_dumped,), buffer_error)
|
234 |
+
else:
|
235 |
+
f2 = dill.loads(f_dumped)
|
236 |
+
f2mode = f2.mode
|
237 |
+
f2tell = f2.tell()
|
238 |
+
f2.write(" world!")
|
239 |
+
f2.close()
|
240 |
+
assert f2mode == f1mode
|
241 |
+
if fmode == dill.CONTENTS_FMODE:
|
242 |
+
# position of writes cannot be changed on some OSs
|
243 |
+
assert open(fname).read() == "h world!"
|
244 |
+
assert f2tell == _ftell
|
245 |
+
elif fmode == dill.HANDLE_FMODE:
|
246 |
+
assert open(fname).read() == "h world!"
|
247 |
+
assert f2tell == _ftell
|
248 |
+
elif fmode == dill.FILE_FMODE:
|
249 |
+
assert open(fname).read() == "hello world!"
|
250 |
+
assert f2tell == ftell
|
251 |
+
else:
|
252 |
+
raise RuntimeError("Unknown file mode '%s'" % fmode)
|
253 |
+
f2.close()
|
254 |
+
|
255 |
+
# file does not exist
|
256 |
+
# read
|
257 |
+
|
258 |
+
write_randomness()
|
259 |
+
|
260 |
+
f = open(fname, "r")
|
261 |
+
fstr = f.read()
|
262 |
+
f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
|
263 |
+
f1mode = f.mode
|
264 |
+
ftell = f.tell()
|
265 |
+
f.close()
|
266 |
+
|
267 |
+
os.remove(fname)
|
268 |
+
|
269 |
+
if strictio: # throw error if file DNE
|
270 |
+
assert throws(dill.loads, (f_dumped,), dne_error)
|
271 |
+
else:
|
272 |
+
f2 = dill.loads(f_dumped)
|
273 |
+
assert f2.mode == f1mode
|
274 |
+
if fmode == dill.CONTENTS_FMODE:
|
275 |
+
# FIXME: this fails on systems where f2.tell() always returns 0
|
276 |
+
# assert f2.tell() == ftell # 200
|
277 |
+
assert f2.read() == ""
|
278 |
+
f2.seek(0)
|
279 |
+
assert f2.read() == ""
|
280 |
+
assert f2.tell() == 0
|
281 |
+
elif fmode == dill.FILE_FMODE:
|
282 |
+
assert f2.tell() == ftell # 200
|
283 |
+
assert f2.read() == ""
|
284 |
+
f2.seek(0)
|
285 |
+
assert f2.read() == fstr
|
286 |
+
assert f2.tell() == ftell # 200
|
287 |
+
elif fmode == dill.HANDLE_FMODE:
|
288 |
+
assert f2.tell() == 0
|
289 |
+
assert f2.read() == ""
|
290 |
+
assert f2.tell() == 0
|
291 |
+
else:
|
292 |
+
raise RuntimeError("Unknown file mode '%s'" % fmode)
|
293 |
+
f2.close()
|
294 |
+
|
295 |
+
# write
|
296 |
+
|
297 |
+
write_randomness()
|
298 |
+
|
299 |
+
f = open(fname, "w+")
|
300 |
+
f.write("hello")
|
301 |
+
f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
|
302 |
+
ftell = f.tell()
|
303 |
+
f1mode = f.mode
|
304 |
+
f.close()
|
305 |
+
|
306 |
+
os.remove(fname)
|
307 |
+
|
308 |
+
if strictio: # throw error if file DNE
|
309 |
+
assert throws(dill.loads, (f_dumped,), dne_error)
|
310 |
+
else:
|
311 |
+
f2 = dill.loads(f_dumped)
|
312 |
+
f2mode = f2.mode
|
313 |
+
f2tell = f2.tell()
|
314 |
+
f2.write(" world!")
|
315 |
+
f2.close()
|
316 |
+
if fmode == dill.CONTENTS_FMODE:
|
317 |
+
assert open(fname).read() == " world!"
|
318 |
+
assert f2mode == 'w+'
|
319 |
+
assert f2tell == 0
|
320 |
+
elif fmode == dill.HANDLE_FMODE:
|
321 |
+
assert open(fname).read() == " world!"
|
322 |
+
assert f2mode == f1mode
|
323 |
+
assert f2tell == 0
|
324 |
+
elif fmode == dill.FILE_FMODE:
|
325 |
+
assert open(fname).read() == "hello world!"
|
326 |
+
assert f2mode == f1mode
|
327 |
+
assert f2tell == ftell
|
328 |
+
else:
|
329 |
+
raise RuntimeError("Unknown file mode '%s'" % fmode)
|
330 |
+
|
331 |
+
# append
|
332 |
+
|
333 |
+
trunc_file()
|
334 |
+
|
335 |
+
f = open(fname, "a")
|
336 |
+
f.write("hello")
|
337 |
+
f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
|
338 |
+
ftell = f.tell()
|
339 |
+
f1mode = f.mode
|
340 |
+
f.close()
|
341 |
+
|
342 |
+
os.remove(fname)
|
343 |
+
|
344 |
+
if strictio: # throw error if file DNE
|
345 |
+
assert throws(dill.loads, (f_dumped,), dne_error)
|
346 |
+
else:
|
347 |
+
f2 = dill.loads(f_dumped)
|
348 |
+
f2mode = f2.mode
|
349 |
+
f2tell = f2.tell()
|
350 |
+
f2.write(" world!")
|
351 |
+
f2.close()
|
352 |
+
assert f2mode == f1mode
|
353 |
+
if fmode == dill.CONTENTS_FMODE:
|
354 |
+
assert open(fname).read() == " world!"
|
355 |
+
assert f2tell == 0
|
356 |
+
elif fmode == dill.HANDLE_FMODE:
|
357 |
+
assert open(fname).read() == " world!"
|
358 |
+
assert f2tell == 0
|
359 |
+
elif fmode == dill.FILE_FMODE:
|
360 |
+
assert open(fname).read() == "hello world!"
|
361 |
+
assert f2tell == ftell
|
362 |
+
else:
|
363 |
+
raise RuntimeError("Unknown file mode '%s'" % fmode)
|
364 |
+
|
365 |
+
# file exists, with different contents (larger size)
|
366 |
+
# read
|
367 |
+
|
368 |
+
write_randomness()
|
369 |
+
|
370 |
+
f = open(fname, "r")
|
371 |
+
fstr = f.read()
|
372 |
+
f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
|
373 |
+
f1mode = f.mode
|
374 |
+
ftell = f.tell()
|
375 |
+
f.close()
|
376 |
+
_flen = 250
|
377 |
+
_fstr = write_randomness(number=_flen)
|
378 |
+
|
379 |
+
# XXX: no safe_file: no way to be 'safe'?
|
380 |
+
|
381 |
+
f2 = dill.loads(f_dumped)
|
382 |
+
assert f2.mode == f1mode
|
383 |
+
if fmode == dill.CONTENTS_FMODE:
|
384 |
+
assert f2.tell() == ftell # 200
|
385 |
+
assert f2.read() == _fstr[ftell:]
|
386 |
+
f2.seek(0)
|
387 |
+
assert f2.read() == _fstr
|
388 |
+
assert f2.tell() == _flen # 250
|
389 |
+
elif fmode == dill.HANDLE_FMODE:
|
390 |
+
assert f2.tell() == 0
|
391 |
+
assert f2.read() == _fstr
|
392 |
+
assert f2.tell() == _flen # 250
|
393 |
+
elif fmode == dill.FILE_FMODE:
|
394 |
+
assert f2.tell() == ftell # 200
|
395 |
+
assert f2.read() == ""
|
396 |
+
f2.seek(0)
|
397 |
+
assert f2.read() == fstr
|
398 |
+
assert f2.tell() == ftell # 200
|
399 |
+
else:
|
400 |
+
raise RuntimeError("Unknown file mode '%s'" % fmode)
|
401 |
+
f2.close() # XXX: other alternatives?
|
402 |
+
|
403 |
+
# write
|
404 |
+
|
405 |
+
f = open(fname, "w")
|
406 |
+
f.write("hello")
|
407 |
+
f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
|
408 |
+
f1mode = f.mode
|
409 |
+
ftell = f.tell()
|
410 |
+
|
411 |
+
fstr = open(fname).read()
|
412 |
+
|
413 |
+
f.write(" and goodbye!")
|
414 |
+
_ftell = f.tell()
|
415 |
+
f.close()
|
416 |
+
|
417 |
+
# XXX: no safe_file: no way to be 'safe'?
|
418 |
+
|
419 |
+
f2 = dill.loads(f_dumped)
|
420 |
+
f2mode = f2.mode
|
421 |
+
f2tell = f2.tell()
|
422 |
+
f2.write(" world!")
|
423 |
+
f2.close()
|
424 |
+
if fmode == dill.CONTENTS_FMODE:
|
425 |
+
assert open(fname).read() == "hello world!odbye!"
|
426 |
+
assert f2mode == f1mode
|
427 |
+
assert f2tell == ftell
|
428 |
+
elif fmode == dill.HANDLE_FMODE:
|
429 |
+
assert open(fname).read() == " world!"
|
430 |
+
assert f2mode == f1mode
|
431 |
+
assert f2tell == 0
|
432 |
+
elif fmode == dill.FILE_FMODE:
|
433 |
+
assert open(fname).read() == "hello world!"
|
434 |
+
assert f2mode == f1mode
|
435 |
+
assert f2tell == ftell
|
436 |
+
else:
|
437 |
+
raise RuntimeError("Unknown file mode '%s'" % fmode)
|
438 |
+
f2.close()
|
439 |
+
|
440 |
+
# append
|
441 |
+
|
442 |
+
trunc_file()
|
443 |
+
|
444 |
+
f = open(fname, "a")
|
445 |
+
f.write("hello")
|
446 |
+
f_dumped = dill.dumps(f, fmode=fmode)#, strictio=strictio)
|
447 |
+
f1mode = f.mode
|
448 |
+
ftell = f.tell()
|
449 |
+
fstr = open(fname).read()
|
450 |
+
|
451 |
+
f.write(" and goodbye!")
|
452 |
+
_ftell = f.tell()
|
453 |
+
f.close()
|
454 |
+
|
455 |
+
# XXX: no safe_file: no way to be 'safe'?
|
456 |
+
|
457 |
+
f2 = dill.loads(f_dumped)
|
458 |
+
f2mode = f2.mode
|
459 |
+
f2tell = f2.tell()
|
460 |
+
f2.write(" world!")
|
461 |
+
f2.close()
|
462 |
+
assert f2mode == f1mode
|
463 |
+
if fmode == dill.CONTENTS_FMODE:
|
464 |
+
assert open(fname).read() == "hello and goodbye! world!"
|
465 |
+
assert f2tell == ftell
|
466 |
+
elif fmode == dill.HANDLE_FMODE:
|
467 |
+
assert open(fname).read() == "hello and goodbye! world!"
|
468 |
+
assert f2tell == _ftell
|
469 |
+
elif fmode == dill.FILE_FMODE:
|
470 |
+
assert open(fname).read() == "hello world!"
|
471 |
+
assert f2tell == ftell
|
472 |
+
else:
|
473 |
+
raise RuntimeError("Unknown file mode '%s'" % fmode)
|
474 |
+
f2.close()
|
475 |
+
|
476 |
+
|
477 |
+
def test_nostrictio_handlefmode():
|
478 |
+
bench(False, dill.HANDLE_FMODE, False)
|
479 |
+
teardown_module()
|
480 |
+
|
481 |
+
|
482 |
+
def test_nostrictio_filefmode():
|
483 |
+
bench(False, dill.FILE_FMODE, False)
|
484 |
+
teardown_module()
|
485 |
+
|
486 |
+
|
487 |
+
def test_nostrictio_contentsfmode():
|
488 |
+
bench(False, dill.CONTENTS_FMODE, True)
|
489 |
+
teardown_module()
|
490 |
+
|
491 |
+
|
492 |
+
#bench(True, dill.HANDLE_FMODE, False)
|
493 |
+
#bench(True, dill.FILE_FMODE, False)
|
494 |
+
#bench(True, dill.CONTENTS_FMODE, True)
|
495 |
+
|
496 |
+
|
497 |
+
if __name__ == '__main__':
|
498 |
+
test_nostrictio_handlefmode()
|
499 |
+
test_nostrictio_filefmode()
|
500 |
+
test_nostrictio_contentsfmode()
|
env-llmeval/lib/python3.10/site-packages/dill/tests/test_module.py
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
#
|
3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
4 |
+
# Copyright (c) 2008-2016 California Institute of Technology.
|
5 |
+
# Copyright (c) 2016-2024 The Uncertainty Quantification Foundation.
|
6 |
+
# License: 3-clause BSD. The full license text is available at:
|
7 |
+
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
|
8 |
+
|
9 |
+
import sys
|
10 |
+
import dill
|
11 |
+
import test_mixins as module
|
12 |
+
from importlib import reload
|
13 |
+
dill.settings['recurse'] = True
|
14 |
+
|
15 |
+
cached = (module.__cached__ if hasattr(module, "__cached__")
|
16 |
+
else module.__file__.split(".", 1)[0] + ".pyc")
|
17 |
+
|
18 |
+
module.a = 1234
|
19 |
+
|
20 |
+
pik_mod = dill.dumps(module)
|
21 |
+
|
22 |
+
module.a = 0
|
23 |
+
|
24 |
+
# remove module
|
25 |
+
del sys.modules[module.__name__]
|
26 |
+
del module
|
27 |
+
|
28 |
+
module = dill.loads(pik_mod)
|
29 |
+
def test_attributes():
|
30 |
+
#assert hasattr(module, "a") and module.a == 1234 #FIXME: -m dill.tests
|
31 |
+
assert module.double_add(1, 2, 3) == 2 * module.fx
|
32 |
+
|
33 |
+
# Restart, and test use_diff
|
34 |
+
|
35 |
+
reload(module)
|
36 |
+
|
37 |
+
try:
|
38 |
+
dill.use_diff()
|
39 |
+
|
40 |
+
module.a = 1234
|
41 |
+
|
42 |
+
pik_mod = dill.dumps(module)
|
43 |
+
|
44 |
+
module.a = 0
|
45 |
+
|
46 |
+
# remove module
|
47 |
+
del sys.modules[module.__name__]
|
48 |
+
del module
|
49 |
+
|
50 |
+
module = dill.loads(pik_mod)
|
51 |
+
def test_diff_attributes():
|
52 |
+
assert hasattr(module, "a") and module.a == 1234
|
53 |
+
assert module.double_add(1, 2, 3) == 2 * module.fx
|
54 |
+
|
55 |
+
except AttributeError:
|
56 |
+
def test_diff_attributes():
|
57 |
+
pass
|
58 |
+
|
59 |
+
# clean up
|
60 |
+
import os
|
61 |
+
if os.path.exists(cached):
|
62 |
+
os.remove(cached)
|
63 |
+
pycache = os.path.join(os.path.dirname(module.__file__), "__pycache__")
|
64 |
+
if os.path.exists(pycache) and not os.listdir(pycache):
|
65 |
+
os.removedirs(pycache)
|
66 |
+
|
67 |
+
|
68 |
+
# test when module is None
|
69 |
+
import math
|
70 |
+
|
71 |
+
def get_lambda(str, **kwarg):
|
72 |
+
return eval(str, kwarg, None)
|
73 |
+
|
74 |
+
obj = get_lambda('lambda x: math.exp(x)', math=math)
|
75 |
+
|
76 |
+
def test_module_is_none():
|
77 |
+
assert obj.__module__ is None
|
78 |
+
assert dill.copy(obj)(3) == obj(3)
|
79 |
+
|
80 |
+
|
81 |
+
if __name__ == '__main__':
|
82 |
+
test_attributes()
|
83 |
+
test_diff_attributes()
|
84 |
+
test_module_is_none()
|
env-llmeval/lib/python3.10/site-packages/dill/tests/test_objects.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
#
|
3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
4 |
+
# Copyright (c) 2008-2016 California Institute of Technology.
|
5 |
+
# Copyright (c) 2016-2024 The Uncertainty Quantification Foundation.
|
6 |
+
# License: 3-clause BSD. The full license text is available at:
|
7 |
+
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
|
8 |
+
"""
|
9 |
+
demonstrate dill's ability to pickle different python types
|
10 |
+
test pickling of all Python Standard Library objects (currently: CH 1-14 @ 2.7)
|
11 |
+
"""
|
12 |
+
|
13 |
+
import dill as pickle
|
14 |
+
pickle.settings['recurse'] = True
|
15 |
+
#pickle.detect.trace(True)
|
16 |
+
#import pickle
|
17 |
+
|
18 |
+
# get all objects for testing
|
19 |
+
from dill import load_types, objects, extend
|
20 |
+
load_types(pickleable=True,unpickleable=False)
|
21 |
+
|
22 |
+
# uncomment the next two lines to test cloudpickle
|
23 |
+
#extend(False)
|
24 |
+
#import cloudpickle as pickle
|
25 |
+
|
26 |
+
# helper objects
|
27 |
+
class _class:
|
28 |
+
def _method(self):
|
29 |
+
pass
|
30 |
+
|
31 |
+
# objects that *fail* if imported
|
32 |
+
special = {}
|
33 |
+
special['LambdaType'] = _lambda = lambda x: lambda y: x
|
34 |
+
special['MethodType'] = _method = _class()._method
|
35 |
+
special['UnboundMethodType'] = _class._method
|
36 |
+
objects.update(special)
|
37 |
+
|
38 |
+
def pickles(name, exact=False, verbose=True):
|
39 |
+
"""quick check if object pickles with dill"""
|
40 |
+
obj = objects[name]
|
41 |
+
try:
|
42 |
+
pik = pickle.loads(pickle.dumps(obj))
|
43 |
+
if exact:
|
44 |
+
try:
|
45 |
+
assert pik == obj
|
46 |
+
except AssertionError:
|
47 |
+
assert type(obj) == type(pik)
|
48 |
+
if verbose: print ("weak: %s %s" % (name, type(obj)))
|
49 |
+
else:
|
50 |
+
assert type(obj) == type(pik)
|
51 |
+
except Exception:
|
52 |
+
if verbose: print ("fails: %s %s" % (name, type(obj)))
|
53 |
+
|
54 |
+
|
55 |
+
def test_objects(verbose=True):
|
56 |
+
for member in objects.keys():
|
57 |
+
#pickles(member, exact=True, verbose=verbose)
|
58 |
+
pickles(member, exact=False, verbose=verbose)
|
59 |
+
|
60 |
+
if __name__ == '__main__':
|
61 |
+
import warnings
|
62 |
+
warnings.simplefilter('ignore')
|
63 |
+
test_objects(verbose=False)
|
env-llmeval/lib/python3.10/site-packages/dill/tests/test_properties.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
#
|
3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
4 |
+
# Copyright (c) 2008-2016 California Institute of Technology.
|
5 |
+
# Copyright (c) 2016-2024 The Uncertainty Quantification Foundation.
|
6 |
+
# License: 3-clause BSD. The full license text is available at:
|
7 |
+
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
|
8 |
+
|
9 |
+
import sys
|
10 |
+
|
11 |
+
import dill
|
12 |
+
dill.settings['recurse'] = True
|
13 |
+
|
14 |
+
|
15 |
+
class Foo(object):
|
16 |
+
def __init__(self):
|
17 |
+
self._data = 1
|
18 |
+
|
19 |
+
def _get_data(self):
|
20 |
+
return self._data
|
21 |
+
|
22 |
+
def _set_data(self, x):
|
23 |
+
self._data = x
|
24 |
+
|
25 |
+
data = property(_get_data, _set_data)
|
26 |
+
|
27 |
+
|
28 |
+
def test_data_not_none():
|
29 |
+
FooS = dill.copy(Foo)
|
30 |
+
assert FooS.data.fget is not None
|
31 |
+
assert FooS.data.fset is not None
|
32 |
+
assert FooS.data.fdel is None
|
33 |
+
|
34 |
+
|
35 |
+
def test_data_unchanged():
|
36 |
+
FooS = dill.copy(Foo)
|
37 |
+
try:
|
38 |
+
res = FooS().data
|
39 |
+
except Exception:
|
40 |
+
e = sys.exc_info()[1]
|
41 |
+
raise AssertionError(str(e))
|
42 |
+
else:
|
43 |
+
assert res == 1
|
44 |
+
|
45 |
+
|
46 |
+
def test_data_changed():
|
47 |
+
FooS = dill.copy(Foo)
|
48 |
+
try:
|
49 |
+
f = FooS()
|
50 |
+
f.data = 1024
|
51 |
+
res = f.data
|
52 |
+
except Exception:
|
53 |
+
e = sys.exc_info()[1]
|
54 |
+
raise AssertionError(str(e))
|
55 |
+
else:
|
56 |
+
assert res == 1024
|
57 |
+
|
58 |
+
|
59 |
+
if __name__ == '__main__':
|
60 |
+
test_data_not_none()
|
61 |
+
test_data_unchanged()
|
62 |
+
test_data_changed()
|
env-llmeval/lib/python3.10/site-packages/dill/tests/test_recursive.py
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
#
|
3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
4 |
+
# Copyright (c) 2019-2024 The Uncertainty Quantification Foundation.
|
5 |
+
# License: 3-clause BSD. The full license text is available at:
|
6 |
+
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
|
7 |
+
|
8 |
+
import dill
|
9 |
+
from functools import partial
|
10 |
+
import warnings
|
11 |
+
|
12 |
+
|
13 |
+
def copy(obj, byref=False, recurse=False):
|
14 |
+
if byref:
|
15 |
+
try:
|
16 |
+
return dill.copy(obj, byref=byref, recurse=recurse)
|
17 |
+
except Exception:
|
18 |
+
pass
|
19 |
+
else:
|
20 |
+
raise AssertionError('Copy of %s with byref=True should have given a warning!' % (obj,))
|
21 |
+
|
22 |
+
warnings.simplefilter('ignore')
|
23 |
+
val = dill.copy(obj, byref=byref, recurse=recurse)
|
24 |
+
warnings.simplefilter('error')
|
25 |
+
return val
|
26 |
+
else:
|
27 |
+
return dill.copy(obj, byref=byref, recurse=recurse)
|
28 |
+
|
29 |
+
|
30 |
+
class obj1(object):
|
31 |
+
def __init__(self):
|
32 |
+
super(obj1, self).__init__()
|
33 |
+
|
34 |
+
class obj2(object):
|
35 |
+
def __init__(self):
|
36 |
+
super(obj2, self).__init__()
|
37 |
+
|
38 |
+
class obj3(object):
|
39 |
+
super_ = super
|
40 |
+
def __init__(self):
|
41 |
+
obj3.super_(obj3, self).__init__()
|
42 |
+
|
43 |
+
|
44 |
+
def test_super():
|
45 |
+
assert copy(obj1(), byref=True)
|
46 |
+
assert copy(obj1(), byref=True, recurse=True)
|
47 |
+
assert copy(obj1(), recurse=True)
|
48 |
+
assert copy(obj1())
|
49 |
+
|
50 |
+
assert copy(obj2(), byref=True)
|
51 |
+
assert copy(obj2(), byref=True, recurse=True)
|
52 |
+
assert copy(obj2(), recurse=True)
|
53 |
+
assert copy(obj2())
|
54 |
+
|
55 |
+
assert copy(obj3(), byref=True)
|
56 |
+
assert copy(obj3(), byref=True, recurse=True)
|
57 |
+
assert copy(obj3(), recurse=True)
|
58 |
+
assert copy(obj3())
|
59 |
+
|
60 |
+
|
61 |
+
def get_trigger(model):
|
62 |
+
pass
|
63 |
+
|
64 |
+
class Machine(object):
|
65 |
+
def __init__(self):
|
66 |
+
self.child = Model()
|
67 |
+
self.trigger = partial(get_trigger, self)
|
68 |
+
self.child.trigger = partial(get_trigger, self.child)
|
69 |
+
|
70 |
+
class Model(object):
|
71 |
+
pass
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
def test_partial():
|
76 |
+
assert copy(Machine(), byref=True)
|
77 |
+
assert copy(Machine(), byref=True, recurse=True)
|
78 |
+
assert copy(Machine(), recurse=True)
|
79 |
+
assert copy(Machine())
|
80 |
+
|
81 |
+
|
82 |
+
class Machine2(object):
|
83 |
+
def __init__(self):
|
84 |
+
self.go = partial(self.member, self)
|
85 |
+
def member(self, model):
|
86 |
+
pass
|
87 |
+
|
88 |
+
|
89 |
+
class SubMachine(Machine2):
|
90 |
+
def __init__(self):
|
91 |
+
super(SubMachine, self).__init__()
|
92 |
+
|
93 |
+
|
94 |
+
def test_partials():
|
95 |
+
assert copy(SubMachine(), byref=True)
|
96 |
+
assert copy(SubMachine(), byref=True, recurse=True)
|
97 |
+
assert copy(SubMachine(), recurse=True)
|
98 |
+
assert copy(SubMachine())
|
99 |
+
|
100 |
+
|
101 |
+
class obj4(object):
|
102 |
+
def __init__(self):
|
103 |
+
super(obj4, self).__init__()
|
104 |
+
a = self
|
105 |
+
class obj5(object):
|
106 |
+
def __init__(self):
|
107 |
+
super(obj5, self).__init__()
|
108 |
+
self.a = a
|
109 |
+
self.b = obj5()
|
110 |
+
|
111 |
+
|
112 |
+
def test_circular_reference():
|
113 |
+
assert copy(obj4())
|
114 |
+
obj4_copy = dill.loads(dill.dumps(obj4()))
|
115 |
+
assert type(obj4_copy) is type(obj4_copy).__init__.__closure__[0].cell_contents
|
116 |
+
assert type(obj4_copy.b) is type(obj4_copy.b).__init__.__closure__[0].cell_contents
|
117 |
+
|
118 |
+
|
119 |
+
def f():
|
120 |
+
def g():
|
121 |
+
return g
|
122 |
+
return g
|
123 |
+
|
124 |
+
|
125 |
+
def test_function_cells():
|
126 |
+
assert copy(f())
|
127 |
+
|
128 |
+
|
129 |
+
def fib(n):
|
130 |
+
assert n >= 0
|
131 |
+
if n <= 1:
|
132 |
+
return n
|
133 |
+
else:
|
134 |
+
return fib(n-1) + fib(n-2)
|
135 |
+
|
136 |
+
|
137 |
+
def test_recursive_function():
|
138 |
+
global fib
|
139 |
+
fib2 = copy(fib, recurse=True)
|
140 |
+
fib3 = copy(fib)
|
141 |
+
fib4 = fib
|
142 |
+
del fib
|
143 |
+
assert fib2(5) == 5
|
144 |
+
for _fib in (fib3, fib4):
|
145 |
+
try:
|
146 |
+
_fib(5)
|
147 |
+
except Exception:
|
148 |
+
# This is expected to fail because fib no longer exists
|
149 |
+
pass
|
150 |
+
else:
|
151 |
+
raise AssertionError("Function fib shouldn't have been found")
|
152 |
+
fib = fib4
|
153 |
+
|
154 |
+
|
155 |
+
def collection_function_recursion():
|
156 |
+
d = {}
|
157 |
+
def g():
|
158 |
+
return d
|
159 |
+
d['g'] = g
|
160 |
+
return g
|
161 |
+
|
162 |
+
|
163 |
+
def test_collection_function_recursion():
|
164 |
+
g = copy(collection_function_recursion())
|
165 |
+
assert g()['g'] is g
|
166 |
+
|
167 |
+
|
168 |
+
if __name__ == '__main__':
|
169 |
+
with warnings.catch_warnings():
|
170 |
+
warnings.simplefilter('error')
|
171 |
+
test_super()
|
172 |
+
test_partial()
|
173 |
+
test_partials()
|
174 |
+
test_circular_reference()
|
175 |
+
test_function_cells()
|
176 |
+
test_recursive_function()
|
177 |
+
test_collection_function_recursion()
|
env-llmeval/lib/python3.10/site-packages/dill/tests/test_temp.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
#
|
3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
4 |
+
# Copyright (c) 2008-2016 California Institute of Technology.
|
5 |
+
# Copyright (c) 2016-2024 The Uncertainty Quantification Foundation.
|
6 |
+
# License: 3-clause BSD. The full license text is available at:
|
7 |
+
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
|
8 |
+
|
9 |
+
import sys
|
10 |
+
from dill.temp import dump, dump_source, dumpIO, dumpIO_source
|
11 |
+
from dill.temp import load, load_source, loadIO, loadIO_source
|
12 |
+
WINDOWS = sys.platform[:3] == 'win'
|
13 |
+
|
14 |
+
|
15 |
+
f = lambda x: x**2
|
16 |
+
x = [1,2,3,4,5]
|
17 |
+
|
18 |
+
# source code to tempfile
|
19 |
+
def test_code_to_tempfile():
|
20 |
+
if not WINDOWS: #see: https://bugs.python.org/issue14243
|
21 |
+
pyfile = dump_source(f, alias='_f')
|
22 |
+
_f = load_source(pyfile)
|
23 |
+
assert _f(4) == f(4)
|
24 |
+
|
25 |
+
# source code to stream
|
26 |
+
def test_code_to_stream():
|
27 |
+
pyfile = dumpIO_source(f, alias='_f')
|
28 |
+
_f = loadIO_source(pyfile)
|
29 |
+
assert _f(4) == f(4)
|
30 |
+
|
31 |
+
# pickle to tempfile
|
32 |
+
def test_pickle_to_tempfile():
|
33 |
+
if not WINDOWS: #see: https://bugs.python.org/issue14243
|
34 |
+
dumpfile = dump(x)
|
35 |
+
_x = load(dumpfile)
|
36 |
+
assert _x == x
|
37 |
+
|
38 |
+
# pickle to stream
|
39 |
+
def test_pickle_to_stream():
|
40 |
+
dumpfile = dumpIO(x)
|
41 |
+
_x = loadIO(dumpfile)
|
42 |
+
assert _x == x
|
43 |
+
|
44 |
+
### now testing the objects ###
|
45 |
+
f = lambda x: x**2
|
46 |
+
def g(x): return f(x) - x
|
47 |
+
|
48 |
+
def h(x):
|
49 |
+
def g(x): return x
|
50 |
+
return g(x) - x
|
51 |
+
|
52 |
+
class Foo(object):
|
53 |
+
def bar(self, x):
|
54 |
+
return x*x+x
|
55 |
+
_foo = Foo()
|
56 |
+
|
57 |
+
def add(x,y):
|
58 |
+
return x+y
|
59 |
+
|
60 |
+
# yes, same as 'f', but things are tricky when it comes to pointers
|
61 |
+
squared = lambda x:x**2
|
62 |
+
|
63 |
+
class Bar:
|
64 |
+
pass
|
65 |
+
_bar = Bar()
|
66 |
+
|
67 |
+
|
68 |
+
# test function-type objects that take 2 args
|
69 |
+
def test_two_arg_functions():
|
70 |
+
for obj in [add]:
|
71 |
+
pyfile = dumpIO_source(obj, alias='_obj')
|
72 |
+
_obj = loadIO_source(pyfile)
|
73 |
+
assert _obj(4,2) == obj(4,2)
|
74 |
+
|
75 |
+
# test function-type objects that take 1 arg
|
76 |
+
def test_one_arg_functions():
|
77 |
+
for obj in [g, h, squared]:
|
78 |
+
pyfile = dumpIO_source(obj, alias='_obj')
|
79 |
+
_obj = loadIO_source(pyfile)
|
80 |
+
assert _obj(4) == obj(4)
|
81 |
+
|
82 |
+
# test instance-type objects
|
83 |
+
#for obj in [_bar, _foo]:
|
84 |
+
# pyfile = dumpIO_source(obj, alias='_obj')
|
85 |
+
# _obj = loadIO_source(pyfile)
|
86 |
+
# assert type(_obj) == type(obj)
|
87 |
+
|
88 |
+
# test the rest of the objects
|
89 |
+
def test_the_rest():
|
90 |
+
for obj in [Bar, Foo, Foo.bar, _foo.bar]:
|
91 |
+
pyfile = dumpIO_source(obj, alias='_obj')
|
92 |
+
_obj = loadIO_source(pyfile)
|
93 |
+
assert _obj.__name__ == obj.__name__
|
94 |
+
|
95 |
+
|
96 |
+
if __name__ == '__main__':
|
97 |
+
test_code_to_tempfile()
|
98 |
+
test_code_to_stream()
|
99 |
+
test_pickle_to_tempfile()
|
100 |
+
test_pickle_to_stream()
|
101 |
+
test_two_arg_functions()
|
102 |
+
test_one_arg_functions()
|
103 |
+
test_the_rest()
|
env-llmeval/lib/python3.10/site-packages/dill/tests/test_weakref.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
#
|
3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
4 |
+
# Copyright (c) 2008-2016 California Institute of Technology.
|
5 |
+
# Copyright (c) 2016-2024 The Uncertainty Quantification Foundation.
|
6 |
+
# License: 3-clause BSD. The full license text is available at:
|
7 |
+
# - https://github.com/uqfoundation/dill/blob/master/LICENSE
|
8 |
+
|
9 |
+
import dill
|
10 |
+
dill.settings['recurse'] = True
|
11 |
+
import weakref
|
12 |
+
|
13 |
+
class _class:
|
14 |
+
def _method(self):
|
15 |
+
pass
|
16 |
+
|
17 |
+
class _callable_class:
|
18 |
+
def __call__(self):
|
19 |
+
pass
|
20 |
+
|
21 |
+
def _function():
|
22 |
+
pass
|
23 |
+
|
24 |
+
|
25 |
+
def test_weakref():
|
26 |
+
o = _class()
|
27 |
+
oc = _callable_class()
|
28 |
+
f = _function
|
29 |
+
x = _class
|
30 |
+
|
31 |
+
# ReferenceType
|
32 |
+
r = weakref.ref(o)
|
33 |
+
d_r = weakref.ref(_class())
|
34 |
+
fr = weakref.ref(f)
|
35 |
+
xr = weakref.ref(x)
|
36 |
+
|
37 |
+
# ProxyType
|
38 |
+
p = weakref.proxy(o)
|
39 |
+
d_p = weakref.proxy(_class())
|
40 |
+
|
41 |
+
# CallableProxyType
|
42 |
+
cp = weakref.proxy(oc)
|
43 |
+
d_cp = weakref.proxy(_callable_class())
|
44 |
+
fp = weakref.proxy(f)
|
45 |
+
xp = weakref.proxy(x)
|
46 |
+
|
47 |
+
objlist = [r,d_r,fr,xr, p,d_p, cp,d_cp,fp,xp]
|
48 |
+
#dill.detect.trace(True)
|
49 |
+
|
50 |
+
for obj in objlist:
|
51 |
+
res = dill.detect.errors(obj)
|
52 |
+
if res:
|
53 |
+
print ("%r:\n %s" % (obj, res))
|
54 |
+
# else:
|
55 |
+
# print ("PASS: %s" % obj)
|
56 |
+
assert not res
|
57 |
+
|
58 |
+
def test_dictproxy():
|
59 |
+
from dill._dill import DictProxyType
|
60 |
+
try:
|
61 |
+
m = DictProxyType({"foo": "bar"})
|
62 |
+
except Exception:
|
63 |
+
m = type.__dict__
|
64 |
+
mp = dill.copy(m)
|
65 |
+
assert mp.items() == m.items()
|
66 |
+
|
67 |
+
|
68 |
+
if __name__ == '__main__':
|
69 |
+
test_weakref()
|
70 |
+
from dill._dill import IS_PYPY
|
71 |
+
if not IS_PYPY:
|
72 |
+
test_dictproxy()
|
env-llmeval/lib/python3.10/site-packages/numexpr/__init__.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
###################################################################
|
2 |
+
# Numexpr - Fast numerical array expression evaluator for NumPy.
|
3 |
+
#
|
4 |
+
# License: MIT
|
5 |
+
# Author: See AUTHORS.txt
|
6 |
+
#
|
7 |
+
# See LICENSE.txt and LICENSES/*.txt for details about copyright and
|
8 |
+
# rights to use.
|
9 |
+
####################################################################
|
10 |
+
|
11 |
+
"""
|
12 |
+
Numexpr is a fast numerical expression evaluator for NumPy. With it,
|
13 |
+
expressions that operate on arrays (like "3*a+4*b") are accelerated
|
14 |
+
and use less memory than doing the same calculation in Python.
|
15 |
+
|
16 |
+
See:
|
17 |
+
|
18 |
+
https://github.com/pydata/numexpr
|
19 |
+
|
20 |
+
for more info about it.
|
21 |
+
|
22 |
+
"""
|
23 |
+
|
24 |
+
from numexpr.interpreter import MAX_THREADS, use_vml, __BLOCK_SIZE1__
|
25 |
+
|
26 |
+
is_cpu_amd_intel = False # DEPRECATION WARNING: WILL BE REMOVED IN FUTURE RELEASE
|
27 |
+
|
28 |
+
# cpuinfo imports were moved into the test submodule function that calls them
|
29 |
+
# to improve import times.
|
30 |
+
|
31 |
+
import os, os.path
|
32 |
+
import platform
|
33 |
+
from numexpr.expressions import E
|
34 |
+
from numexpr.necompiler import (NumExpr, disassemble, evaluate, re_evaluate,
|
35 |
+
validate)
|
36 |
+
|
37 |
+
from numexpr.utils import (_init_num_threads,
|
38 |
+
get_vml_version, set_vml_accuracy_mode, set_vml_num_threads,
|
39 |
+
set_num_threads, get_num_threads,
|
40 |
+
detect_number_of_cores, detect_number_of_threads)
|
41 |
+
|
42 |
+
# Detect the number of cores
|
43 |
+
ncores = detect_number_of_cores()
|
44 |
+
# Initialize the number of threads to be used
|
45 |
+
nthreads = _init_num_threads()
|
46 |
+
# The default for VML is 1 thread (see #39)
|
47 |
+
# set_vml_num_threads(1)
|
48 |
+
|
49 |
+
from . import version
|
50 |
+
__version__ = version.version
|
51 |
+
|
52 |
+
def print_versions():
|
53 |
+
"""Print the versions of software that numexpr relies on."""
|
54 |
+
try:
|
55 |
+
import numexpr.tests
|
56 |
+
return numexpr.tests.print_versions()
|
57 |
+
except ImportError:
|
58 |
+
# To maintain Python 2.6 compatibility we have simple error handling
|
59 |
+
raise ImportError('`numexpr.tests` could not be imported, likely it was excluded from the distribution.')
|
60 |
+
|
61 |
+
def test(verbosity=1):
|
62 |
+
"""Run all the tests in the test suite."""
|
63 |
+
try:
|
64 |
+
import numexpr.tests
|
65 |
+
return numexpr.tests.test(verbosity=verbosity)
|
66 |
+
except ImportError:
|
67 |
+
# To maintain Python 2.6 compatibility we have simple error handling
|
68 |
+
raise ImportError('`numexpr.tests` could not be imported, likely it was excluded from the distribution.')
|
env-llmeval/lib/python3.10/site-packages/numexpr/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (1.76 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/numexpr/__pycache__/cpuinfo.cpython-310.pyc
ADDED
Binary file (31.8 kB). View file
|
|