| 1 | """Test creation of all Label classes and decoders""" |
| 2 | import random |
| 3 | |
| 4 | import pytest |
| 5 | |
| 6 | |
| 7 | from pyglet.text import decode_text, decode_attributed, decode_html |
| 8 | from pyglet.text import Label, DocumentLabel, HTMLLabel |
| 9 | |
| 10 | WIDTH = 500 |
| 11 | HEIGHT = 100 |
| 12 | X = random.randint(0, 900) |
| 13 | Y = random.randint(0, 600) |
| 14 | Z = random.randint(-10, 10) |
| 15 | |
| 16 | |
| 17 | @pytest.mark.parametrize('label_class', [Label, HTMLLabel]) |
| 18 | def test_label_creation(label_class): |
| 19 | label = label_class("This is a test", x=X, y=Y, z=Z) |
| 20 | assert label.x == X |
| 21 | assert label.y == Y |
| 22 | assert label.z == Z |
| 23 | |
| 24 | |
| 25 | @pytest.fixture(params=[(decode_text, "This is a string of regular text."), |
| 26 | (decode_html, "<font color=green>This is html text.</font>"), |
| 27 | (decode_attributed, "This is {bold True}attributed{bold False} text.")]) |
| 28 | def document(request): |
| 29 | decoder, string = request.param |
| 30 | return decoder(string) |
| 31 | |
| 32 | |
| 33 | def test_documentlabel_creation(document): |
| 34 | label = DocumentLabel(document=document, x=X, y=Y, z=Z) |
| 35 | assert label.x == X |
| 36 | assert label.y == Y |
| 37 | assert label.z == Z |