def test_Plotter_auto_zoom(ex, tile_provider): tile_provider.tilesize = 256 plot = mapping.Plotter(ex, tile_provider, width=100) # Tile is 256 wide, needed width is 0.3, or 76.8 # Each zoom level doubles that assert plot.zoom == 1 plot = mapping.Plotter(ex, tile_provider, width=1000) assert plot.zoom == 4 plot = mapping.Plotter(ex, tile_provider, width=76) assert plot.zoom == 0 plot = mapping.Plotter(ex, tile_provider, width=77) assert plot.zoom == 1 tile_provider.tilesize = 512 plot = mapping.Plotter(ex, tile_provider, width=1000) assert plot.zoom == 3 plot = mapping.Plotter(ex, tile_provider, width=5033164) assert plot.zoom == 15 plot = mapping.Plotter(ex, tile_provider, width=5033165) assert plot.zoom == 16 plot = mapping.Plotter(ex, tile_provider, height=1000) assert plot.zoom == 5 plot = mapping.Plotter(ex, tile_provider, width=1000, height=1000) assert plot.zoom == 5
def test_Plotter_as_one_image_1x1(ex, tile_provider, new_image): plot = mapping.Plotter(ex, tile_provider, width=50) image = plot.as_one_image() assert new_image.called_with("RGB", (256, 256)) assert image == new_image.return_value assert tile_provider.get_tile.call_args_list == [mock.call(0, 0, 0)] tile = tile_provider.get_tile.return_value image.paste.assert_called_with(tile, (0, 0))
def test_Plotter_constructs(ex, tile_provider): with pytest.raises(ValueError): mapping.Plotter(ex, tile_provider) with pytest.raises(ValueError): mapping.Plotter(ex, tile_provider, zoom=2, width=100) with pytest.raises(ValueError): mapping.Plotter(ex, tile_provider, zoom=2, height=100) plot = mapping.Plotter(ex, tile_provider, zoom=10) assert plot.zoom == 10 assert plot.extent is ex assert plot.extent_in_web_mercator.xrange == ex.xrange assert plot.extent_in_web_mercator.yrange == ex.yrange assert plot.xtilemin == int(1024 * 0.2) assert plot.xtilemax == int(1024 * 0.5) assert plot.ytilemin == int(1024 * 0.3) assert plot.ytilemax == int(1024 * 0.4)
def test_Plotter_plotlq_1x1(ex, tile_provider): plot = mapping.Plotter(ex, tile_provider, width=50) ax = mock.Mock() plot.plotlq(ax) assert tile_provider.get_tile.call_args_list == [mock.call(0, 0, 0)] tile, extent = imshow_calls_to_list(ax)[0] assert tile == tile_provider.get_tile.return_value assert extent == pytest.approx((0, 1, 1, 0)) ax.set.assert_called_with(xlim=(0.2, 0.5), ylim=(0.4, 0.3))
def test_Plotter_plot_2x2(ex, tile_provider, new_image): plot = mapping.Plotter(ex, tile_provider, width=100) ax = mock.Mock() plot.plot(ax) image = new_image.return_value imshow = imshow_calls_to_list(ax) assert len(imshow) == 1 tile, extent = imshow[0] assert tile == image assert extent == pytest.approx((0, 1, 0.5, 0)) ax.set.assert_called_with(xlim=(0.2, 0.5), ylim=(0.4, 0.3))
def test_Plotter_plot_epsg(ex, tile_provider, new_image): ex = ex.to_project_3857() plot = mapping.Plotter(ex, tile_provider, width=100) ax = mock.Mock() plot.plot(ax) image = new_image.return_value imshow = imshow_calls_to_list(ax) assert len(imshow) == 1 tile, extent = imshow[0] assert tile == image x, y = mapping._to_3857(0, 0) xx, yy = mapping._to_3857(1, 0.5) assert extent == pytest.approx((x, xx, yy, y)) kwargs = ax.set.call_args_list[0][1] x, y = mapping._to_3857(0.2, 0.3) xx, yy = mapping._to_3857(0.5, 0.4) kwargs["xlim"] == pytest.approx((x, xx)) kwargs["ylim"] == pytest.approx((yy, y))
def test_Plotter_too_many_tiles(ex, tile_provider): plot = mapping.Plotter(ex, tile_provider, width=10000) with pytest.raises(ValueError): plot.plot(mock.Mock())