Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_empty_input_files(example_mapchete):
"""Assert empty input files raises error."""
with pytest.raises(errors.MapcheteConfigError):
config = deepcopy(example_mapchete.dict)
del config["input"]
MapcheteConfig(config)
for param in ["process", "input", "output"]:
with pytest.raises(errors.MapcheteConfigError):
config = deepcopy(example_mapchete.dict)
del config[param]
MapcheteConfig(config)
# invalid path
with pytest.raises(errors.MapcheteConfigError):
config = deepcopy(example_mapchete.dict)
config.update(process="invalid/path.py")
MapcheteConfig(config).process
# no config dir given
with pytest.raises(errors.MapcheteConfigError):
config = deepcopy(example_mapchete.dict)
config.pop("config_dir")
MapcheteConfig(config).process
def test_config_zoom11(example_mapchete, dummy2_tif, dummy1_tif):
"""Example configuration at zoom 11."""
config = MapcheteConfig(example_mapchete.path)
zoom11 = config.params_at_zoom(11)
input_files = zoom11["input"]
assert input_files["file1"].path == dummy1_tif
assert input_files["file2"].path == dummy2_tif
assert zoom11["some_integer_parameter"] == 12
assert zoom11["some_float_parameter"] == 5.3
assert zoom11["some_string_parameter"] == "string2"
assert zoom11["some_bool_parameter"] is True
def test_mandatory_params(example_mapchete):
"""Check availability of mandatory parameters."""
for param in ["process", "input", "output"]:
with pytest.raises(errors.MapcheteConfigError):
config = deepcopy(example_mapchete.dict)
del config[param]
MapcheteConfig(config)
# invalid path
with pytest.raises(errors.MapcheteConfigError):
config = deepcopy(example_mapchete.dict)
config.update(process="invalid/path.py")
MapcheteConfig(config).process
# no config dir given
with pytest.raises(errors.MapcheteConfigError):
config = deepcopy(example_mapchete.dict)
config.pop("config_dir")
MapcheteConfig(config).process
def test_config_zoom7(example_mapchete, dummy2_tif):
"""Example configuration at zoom 5."""
config = MapcheteConfig(example_mapchete.path)
zoom7 = config.params_at_zoom(7)
input_files = zoom7["input"]
assert input_files["file1"] is None
assert input_files["file2"].path == dummy2_tif
assert zoom7["some_integer_parameter"] == 12
assert zoom7["some_float_parameter"] == 5.3
assert zoom7["some_string_parameter"] == "string1"
assert zoom7["some_bool_parameter"] is True
print "FAILED: read zoom level from config file"
print mapchete_file
raise
## read min/max zoom levels from config file
mapchete_file = os.path.join(scriptdir, "testdata/minmax_zoom.mapchete")
config = Mapchete(MapcheteConfig(mapchete_file)).config
try:
for zoom in [7, 8, 9, 10]:
assert zoom in config.zoom_levels
print "OK: read min/max zoom levels from config file"
except:
print "FAILED: read min/max zoom levels from config file"
raise
## zoom levels override
mapchete_file = os.path.join(scriptdir, "testdata/minmax_zoom.mapchete")
config = Mapchete(MapcheteConfig(mapchete_file, zoom=[1, 4])).config
try:
for zoom in [1, 2, 3, 4]:
assert zoom in config.zoom_levels
print "OK: zoom levels override"
except:
print "FAILED: zoom levels override"
raise
## read bounds from config file
mapchete_file = os.path.join(scriptdir, "testdata/zoom.mapchete")
config = Mapchete(MapcheteConfig(mapchete_file)).config
try:
test_polygon = Polygon([
[3, 1.5], [3, 2], [3.5, 2], [3.5, 1.5], [3, 1.5]
])
assert config.process_area(5).equals(test_polygon)
print "OK: read bounds from config file"
def test_read_input_groups(file_groups):
"""Read input data groups."""
config = MapcheteConfig(file_groups.path)
input_files = config.params_at_zoom(0)["input"]
assert "file1" in input_files["group1"]
assert "file2" in input_files["group1"]
assert "file1" in input_files["group2"]
assert "file2" in input_files["group2"]
assert "nested_group" in input_files
assert "group1" in input_files["nested_group"]
assert "file1" in input_files["nested_group"]["group1"]
assert "file2" in input_files["nested_group"]["group1"]
assert "file1" in input_files["nested_group"]["group2"]
assert "file2" in input_files["nested_group"]["group2"]
assert config.area_at_zoom()
def test_wrong_bounds(example_mapchete):
"""Wrong bounds number raises error."""
with pytest.raises(errors.MapcheteConfigError):
MapcheteConfig(example_mapchete.dict, bounds=[2, 3])
with pytest.raises(errors.MapcheteConfigError):
MapcheteConfig(dict(example_mapchete.dict, process_bounds=[2, 3]))
def test_effective_bounds(files_bounds, baselevels):
config = MapcheteConfig(files_bounds.dict)
assert config.effective_bounds == snap_bounds(
bounds=config.bounds, pyramid=config.process_pyramid, zoom=min(config.zoom_levels)
)
config = MapcheteConfig(
baselevels.dict, zoom=[5, 7], bounds=(0, 1, 2, 3)
)
assert config.effective_bounds != config.init_bounds
assert config.effective_bounds == snap_bounds(
bounds=config.init_bounds, pyramid=config.process_pyramid, zoom=5
)
with pytest.raises(MapcheteConfigError):
MapcheteConfig(dict(
baselevels.dict,
zoom_levels=dict(min=7, max=7),
baselevels=dict(lower="cubic", max=7)
))
def test_no_cli_input_file(example_mapchete):
"""Assert input file from command line is checked."""
with pytest.raises(errors.MapcheteConfigError):
config = deepcopy(example_mapchete.dict)
config.update(input="from_command_line")
MapcheteConfig(config)