示例#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_merge(styles, expected):
    merged_style = style.merge(*styles)
    assert merged_style == expected
示例#4
0
def test_merge_warning(case, should_warn):
    warn_type = UserWarning if should_warn else None
    with pytest.warns(warn_type, match=r'defined as \"never\"') as record:
        style.merge({'facecolor': 'never'}, case)
    assert len(record) == (1 if should_warn else 0)
示例#5
0
def test_merge(styles, expected):
    merged_style = style.merge(*styles)
    assert merged_style == expected