-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb1b654
commit ea87564
Showing
6 changed files
with
97 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Test creation of all Label classes and decoders""" | ||
import random | ||
|
||
import pytest | ||
|
||
|
||
from pyglet.text import decode_text, decode_attributed, decode_html | ||
from pyglet.text import Label, DocumentLabel, HTMLLabel | ||
|
||
WIDTH = 500 | ||
HEIGHT = 100 | ||
X = random.randint(0, 900) | ||
Y = random.randint(0, 600) | ||
Z = random.randint(-10, 10) | ||
|
||
|
||
@pytest.mark.parametrize('label_class', [Label, HTMLLabel]) | ||
def test_label_creation(label_class): | ||
label = label_class("This is a test", x=X, y=Y, z=Z) | ||
assert label.x == X | ||
assert label.y == Y | ||
assert label.z == Z | ||
|
||
|
||
@pytest.fixture(params=[(decode_text, "This is a string of regular text."), | ||
(decode_html, "<font color=green>This is html text.</font>"), | ||
(decode_attributed, "This is {bold True}attributed{bold False} text.")]) | ||
def document(request): | ||
decoder, string = request.param | ||
return decoder(string) | ||
|
||
|
||
def test_documentlabel_creation(document): | ||
label = DocumentLabel(document=document, x=X, y=Y, z=Z) | ||
assert label.x == X | ||
assert label.y == Y | ||
assert label.z == Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Test creation of all Layout classes""" | ||
import random | ||
import itertools | ||
|
||
|
||
import pytest | ||
|
||
from pyglet.text import document | ||
from pyglet.text import layout | ||
|
||
WIDTH = 500 | ||
HEIGHT = 100 | ||
X = random.randint(0, 900) | ||
Y = random.randint(0, 600) | ||
Z = random.randint(-10, 10) | ||
|
||
|
||
# Create combination of all Layout and Document types | ||
document_classes = [document.UnformattedDocument, document.FormattedDocument] | ||
layout_classes = [layout.TextLayout, layout.ScrollableTextLayout, layout.IncrementalTextLayout] | ||
all_combinations = list(itertools.product(document_classes, layout_classes)) | ||
|
||
|
||
@pytest.mark.parametrize('doctype, layouttype', all_combinations) | ||
def test_layout_creation_keyword(doctype, layouttype): | ||
_doc = doctype("This is a test") | ||
_layout = layouttype(document=_doc, width=WIDTH, height=HEIGHT, x=X, y=Y, z=Z) | ||
assert _layout.width == WIDTH | ||
assert _layout.height == HEIGHT | ||
assert _layout.x == X | ||
assert _layout.y == Y | ||
assert _layout.z == Z | ||
assert _layout.position == (X, Y, Z) | ||
|
||
|
||
@pytest.mark.parametrize('doctype, layouttype', all_combinations) | ||
def test_layout_creation_positional(doctype, layouttype): | ||
_doc = doctype("This is a test") | ||
_layout = layouttype(_doc, WIDTH, HEIGHT, X, Y, Z) | ||
# Make sure the arguments were in order: | ||
assert _layout.width == WIDTH | ||
assert _layout.height == HEIGHT | ||
assert _layout.x == X | ||
assert _layout.y == Y | ||
assert _layout.z == Z | ||
assert _layout.position == (X, Y, Z) |