Skip to content

Commit 519bac2

Browse files
committed
test(inset): footer inset placement and degenerate case
1 parent 4aa5c56 commit 519bac2

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tests/test_inset_element.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from plotnine._utils.yippie import geom as g
1414
from plotnine._utils.yippie import plot
1515
from plotnine.composition import inset_element, plot_annotation
16+
from plotnine.exceptions import PlotnineWarning
1617

1718

1819
def _smiley() -> np.ndarray:
@@ -374,3 +375,39 @@ def test_inset_on_facet_host():
374375
+ inset_element(plot.tomato, 0, 0, 0.25, 0.25)
375376
)
376377
assert p == "inset_on_facet_host"
378+
379+
380+
class TestFooterInset:
381+
"""
382+
align_to="footer" maps the inset bbox onto the footer band
383+
"""
384+
385+
def test_footer_logo_right_aligned(self):
386+
# A logo placed in the right portion of the footer band, inline
387+
# with left-justified footer text.
388+
p = (
389+
plot.white
390+
+ g.points
391+
+ labs(footer="Source: Example Corp")
392+
+ inset_element(
393+
SMILEY_FACE,
394+
left=0.9,
395+
bottom=0.0,
396+
right=1.0,
397+
top=1.0,
398+
align_to="footer",
399+
)
400+
)
401+
assert p == "footer_logo_right_aligned"
402+
403+
def test_footer_inset_without_footer_text(self):
404+
# No footer text -> degenerate footer band. The inset is skipped
405+
# and a warning is emitted; the rendered plot is just the host.
406+
# The == comparison draws the plot, which triggers the warning.
407+
p = (
408+
plot.white
409+
+ g.points
410+
+ inset_element(SMILEY_FACE, 0.9, 0.0, 1.0, 1.0, align_to="footer")
411+
)
412+
with pytest.warns(PlotnineWarning, match="no footer text"):
413+
assert p == "footer_inset_no_footer_text"

0 commit comments

Comments
 (0)