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

Code before:
    with pytest.warns(UserWarning, match="Ignoring specified arguments in this call"):
        fig2 = plt.figure(1, figsize=np.array([3, 4]))
    with pytest.warns(UserWarning, match="Ignoring specified arguments in this call"):
        plt.figure(fig, figsize=np.array([5, 6]))
    assert fig is fig2
    fig3 = plt.figure(1)  # Checks for false warnings
    assert fig is fig3


def test_close_all_warning():
    fig1 = plt.figure()

    # Check that the warning is issued when 'all' is passed to plt.figure
    with pytest.warns(UserWarning, match="closes all existing figures"):
        fig2 = plt.figure("all")


def test_matshow():
    fig = plt.figure()
    arr = [[0, 1], [1, 2]]

    # Smoke test that matshow does not ask for a new figsize on the existing figure
    plt.matshow(arr, fignum=fig.number)


def assert_same_signature(meth, original_meth):
    """
    Assert that the arguments of plt_meth and original_meth have the same names.

    :param meth: The method to check.
    :param original_meth: The original method to compare against.
    """
    params = inspect.signature(meth).parameters
    original_params = inspect.signature(original_meth).parameters

    assert len(params) == len(original_params)
    assert all([
        params[p].name == original_params[p].name and
        params[p].kind == original_params[p].kind
        for p in params
    ])


def test_setloglevel_signature():
    assert_same_signature(plt.set_loglevel, mpl.set_loglevel)


Review comment (suggestion):
I’d go with 
```suggestion
def assert_same_signature(func1, func2):
```
(Also adapt the docstring)


There’s nothing special for methods in here, and in fact, the case of set_loglevel are both functions.

Code after:
    with pytest.warns(UserWarning, match="Ignoring specified arguments in this call"):
        fig2 = plt.figure(1, figsize=np.array([3, 4]))
    with pytest.warns(UserWarning, match="Ignoring specified arguments in this call"):
        plt.figure(fig, figsize=np.array([5, 6]))
    assert fig is fig2
    fig3 = plt.figure(1)  # Checks for false warnings
    assert fig is fig3


def test_close_all_warning():
    fig1 = plt.figure()

    # Check that the warning is issued when 'all' is passed to plt.figure
    with pytest.warns(UserWarning, match="closes all existing figures"):
        fig2 = plt.figure("all")


def test_matshow():
    fig = plt.figure()
    arr = [[0, 1], [1, 2]]

    # Smoke test that matshow does not ask for a new figsize on the existing figure
    plt.matshow(arr, fignum=fig.number)


def assert_same_signature(func1, func2):
    """
    Assert that `func1` and `func2` have the same arguments,
    i.e. same parameter count, names and kinds.

    :param func1: First function to check
    :param func2: Second function to check
    """
    params1 = inspect.signature(func1).parameters
    params2 = inspect.signature(func2).parameters

    assert len(params1) == len(params2)
    assert all([
        params1[p].name == params2[p].name and
        params1[p].kind == params2[p].kind
        for p in params1
    ])


def test_setloglevel_signature():
    assert_same_signature(plt.set_loglevel, mpl.set_loglevel)