|
71 | 71 |
|
72 | 72 | def _get_example_figures():
|
73 | 73 | """Create two example figures."""
|
74 |
| - fig1 = plt.plot([1, 2], [1, 2])[0].figure |
75 |
| - fig2 = plt.plot([3, 4], [3, 4])[0].figure |
| 74 | + fig1 = np.zeros((2, 2, 3)) |
| 75 | + fig2 = np.ones((2, 2, 3)) |
76 | 76 | return [fig1, fig2]
|
77 | 77 |
|
78 | 78 |
|
@@ -609,28 +609,33 @@ def test_remove():
|
609 | 609 | assert r2.html[2] == r.html[3]
|
610 | 610 |
|
611 | 611 |
|
612 |
| -def test_add_or_replace(): |
| 612 | +@pytest.mark.parametrize('tags', (True, False)) # shouldn't matter |
| 613 | +def test_add_or_replace(tags): |
613 | 614 | """Test replacing existing figures in a report."""
|
| 615 | + # Note that tags don't matter, only titles do! |
614 | 616 | r = Report()
|
615 | 617 | fig1, fig2 = _get_example_figures()
|
616 |
| - r.add_figure(fig=fig1, title='duplicate', tags=('foo',)) |
617 |
| - r.add_figure(fig=fig1, title='duplicate', tags=('foo',)) |
618 |
| - r.add_figure(fig=fig1, title='duplicate', tags=('bar',)) |
619 |
| - r.add_figure(fig=fig2, title='nonduplicate', tags=('foo',)) |
| 618 | + r.add_figure(fig=fig1, title='duplicate', tags=('foo',) if tags else ()) |
| 619 | + r.add_figure(fig=fig2, title='duplicate', tags=('foo',) if tags else ()) |
| 620 | + r.add_figure(fig=fig1, title='duplicate', tags=('bar',) if tags else ()) |
| 621 | + r.add_figure(fig=fig2, title='nonduplicate', tags=('foo',) if tags else ()) |
620 | 622 | # By default, replace=False, so all figures should be there
|
621 | 623 | assert len(r.html) == 4
|
| 624 | + assert len(r._content) == 4 |
622 | 625 |
|
623 | 626 | old_r = copy.deepcopy(r)
|
624 | 627 |
|
625 | 628 | # Replace last occurrence of `fig1` tagges as `foo`
|
626 | 629 | r.add_figure(
|
627 |
| - fig=fig2, title='duplicate', tags=('foo',), replace=True |
| 630 | + fig=fig2, title='duplicate', tags=('bar',) if tags else (), |
| 631 | + replace=True, |
628 | 632 | )
|
629 | 633 | assert len(r._content) == len(r.html) == 4
|
630 |
| - assert r.html[1] != old_r.html[1] # This figure should have changed |
| 634 | + # This figure should have changed |
| 635 | + assert r.html[2] != old_r.html[2] |
631 | 636 | # All other figures should be the same
|
632 | 637 | assert r.html[0] == old_r.html[0]
|
633 |
| - assert r.html[2] == old_r.html[2] |
| 638 | + assert r.html[1] == old_r.html[1] |
634 | 639 | assert r.html[3] == old_r.html[3]
|
635 | 640 |
|
636 | 641 |
|
|
0 commit comments