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

Code before:
               for tick in ax.xaxis.majorTicks)
    assert all(tick.gridline.get_visible() == minor_visible
               for tick in ax.xaxis.minorTicks)


def test_grid():
    fig, ax = plt.subplots()
    ax.grid()
    fig.canvas.draw()
    assert ax.xaxis.majorTicks[0].gridline.get_visible()
    ax.grid(visible=False)
    fig.canvas.draw()
    assert not ax.xaxis.majorTicks[0].gridline.get_visible()
    ax.grid(visible=True)
    fig.canvas.draw()
    assert ax.xaxis.majorTicks[0].gridline.get_visible()
    ax.grid()
    fig.canvas.draw()
    assert not ax.xaxis.majorTicks[0].gridline.get_visible()


def test_grid_color_with_alpha():
    """Test that grid(color=(..., alpha)) respects the alpha value."""
    fig, ax = plt.subplots()
    ax.plot([0, 1], [0, 1])
    
    # Test 1: Color tuple with alpha
    ax.grid(True, color=(0.5, 0.6, 0.7, 0.3))
    fig.canvas.draw()
    
    # Check that alpha is extracted from color tuple
    for tick in ax.xaxis.get_major_ticks():
        assert tick.gridline.get_alpha() == 0.3, \
            f"Expected alpha=0.3, got {tick.gridline.get_alpha()}"
        # Color should be RGB only, without alpha component
        color = tick.gridline.get_color()
        assert len(color) in (3, 4), f"Unexpected color format: {color}"
        
    for tick in ax.yaxis.get_major_ticks():
        assert tick.gridline.get_alpha() == 0.3, \
            f"Expected alpha=0.3, got {tick.gridline.get_alpha()}"


def test_reset_grid():
    fig, ax = plt.subplots()
    ax.tick_params(reset=True, which='major', labelsize=10)
    assert not ax.xaxis.majorTicks[0].gridline.get_visible()
    ax.grid(color='red')  # enables grid
    assert ax.xaxis.majorTicks[0].gridline.get_visible()

    with plt.rc_context({'axes.grid': True}):

Review comment (suggestion):
You don't need to plot someting an empty Axes is sufficient.
```suggestion

```

Code after:
               for tick in ax.xaxis.majorTicks)
    assert all(tick.gridline.get_visible() == minor_visible
               for tick in ax.xaxis.minorTicks)


def test_grid():
    fig, ax = plt.subplots()
    ax.grid()
    fig.canvas.draw()
    assert ax.xaxis.majorTicks[0].gridline.get_visible()
    ax.grid(visible=False)
    fig.canvas.draw()
    assert not ax.xaxis.majorTicks[0].gridline.get_visible()
    ax.grid(visible=True)
    fig.canvas.draw()
    assert ax.xaxis.majorTicks[0].gridline.get_visible()
    ax.grid()
    fig.canvas.draw()
    assert not ax.xaxis.majorTicks[0].gridline.get_visible()


def test_grid_color_with_alpha():
    """Test that grid(color=(..., alpha)) respects the alpha value."""
    fig, ax = plt.subplots()
    ax.grid(True, color=(0.5, 0.6, 0.7, 0.3))

    # Check that alpha is extracted from color tuple
    for tick in ax.xaxis.get_major_ticks():
        assert tick.gridline.get_alpha() == 0.3, \
            f"Expected alpha=0.3, got {tick.gridline.get_alpha()}"

    for tick in ax.yaxis.get_major_ticks():
        assert tick.gridline.get_alpha() == 0.3, \
            f"Expected alpha=0.3, got {tick.gridline.get_alpha()}"


def test_reset_grid():
    fig, ax = plt.subplots()
    ax.tick_params(reset=True, which='major', labelsize=10)
    assert not ax.xaxis.majorTicks[0].gridline.get_visible()
    ax.grid(color='red')  # enables grid
    assert ax.xaxis.majorTicks[0].gridline.get_visible()

    with plt.rc_context({'axes.grid': True}):
        ax.clear()
        ax.tick_params(reset=True, which='major', labelsize=10)
        assert ax.xaxis.majorTicks[0].gridline.get_visible()


@check_figures_equal()
def test_reset_ticks(fig_test, fig_ref):