Repository: matplotlib/matplotlib
File: lib/matplotlib/tests/test_cbook.py (Python)

Code before:
    assert cbook._resize_sequence(a_list, 3) is a_list
    assert cbook._resize_sequence(arr, 3) is arr

    # shortening
    assert cbook._resize_sequence(a_list, 2) == [1, 2]
    assert_array_equal(cbook._resize_sequence(arr, 2), [1, 2])

    # extending
    assert cbook._resize_sequence(a_list, 5) == [1, 2, 3, 1, 2]
    assert_array_equal(cbook._resize_sequence(arr, 5), [1, 2, 3, 1, 2])


fail_mapping: tuple[tuple[dict, type], ...] = (
    (
        {"a": 1, "b": 2},
        _api.define_aliases({"a": ["b"]})(
            type("Type", (mpl.artist.Artist,), {"get_a": lambda self: None})),
    ),
    (
        {"a": 1, "b": 2},
        _api.define_aliases({"a": ["a", "b"]})(
            type("Type", (mpl.artist.Artist,), {"get_a": lambda self: None})),
    ),
)

pass_mapping: tuple[tuple[Any, dict, tuple], ...] = (
    (
        None, {},
        _api.define_aliases({})(
            type("Type", (mpl.artist.Artist,), {"get_a": lambda self: None})),
    ),
    (
        {"a": 1, "b": 2}, {"a": 1, "b": 2},
        _api.define_aliases({})(
            type("Type", (mpl.artist.Artist,), {"get_a": lambda self: None})),
    ),
    (
        {"b": 2}, {"a": 2},
        _api.define_aliases({"a": ["a", "b"]})(
            type("Type", (mpl.artist.Artist,), {"get_a": lambda self: None})),
    ),
)


@pytest.mark.parametrize('inp, cls', fail_mapping)
def test_normalize_kwargs_fail(inp, cls):
    with pytest.raises(TypeError):
        cbook.normalize_kwargs(inp, cls)


@pytest.mark.parametrize('inp, expected, cls', pass_mapping)

Review comment (suggestion):
```suggestion
pass_mapping: tuple[tuple[Any, dict, type], ...] = (
```
Unless the type definition goes inside the test (as suggested above)

Code after:
    assert cbook._resize_sequence(a_list, 3) is a_list
    assert cbook._resize_sequence(arr, 3) is arr

    # shortening
    assert cbook._resize_sequence(a_list, 2) == [1, 2]
    assert_array_equal(cbook._resize_sequence(arr, 2), [1, 2])

    # extending
    assert cbook._resize_sequence(a_list, 5) == [1, 2, 3, 1, 2]
    assert_array_equal(cbook._resize_sequence(arr, 5), [1, 2, 3, 1, 2])


fail_mapping: list[tuple[dict, dict]] = [
    ({"a": 1, "b": 2}, {"a": ["b"]}),
    ({"a": 1, "b": 2}, {"a": ["a", "b"]}),
]

pass_mapping: list[tuple[Any, dict, dict]] = [
    (None, {}, {}),
    ({"a": 1, "b": 2}, {"a": 1, "b": 2}, {}),
    ({"b": 2}, {"a": 2}, {"a": ["a", "b"]}),
]


@pytest.mark.parametrize('inp, alias_def', fail_mapping)
def test_normalize_kwargs_fail(inp, alias_def):

    @_api.define_aliases(alias_def)
    class Type(mpl.artist.Artist):
        def get_a(self): return None

    with pytest.raises(TypeError):
        cbook.normalize_kwargs(inp, Type)


@pytest.mark.parametrize('inp, expected, alias_def', pass_mapping)
def test_normalize_kwargs_pass(inp, expected, alias_def):

    @_api.define_aliases(alias_def)
    class Type(mpl.artist.Artist):
        def get_a(self): return None

    assert expected == cbook.normalize_kwargs(inp, Type)
    old_alias_map = {}
    for alias, prop in Type._alias_to_prop.items():
        old_alias_map.setdefault(prop, []).append(alias)
    with pytest.warns(mpl.MatplotlibDeprecationWarning):
        assert expected == cbook.normalize_kwargs(inp, old_alias_map)


def test_warn_external(recwarn):