|
5 | 5 |
|
6 | 6 | import pytest
|
7 | 7 |
|
8 |
| -from hamilton import graph_types, node |
| 8 | +from hamilton import driver, graph_types, node |
9 | 9 | from hamilton.node import Node, NodeType
|
10 | 10 |
|
11 | 11 | from tests import nodes as test_nodes
|
| 12 | +from tests.resources.dynamic_parallelism import no_parallel |
12 | 13 |
|
13 | 14 |
|
14 | 15 | @pytest.fixture()
|
@@ -113,14 +114,52 @@ def node_to_create(required_dep: int, optional_dep: int = 1) -> str:
|
113 | 114 | }
|
114 | 115 |
|
115 | 116 |
|
116 |
| -def test_create_hamilton_node_missing_version(): |
| 117 | +def test_create_hamilton_config_node_version(): |
| 118 | + """Config nodes now return the name as the version.""" |
117 | 119 | n = Node("foo", int, node_source=NodeType.EXTERNAL)
|
118 | 120 | hamilton_node = graph_types.HamiltonNode.from_node(n)
|
119 | 121 | # the above will have no specified versions
|
| 122 | + assert hamilton_node.version == "foo" |
| 123 | + assert hamilton_node.as_dict()["version"] == "foo" |
| 124 | + |
| 125 | + |
| 126 | +def test_create_hamilton_node_missing_version(): |
| 127 | + """We contrive a case where originating_functions is None.""" |
| 128 | + |
| 129 | + def foo(i: int) -> int: |
| 130 | + return i |
| 131 | + |
| 132 | + n = Node("foo", int, "", foo, node_source=NodeType.STANDARD) |
| 133 | + hamilton_node = graph_types.HamiltonNode.from_node(n) |
| 134 | + # the above will have no specified versions |
120 | 135 | assert hamilton_node.version is None
|
121 | 136 | assert hamilton_node.as_dict()["version"] is None
|
122 | 137 |
|
123 | 138 |
|
| 139 | +def test_hamilton_graph_version_normal(): |
| 140 | + dr = driver.Builder().with_modules(no_parallel).build() |
| 141 | + graph = graph_types.HamiltonGraph.from_graph(dr.graph) |
| 142 | + # assumption is for python 3 |
| 143 | + if sys.version_info.minor == 8: |
| 144 | + hash_value = "0a375f3366590453dea8927d4c02c15dc090f8be42e9129d9a1139284eac920c" |
| 145 | + else: |
| 146 | + hash_value = "3b3487599ccc4fc56995989c6d32b58a90c0b91b8c16b3f453a2793f47436831" |
| 147 | + assert graph.version == hash_value |
| 148 | + |
| 149 | + |
| 150 | +def test_hamilton_graph_version_with_none_originating_functions(): |
| 151 | + dr = driver.Builder().with_modules(no_parallel).build() |
| 152 | + graph = graph_types.HamiltonGraph.from_graph(dr.graph) |
| 153 | + # if this gets flakey we should find a specific node to make None |
| 154 | + graph.nodes[-1].originating_functions = None |
| 155 | + # assumption is for python 3 |
| 156 | + if sys.version_info.minor == 8: |
| 157 | + hash_value = "7d556424cd84b97a395d9b6219f502e8f818f17002ce88f47974266c0cce454a" |
| 158 | + else: |
| 159 | + hash_value = "781d89517c1744c40a7afcdc49ee8592fbb23955e28d87f1b584d08430a3e837" |
| 160 | + assert graph.version == hash_value |
| 161 | + |
| 162 | + |
124 | 163 | def test_json_serializable_dict():
|
125 | 164 | for name, obj in inspect.getmembers(test_nodes):
|
126 | 165 | if inspect.isfunction(obj) and not name.startswith("_"):
|
|
0 commit comments