예제 #1
0
def test_feature_artist_draw_styler(path_collection_cls, feature):
    geoms = list(feature.geometries())
    style1 = {'facecolor': 'blue', 'edgecolor': 'white'}
    style2 = {'color': 'black', 'linewidth': 1}
    style2_finalized = style.finalize(style.merge(style2))

    def styler(geom):
        if geom == geoms[0]:
            return style1
        else:
            return style2

    fa = FeatureArtist(feature, styler=styler, linewidth=2)
    extent = [-10, 10, -10, 10]
    prj_crs = ccrs.Robinson()
    fa.axes = mocked_axes(extent, projection=prj_crs)
    fa.draw(mock.sentinel.renderer)

    transform = prj_crs._as_mpl_transform(fa.axes)

    calls = [{'paths': (cached_paths(geoms[0], prj_crs), ),
              'style': dict(linewidth=2, **style1)},
             {'paths': (cached_paths(geoms[1], prj_crs), ),
              'style': style2_finalized}]

    assert path_collection_cls.call_count == 2
    for expected_call, (actual_args, actual_kwargs) in \
            zip(calls, path_collection_cls.call_args_list):
        assert expected_call['paths'] == actual_args
        assert transform == actual_kwargs.pop('transform')
        assert expected_call['style'] == actual_kwargs
예제 #2
0
def test_feature_artist_draw_styler(path_collection_cls, feature):
    geoms = list(feature.geometries())
    style1 = {'facecolor': 'blue', 'edgecolor': 'white'}
    style2 = {'color': 'black', 'linewidth': 1}
    style2_finalized = style.finalize(style.merge(style2))

    def styler(geom):
        if geom == geoms[0]:
            return style1
        else:
            return style2

    fa = FeatureArtist(feature, styler=styler, linewidth=2)
    extent = [-10, 10, -10, 10]
    prj_crs = ccrs.Robinson()
    fa.axes = mocked_axes(extent, projection=prj_crs)
    fa.draw(mock.sentinel.renderer)

    transform = prj_crs._as_mpl_transform(fa.axes)

    calls = [{'paths': (cached_paths(geoms[0], prj_crs), ),
              'style': dict(linewidth=2, **style1)},
             {'paths': (cached_paths(geoms[1], prj_crs), ),
              'style': style2_finalized}]

    assert path_collection_cls.call_count == 2
    for expected_call, (actual_args, actual_kwargs) in \
            zip(calls, path_collection_cls.call_args_list):
        assert expected_call['paths'] == actual_args
        assert transform == actual_kwargs.pop('transform')
        assert expected_call['style'] == actual_kwargs
예제 #3
0
def test_feature_artist_draw(path_collection_cls, feature):
    geoms = list(feature.geometries())

    fa = FeatureArtist(feature, facecolor='red')
    prj_crs = ccrs.Robinson()
    fa.axes = mocked_axes(extent=[-10, 10, -10, 10], projection=prj_crs)
    fa.draw(mock.sentinel.renderer)

    transform = prj_crs._as_mpl_transform(fa.axes)
    expected_paths = (cached_paths(geoms[0], prj_crs) +
                      cached_paths(geoms[1], prj_crs), )
    expected_style = {'facecolor': 'red'}

    args, kwargs = path_collection_cls.call_args_list[0]
    assert transform == kwargs.pop('transform', None)
    assert kwargs == expected_style
    assert args == expected_paths

    path_collection_cls().set_clip_path.assert_called_once_with(fa.axes.patch)
    path_collection_cls().set_figure.assert_called_once_with(fa.axes.figure)
    path_collection_cls().draw(mock.sentinel.renderer)
예제 #4
0
def test_feature_artist_draw(path_collection_cls, feature):
    geoms = list(feature.geometries())

    fa = FeatureArtist(feature, facecolor='red')
    prj_crs = ccrs.Robinson()
    fa.axes = mocked_axes(extent=[-10, 10, -10, 10], projection=prj_crs)
    fa.draw(mock.sentinel.renderer)

    transform = prj_crs._as_mpl_transform(fa.axes)
    expected_paths = (cached_paths(geoms[0], prj_crs) +
                      cached_paths(geoms[1], prj_crs), )
    expected_style = {'facecolor': 'red'}

    args, kwargs = path_collection_cls.call_args_list[0]
    assert transform == kwargs.pop('transform', None)
    assert kwargs == expected_style
    assert args == expected_paths

    path_collection_cls().set_clip_path.assert_called_once_with(fa.axes.patch)
    path_collection_cls().set_figure.assert_called_once_with(fa.axes.figure)
    path_collection_cls().draw(mock.sentinel.renderer)