Convert test to pytest. Fix warning in collection.
-import unittest
+import pytest
from pyglet import gl
from pyglet import graphics
@@ -7,9 +7,13 @@ from pyglet.text import layout
from pyglet import window
-class TestWindow(window.Window):
+
+@pytest.fixture(params=[document.UnformattedDocument,
+ document.FormattedDocument])
+def text_window(request):
+ class _TestWindow(window.Window):
def __init__(self, doctype, *args, **kwargs):
- super(TestWindow, self).__init__(*args, **kwargs)
+ super(_TestWindow, self).__init__(*args, **kwargs)
self.batch = graphics.Batch()
self.document = doctype()
@@ -24,28 +28,18 @@ class TestWindow(window.Window):
def set_bold(self):
self.document.set_style(0, len(self.document.text), {"bold": True})
+ return _TestWindow(request.param)
+
+
+def test_empty_document(text_window):
+ """Empty text document can be rendered."""
+ text_window.dispatch_events()
+ text_window.close()
+
-class EmptyDocumentTest(unittest.TestCase):
- """Test that an empty document doesn't break."""
- def test_unformatted(self):
- self.window = TestWindow(document.UnformattedDocument)
- self.window.dispatch_events()
- self.window.close()
-
- def test_formatted(self):
- self.window = TestWindow(document.FormattedDocument)
- self.window.dispatch_events()
- self.window.close()
-
- def test_bold_unformatted(self):
- self.window = TestWindow(document.UnformattedDocument)
- self.window.set_bold()
- self.window.dispatch_events()
- self.window.close()
-
- def test_bold_formatted(self):
- self.window = TestWindow(document.FormattedDocument)
- self.window.set_bold()
- self.window.dispatch_events()
- self.window.close()
+def test_empty_document_bold(text_window):
+ """Empty text document can be rendered and attributes can be set."""
+ text_window.set_bold()
+ text_window.dispatch_events()
+ text_window.close()
