Skip to content

Commit 4809dfe

Browse files
committed
fixed tests after switch to using nested bytes repr instead of hashes for nested types
1 parent 10dda96 commit 4809dfe

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

pydra/utils/hash.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,15 @@ def type_name(tp):
242242
origin = ty.get_origin(klass)
243243
if origin:
244244
yield f"{origin.__module__}.{type_name(origin)}[".encode()
245-
yield from (b for t in ty.get_args(klass) for b in bytes_repr_type(t, cache))
245+
for arg in ty.get_args(klass):
246+
if isinstance(
247+
arg, list
248+
): # sometimes (e.g. Callable) the args of a type is a list
249+
yield b"["
250+
yield from (b for t in arg for b in bytes_repr_type(t, cache))
251+
yield b"]"
252+
else:
253+
yield from bytes_repr_type(arg, cache)
246254
yield b"]"
247255
else:
248256
yield f"{klass.__module__}.{type_name(klass)}".encode()

pydra/utils/tests/test_hash.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,14 @@ class MyClass(ty.Generic[T]):
181181
pass
182182

183183
obj_repr = join_bytes_repr(MyClass[int])
184-
assert obj_repr == b"type:(pydra.utils.tests.test_hash.MyClass[type:(int)])"
184+
assert (
185+
obj_repr == b"type:(pydra.utils.tests.test_hash.MyClass[type:(builtins.int)])"
186+
)
185187

186188

187189
def test_bytes_special_form1():
188190
obj_repr = join_bytes_repr(ty.Union[int, float])
189-
assert re.match(rb"type:\(typing.Union\[.{32}\]\)", obj_repr)
191+
assert obj_repr == b"type:(typing.Union[type:(builtins.int)type:(builtins.float)])"
190192

191193

192194
def test_bytes_special_form2():
@@ -196,20 +198,22 @@ def test_bytes_special_form2():
196198

197199
def test_bytes_special_form3():
198200
obj_repr = join_bytes_repr(ty.Optional[Path])
199-
assert re.match(rb"type:\(typing.Union\[.{32}\]\)", obj_repr, flags=re.DOTALL)
201+
assert (
202+
obj_repr == b"type:(typing.Union[type:(pathlib.Path)type:(builtins.NoneType)])"
203+
)
200204

201205

202206
def test_bytes_special_form4():
203207
obj_repr = join_bytes_repr(ty.Type[Path])
204-
assert re.match(rb"type:\(builtins.type\[.{16}\]\)", obj_repr, flags=re.DOTALL)
208+
assert obj_repr == b"type:(builtins.type[type:(pathlib.Path)])"
205209

206210

207211
def test_bytes_special_form5():
208212
obj_repr = join_bytes_repr(ty.Callable[[Path, int], ty.Tuple[float, str]])
209-
assert re.match(
210-
rb"type:\(collections.abc.Callable\[.{32}\]\)", obj_repr, flags=re.DOTALL
213+
assert obj_repr == (
214+
b"type:(collections.abc.Callable[[type:(pathlib.Path)type:(builtins.int)]"
215+
b"type:(builtins.tuple[type:(builtins.float)type:(builtins.str)])])"
211216
)
212-
assert obj_repr != join_bytes_repr(ty.Callable[[Path, int], ty.Tuple[float, bytes]])
213217

214218

215219
def test_recursive_object():

0 commit comments

Comments
 (0)