|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import hashlib |
3 | 4 | import pickle |
4 | 5 | import sys |
5 | 6 | from pathlib import Path |
| 7 | +from typing import cast |
6 | 8 |
|
7 | 9 | import cloudpickle |
8 | 10 | import pytest |
| 11 | +import upath |
9 | 12 |
|
10 | 13 | from pytask import NodeInfo |
11 | 14 | from pytask import PathNode |
@@ -118,6 +121,29 @@ def test_hash_of_pickle_node(tmp_path, value, exists, expected): |
118 | 121 | assert state is expected |
119 | 122 |
|
120 | 123 |
|
| 124 | +@pytest.mark.parametrize("node_cls", [PathNode, PickleNode]) |
| 125 | +def test_signature_of_remote_upath_node(node_cls): |
| 126 | + node = node_cls(name="test", path=cast("Path", upath.UPath("s3://bucket/file.pkl"))) |
| 127 | + |
| 128 | + expected = hashlib.sha256( |
| 129 | + b"5bbedd1ab74242143481060b901083e77080661d97003b96e0cbae3a887ebce6" |
| 130 | + ).hexdigest() |
| 131 | + |
| 132 | + assert node.signature == expected |
| 133 | + |
| 134 | + |
| 135 | +@pytest.mark.parametrize("node_cls", [PathNode, PickleNode]) |
| 136 | +@pytest.mark.parametrize("protocol", ["file", "local"]) |
| 137 | +def test_signature_of_local_upath_node_matches_path(tmp_path, node_cls, protocol): |
| 138 | + path = tmp_path / "file.pkl" |
| 139 | + upath_value = upath.UPath(f"{protocol}:///{path.as_posix().lstrip('/')}") |
| 140 | + |
| 141 | + local_node = node_cls(name="test", path=path) |
| 142 | + upath_node = node_cls(name="test", path=cast("Path", upath_value)) |
| 143 | + |
| 144 | + assert upath_node.signature == local_node.signature |
| 145 | + |
| 146 | + |
121 | 147 | @pytest.mark.parametrize( |
122 | 148 | ("node", "protocol", "expected"), |
123 | 149 | [ |
|
0 commit comments