Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 825197a

Browse files
committed
TST: put collage tests under a class
1 parent b0b4709 commit 825197a

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

lib/matplotlib/tests/test_figure.py

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -501,64 +501,65 @@ def test_removed_axis():
501501
axs[0].remove()
502502
fig.canvas.draw()
503503

504-
@check_figures_equal()
505-
@pytest.mark.parametrize('x', [
506-
[["A", "A", "B"], ["C", "D", "B"]],
507-
[[1, 1, 2], [3, 4, 2]]]
508-
)
509-
def test_collage_basic(fig_test, fig_ref, x):
510-
grid_axes = fig_test.build_grid(x)
511504

512-
for k, ax in grid_axes.items():
513-
ax.set_title(k)
505+
class TestCollage:
506+
@check_figures_equal()
507+
@pytest.mark.parametrize('x', [
508+
[["A", "A", "B"], ["C", "D", "B"]],
509+
[[1, 1, 2], [3, 4, 2]]]
510+
)
511+
def test_basic(self, fig_test, fig_ref, x):
512+
grid_axes = fig_test.build_grid(x)
514513

515-
labels = sorted(np.unique(x))
514+
for k, ax in grid_axes.items():
515+
ax.set_title(k)
516516

517-
assert len(labels) == len(grid_axes)
517+
labels = sorted(np.unique(x))
518518

519-
gs = fig_ref.add_gridspec(2, 3)
520-
axA = fig_ref.add_subplot(gs[:1, :2])
521-
axA.set_title(labels[0])
519+
assert len(labels) == len(grid_axes)
522520

523-
axB = fig_ref.add_subplot(gs[:, 2])
524-
axB.set_title(labels[1])
521+
gs = fig_ref.add_gridspec(2, 3)
522+
axA = fig_ref.add_subplot(gs[:1, :2])
523+
axA.set_title(labels[0])
525524

526-
axC = fig_ref.add_subplot(gs[1, 0])
527-
axC.set_title(labels[2])
525+
axB = fig_ref.add_subplot(gs[:, 2])
526+
axB.set_title(labels[1])
528527

529-
axD = fig_ref.add_subplot(gs[1, 1])
530-
axD.set_title(labels[3])
528+
axC = fig_ref.add_subplot(gs[1, 0])
529+
axC.set_title(labels[2])
531530

531+
axD = fig_ref.add_subplot(gs[1, 1])
532+
axD.set_title(labels[3])
532533

533-
@check_figures_equal(tol=0.005)
534-
def test_collage_nested(fig_test, fig_ref):
535-
x = [["A", "B", "B"], ["C", "C", "D"]]
534+
@check_figures_equal(tol=0.005)
535+
def test_nested(self, fig_test, fig_ref):
536+
x = [["A", "B", "B"], ["C", "C", "D"]]
536537

537-
y = [["F"], [x]]
538+
y = [["F"], [x]]
538539

539-
grid_axes = fig_test.build_grid(y)
540+
grid_axes = fig_test.build_grid(y)
540541

541-
for k, ax in grid_axes.items():
542-
ax.set_title(k)
542+
for k, ax in grid_axes.items():
543+
ax.set_title(k)
543544

544-
gs = fig_ref.add_gridspec(2, 1)
545+
gs = fig_ref.add_gridspec(2, 1)
545546

546-
gs_n = gs[1, 0].subgridspec(2, 3)
547+
gs_n = gs[1, 0].subgridspec(2, 3)
547548

548-
axA = fig_ref.add_subplot(gs_n[0, 0])
549-
axA.set_title("A")
549+
axA = fig_ref.add_subplot(gs_n[0, 0])
550+
axA.set_title("A")
550551

551-
axB = fig_ref.add_subplot(gs_n[0, 1:])
552-
axB.set_title("B")
552+
axB = fig_ref.add_subplot(gs_n[0, 1:])
553+
axB.set_title("B")
553554

554-
axC = fig_ref.add_subplot(gs_n[1, :2])
555-
axC.set_title("C")
555+
axC = fig_ref.add_subplot(gs_n[1, :2])
556+
axC.set_title("C")
556557

557-
axD = fig_ref.add_subplot(gs_n[1, 2])
558-
axD.set_title("D")
558+
axD = fig_ref.add_subplot(gs_n[1, 2])
559+
axD.set_title("D")
559560

560-
axF = fig_ref.add_subplot(gs[0, 0])
561-
axF.set_title("F")
561+
axF = fig_ref.add_subplot(gs[0, 0])
562+
axF.set_title("F")
562563

563-
fig_test.tight_layout()
564-
fig_ref.tight_layout()
564+
fig_test.tight_layout()
565+
fig_ref.tight_layout()

0 commit comments

Comments
 (0)