def test_select_sources_intersection(self): source_coords = podpac.Coordinates([[0, 10]], ["time"]) node = BaseCompositor(sources=[DataSource(), DataSource()], source_coordinates=source_coords) # select all selected = node.select_sources(source_coords) assert len(selected) == 2 assert selected[0] == node.sources[0] assert selected[1] == node.sources[1] # select first c = podpac.Coordinates( [podpac.clinspace(0, 1, 10), podpac.clinspace(0, 1, 11), 0], ["lat", "lon", "time"]) selected = node.select_sources(c) assert len(selected) == 1 assert selected[0] == node.sources[0] # select second c = podpac.Coordinates( [podpac.clinspace(0, 1, 10), podpac.clinspace(0, 1, 11), 10], ["lat", "lon", "time"]) selected = node.select_sources(c) assert len(selected) == 1 assert selected[0] == node.sources[1] # select none c = podpac.Coordinates( [podpac.clinspace(0, 1, 10), podpac.clinspace(0, 1, 11), 100], ["lat", "lon", "time"]) selected = node.select_sources(c) assert len(selected) == 0
def test_select_sources_default(self): node = BaseCompositor( sources=[DataSource(), DataSource(), podpac.algorithm.Arange()]) sources = node.select_sources(podpac.Coordinates([[0, 10]], ["time"])) assert isinstance(sources, list) assert len(sources) == 3
def test_set_native_coordinates(self): nc = Coordinates([clinspace(0, 50, 101), clinspace(0, 50, 101)], dims=['lat', 'lon']) node = DataSource(source='test', native_coordinates=nc) assert node.native_coordinates is not None with pytest.raises(tl.TraitError): DataSource(source='test', native_coordinates='not a coordinate') with pytest.raises(NotImplementedError): DataSource(source='test').native_coordinates
def test_interpolation_class(self): node = DataSource(source='test', interpolation='max') assert node.interpolation_class assert isinstance(node.interpolation_class, Interpolation) assert node.interpolation_class.definition == 'max' assert isinstance(node.interpolation_class.config, OrderedDict) assert ('default', ) in node.interpolation_class.config
def test_nomethods_must_be_implemented(self): node = DataSource() with pytest.raises(NotImplementedError): node.get_native_coordinates() with pytest.raises(NotImplementedError): node.get_data(None, None)
def test_coordinates(self): # not implemented node = DataSource() with pytest.raises(NotImplementedError): node.coordinates # make sure get_coordinates gets called only once class MyDataSource(DataSource): get_coordinates_called = 0 def get_coordinates(self): self.get_coordinates_called += 1 return Coordinates([]) node = MyDataSource() assert node.get_coordinates_called == 0 assert isinstance(node.coordinates, Coordinates) assert node.get_coordinates_called == 1 assert isinstance(node.coordinates, Coordinates) assert node.get_coordinates_called == 1 # can't set coordinates attribute with pytest.raises(AttributeError, match="can't set attribute"): node.coordinates = Coordinates([])
def test_base_definition(self): """Test definition property method""" # TODO: add interpolation definition testing node = DataSource(source='test') d = node.base_definition assert d assert 'node' in d assert 'source' in d assert 'interpolation' in d assert d['source'] == node.source class MyDataSource(DataSource): source = tl.Unicode().tag(attr=True) node = MyDataSource(source='test') with pytest.raises( NodeException, match="The 'source' property cannot be tagged as an 'attr'"): node.base_definition
def test_init(self): node = DataSource()
def test_get_coordinates_not_implemented(self): node = DataSource() with pytest.raises(NotImplementedError): node.get_coordinates()
def test_get_data_not_implemented(self): node = DataSource() with pytest.raises(NotImplementedError): node.get_data(None, None)
def test_repr(self): node = DataSource() repr(node)
def test_invalid_nan_vals(self): with pytest.raises(tl.TraitError): DataSource(nan_vals={}) with pytest.raises(tl.TraitError): DataSource(nan_vals=10)
def test_boundary(self): # default node = DataSource() assert node.boundary == {} # none node = DataSource(boundary={}) # centered node = DataSource(boundary={"lat": 0.25, "lon": 2.0}) node = DataSource(boundary={"time": "1,D"}) # box (not necessary centered) with pytest.raises(NotImplementedError, match="Non-centered boundary not yet supported"): node = DataSource(boundary={ "lat": [-0.2, 0.3], "lon": [-2.0, 2.0] }) with pytest.raises(NotImplementedError, match="Non-centered boundary not yet supported"): node = DataSource(boundary={"time": ["-1,D", "2,D"]}) # polygon with pytest.raises(NotImplementedError, match="Non-centered boundary not yet supported"): node = DataSource(boundary={ "lat": [0.0, -0.5, 0.0, 0.5], "lon": [-0.5, 0.0, 0.5, 0.0] }) # diamond # array of boundaries (one for each coordinate) with pytest.raises(NotImplementedError, match="Non-uniform boundary not yet supported"): node = DataSource(boundary={ "lat": [[-0.1, 0.4], [-0.2, 0.3], [-0.3, 0.2]], "lon": 0.5 }) with pytest.raises(NotImplementedError, match="Non-uniform boundary not yet supported"): node = DataSource( boundary={"time": [["-1,D", "1,D"], ["-2,D", "1,D"]]}) # invalid with pytest.raises(tl.TraitError): node = DataSource(boundary=0.5) with pytest.raises(ValueError, match="Invalid dimension"): node = DataSource(boundary={"other": 0.5}) with pytest.raises(TypeError, match="Invalid coordinate delta"): node = DataSource(boundary={"lat": {}}) with pytest.raises(ValueError, match="Invalid boundary"): node = DataSource(boundary={"lat": -0.25, "lon": 2.0}) # negative with pytest.raises(ValueError, match="Invalid boundary"): node = DataSource(boundary={"time": "-2,D"}) # negative with pytest.raises(ValueError, match="Invalid boundary"): node = DataSource(boundary={"time": "2018-01-01"}) # not a delta