MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / test_4254

Function test_4254

tests/test_annots.py:522–562  ·  view source on GitHub ↗

Ensure that both annotations are fully created We do this by asserting equal top-used colors in respective pixmaps.

()

Source from the content-addressed store, hash-verified

520 assert rms == 0
521
522def test_4254():
523 """Ensure that both annotations are fully created
524
525 We do this by asserting equal top-used colors in respective pixmaps.
526 """
527 doc = pymupdf.open()
528 page = doc.new_page()
529
530 rect = pymupdf.Rect(100, 100, 200, 150)
531 annot = page.add_freetext_annot(rect, "Test Annotation from minimal example")
532 annot.set_border(width=1, dashes=(3, 3))
533 annot.set_opacity(0.5)
534 try:
535 annot.set_colors(stroke=(1, 0, 0))
536 except ValueError as e:
537 assert 'cannot be used for FreeText annotations' in str(e), f'{e}'
538 else:
539 assert 0
540 annot.update()
541
542 rect = pymupdf.Rect(200, 200, 400, 400)
543 annot2 = page.add_freetext_annot(rect, "Test Annotation from minimal example pt 2")
544 annot2.set_border(width=1, dashes=(3, 3))
545 annot2.set_opacity(0.5)
546 try:
547 annot2.set_colors(stroke=(1, 0, 0))
548 except ValueError as e:
549 assert 'cannot be used for FreeText annotations' in str(e), f'{e}'
550 else:
551 assert 0
552 annot.update()
553 annot2.update()
554
555 # stores top color for each pixmap
556 top_colors = set()
557 for annot in page.annots():
558 pix = annot.get_pixmap()
559 top_colors.add(pix.color_topusage()[1])
560
561 # only one color must exist
562 assert len(top_colors) == 1
563
564def test_richtext():
565 """Test creation of rich text FreeText annotations.

Callers

nothing calls this directly

Calls 10

new_pageMethod · 0.80
add_freetext_annotMethod · 0.80
annotsMethod · 0.80
color_topusageMethod · 0.80
set_borderMethod · 0.45
set_opacityMethod · 0.45
set_colorsMethod · 0.45
updateMethod · 0.45
get_pixmapMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…