def test_debuggable(self): s = """ { "a": { "node": "algorithm.Arange" }, "mean": { "node": "algorithm.Convolution", "lookup_attrs": {"source": "a"}, "attrs": {"kernel_type": "mean,3", "kernel_dims": ["lat", "lon"]} }, "c": { "node": "algorithm.Arithmetic", "lookup_attrs": {"A": "a", "B": "mean"}, "attrs": {"eqn": "a-b"} } } """ with warnings.catch_warnings(), podpac.settings: warnings.filterwarnings("ignore", "Insecure evaluation.*") # normally node objects can and should be re-used podpac.settings["DEBUG"] = False node = Node.from_json(s) assert node.inputs["A"] is node.inputs["B"].source # when debugging is on, node objects should be unique podpac.settings["DEBUG"] = True node = Node.from_json(s) assert node.inputs["A"] is not node.inputs["B"].source
def test_inputs(self): # invalid type s = """ { "a": { "node": "algorithm.Min", "inputs": { "source": 10 } } } """ with pytest.raises(ValueError, match="Invalid definition for node"): Node.from_json(s) # nonexistent node s = """ { "a": { "node": "algorithm.Min", "inputs": { "source": "nonexistent" } } } """ with pytest.raises(ValueError, match="Invalid definition for node"): Node.from_json(s)
def test_plugin(self): global MyPluginNode class MyPluginNode(Node): pass s = """ { "mynode": { "plugin": "test_node", "node": "MyPluginNode" } } """ node = Node.from_json(s) assert isinstance(node, MyPluginNode) # missing plugin s = """ { "mynode": { "plugin": "missing", "node": "MyPluginNode" } } """ with pytest.raises(ValueError, match="no module found"): Node.from_json(s)
def test_invalid_node(self): # module does not exist s = '{"a": {"node": "nonexistent.Arbitrary"} }' with pytest.raises(ValueError, match="no module found"): Node.from_json(s) # node does not exist in module s = '{"a": {"node": "core.Nonexistent"} }' with pytest.raises(ValueError, match="class 'Nonexistent' not found in module"): Node.from_json(s)
def test_invalid_property(self): s = """ { "a": { "node": "algorithm.Arange", "invalid_property": "value" } } """ with pytest.raises(ValueError, match="unexpected property"): Node.from_json(s)
def test_from_definition_version_warning(self): s = """ { "a": { "node": "algorithm.Arange" }, "podpac_version": "other" } """ with pytest.warns(UserWarning, match="node definition version mismatch"): node = Node.from_json(s)
def _f(definition, coords, q, outputkw): try: n = Node.from_json(definition) c = Coordinates.from_json(coords) o = n.eval(c) o._pp_serialize() _log.debug("o.shape: {}, output_format: {}".format(o.shape, outputkw)) if outputkw: _log.debug( "Saving output results to output format {}".format(outputkw)) o = o.to_format(outputkw["format"], **outputkw.get("format_kwargs")) q.put(o) except Exception as e: q.put(str(e))
def test_json(self): # json s = self.node.json assert isinstance(s, six.string_types) assert json.loads(s) # test from_json with warnings.catch_warnings(): warnings.filterwarnings("ignore", "Insecure evaluation.*") node = Node.from_json(s) assert node is not self.node assert node == self.node assert isinstance(node, podpac.algorithm.Arithmetic) assert isinstance(node.inputs["A"], podpac.algorithm.Arange) assert isinstance(node.inputs["B"], podpac.data.Array) assert isinstance(node.inputs["C"], podpac.compositor.OrderedCompositor)
def test_interpolation_definition(self): node = Node.from_json(self.interp.json) o1 = node.eval(self.coords) o2 = self.interp.eval(self.coords) np.testing.assert_array_equal(o1.data, o2.data) assert node.json == self.interp.json
def test_lookup_attrs(self): s = """ { "a": { "node": "algorithm.CoordData", "attrs": { "coord_name": "lat" } }, "b": { "node": "algorithm.CoordData", "lookup_attrs": { "coord_name": "a.coord_name" } } } """ node = Node.from_json(s) assert isinstance(node, podpac.algorithm.CoordData) assert node.coord_name == "lat" # invalid type s = """ { "a": { "node": "algorithm.CoordData", "attrs": { "coord_name": "lat" } }, "b": { "node": "algorithm.CoordData", "lookup_attrs": { "coord_name": 10 } } } """ with pytest.raises(ValueError, match="Invalid definition for node"): Node.from_json(s) # nonexistent node s = """ { "a": { "node": "algorithm.CoordData", "attrs": { "coord_name": "lat" } }, "b": { "node": "algorithm.CoordData", "lookup_attrs": { "coord_name": "nonexistent.coord_name" } } } """ with pytest.raises(ValueError, match="Invalid definition for node"): Node.from_json(s) # nonexistent subattr s = """ { "a": { "node": "algorithm.CoordData", "attrs": { "coord_name": "lat" } }, "b": { "node": "algorithm.CoordData", "lookup_attrs": { "coord_name": "a.nonexistent" } } } """ with pytest.raises(ValueError, match="Invalid definition for node"): Node.from_json(s)
def test_no_node(self): s = '{"test": { } }' with pytest.raises(ValueError, match="'node' property required"): Node.from_json(s)
def test_empty(self): s = "{ }" with pytest.raises(ValueError, match="definition cannot be empty"): Node.from_json(s)