def test_Extent_mutations(): # 1000 x 5000 ex = ons.Extent(1000, 2000, 4000, 9000) ex1 = ex.with_centre(10000, 20000) assert ex1.xrange == (10000 - 500, 10000 + 500) assert ex1.yrange == (20000 - 2500, 20000 + 2500) ex2 = ex.with_centre_lonlat(-3.02516, 58.64389) assert ex2.xrange == pytest.approx((340094.489913, 341094.489913)) assert ex2.yrange == pytest.approx( (973345.118179 - 2500, 973345.118179 + 2500)) ex3 = ex.to_aspect(2.0) assert ex3.xrange == (1000, 2000) assert ex3.yrange == (6500 - 250, 6500 + 250) ex3 = ex.to_aspect(0.5) assert ex3.xrange == (1000, 2000) assert ex3.yrange == (6500 - 1000, 6500 + 1000) ex3 = ex.to_aspect(0.1) assert ex3.xrange == (1250, 1750) assert ex3.yrange == (4000, 9000) ex4 = ex.with_absolute_translation(100, 200) assert ex4.xrange == (1100, 2100) assert ex4.yrange == (4200, 9200) ex5 = ex.with_translation(0.5, 1) assert ex5.xrange == (1500, 2500) assert ex5.yrange == (9000, 14000) ex6 = ex.with_scaling(0.5) assert ex6.xrange == (1500 - 1000, 2500) assert ex6.yrange == (6500 - 5000, 6500 + 5000)
def test_Plotter_plot(source, image_mock): ex = ons.Extent(1100, 1900, 4200, 5500) plotter = ons.Plotter(ex, source) ax = mock.Mock() plotter.plot(ax, bob="fish") assert source.call_args_list == [ mock.call("SV 1000 4000"), mock.call("SV 1000 5000") ] assert ax.imshow.call_args_list == [ mock.call(image_mock.new.return_value, interpolation="lanczos", extent=(1000, 2000, 4000, 6000), bob="fish"), ]
def test_Plotter_ignore_errors(source, image_mock): source.side_effect = Exception ex = ons.Extent(1100, 1900, 4200, 5500) plotter = ons.Plotter(ex, source) ax = mock.Mock() plotter.plotlq(ax, bob="fish") assert ax.imshow.call_args_list == [ mock.call(source.blank.return_value, interpolation="lanczos", extent=(1000, 2000, 4000, 5000), bob="fish"), mock.call(source.blank.return_value, interpolation="lanczos", extent=(1000, 2000, 5000, 6000), bob="fish") ]
def test_Plotter_as_one_image(source, image_mock): ex = ons.Extent(1100, 1900, 4200, 5500) plotter = ons.Plotter(ex, source) ax = mock.Mock() out = plotter.as_one_image() assert source.call_args_list == [ mock.call("SV 1000 4000"), mock.call("SV 1000 5000") ] image_mock.new.assert_called_with("RGB", (2000, 4000)) im = image_mock.new.return_value assert out is im assert im.paste.call_args_list == [ mock.call(source.return_value, (0, 2000)), mock.call(source.return_value, (0, 0)) ]