MCPcopy Index your code
hub / github.com/ray-project/ray / test_complex_serialization

Function test_complex_serialization

python/ray/tests/test_serialization.py:89–289  ·  view source on GitHub ↗
(ray_start_regular)

Source from the content-addressed store, hash-verified

87
88
89def test_complex_serialization(ray_start_regular):
90 def assert_equal(obj1, obj2):
91 module_numpy = (
92 type(obj1).__module__ == np.__name__ or type(obj2).__module__ == np.__name__
93 )
94 if module_numpy:
95 empty_shape = (hasattr(obj1, "shape") and obj1.shape == ()) or (
96 hasattr(obj2, "shape") and obj2.shape == ()
97 )
98 if empty_shape:
99 # This is a special case because currently
100 # np.testing.assert_equal fails because we do not properly
101 # handle different numerical types.
102 assert obj1 == obj2, "Objects {} and {} are different.".format(
103 obj1, obj2
104 )
105 else:
106 np.testing.assert_equal(obj1, obj2)
107 elif hasattr(obj1, "__dict__") and hasattr(obj2, "__dict__"):
108 special_keys = ["_pytype_"]
109 assert set(list(obj1.__dict__.keys()) + special_keys) == set(
110 list(obj2.__dict__.keys()) + special_keys
111 ), "Objects {} and {} are different.".format(obj1, obj2)
112 for key in obj1.__dict__.keys():
113 if key not in special_keys:
114 assert_equal(obj1.__dict__[key], obj2.__dict__[key])
115 elif type(obj1) is dict or type(obj2) is dict:
116 assert_equal(obj1.keys(), obj2.keys())
117 for key in obj1.keys():
118 assert_equal(obj1[key], obj2[key])
119 elif type(obj1) is list or type(obj2) is list:
120 assert len(obj1) == len(
121 obj2
122 ), "Objects {} and {} are lists with different lengths.".format(obj1, obj2)
123 for i in range(len(obj1)):
124 assert_equal(obj1[i], obj2[i])
125 elif type(obj1) is tuple or type(obj2) is tuple:
126 assert len(obj1) == len(
127 obj2
128 ), "Objects {} and {} are tuples with different lengths.".format(obj1, obj2)
129 for i in range(len(obj1)):
130 assert_equal(obj1[i], obj2[i])
131 elif is_named_tuple(type(obj1)) or is_named_tuple(type(obj2)):
132 assert len(obj1) == len(
133 obj2
134 ), "Objects {} and {} are named tuples with different lengths.".format(
135 obj1, obj2
136 )
137 for i in range(len(obj1)):
138 assert_equal(obj1[i], obj2[i])
139 else:
140 assert obj1 == obj2, "Objects {} and {} are different.".format(obj1, obj2)
141
142 long_extras = [0, np.array([["hi", "hi"], [1.3, 1]])]
143
144 PRIMITIVE_OBJECTS = [
145 0,
146 0.0,

Callers

nothing calls this directly

Calls 15

BazClass · 0.85
DataClass2Class · 0.85
assert_equalFunction · 0.85
normalMethod · 0.80
readlineMethod · 0.80
CustomErrorClass · 0.70
FooClass · 0.70
BarClass · 0.70
CustomClassClass · 0.70
getMethod · 0.65
putMethod · 0.65
rangeFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…