Commits

rkruppe  committed 9592419

new module ttgx.process

  • Participants
  • Parent commits cf20f97

Comments (0)

Files changed (2)

File ttgx/process.py

+import ttgx.dodecs
+import ttgx.gui.window
+import ttgx.gui.driver
+import ttgx.assets
+
+class Process:
+
+    """Holds process-global data and resources."""
+
+    def __init__(self):
+        self.assets = None
+        self.gui_driver = None
+        self.universe = None
+        self.window = None
+
+    def create_assets(self, path):
+        self.assets = ttgx.assets.AssetCollection(path)
+
+    def create_universe(self):
+        self.universe = ttgx.dodecs.Universe()
+
+    def create_window(self, **kwargs):
+        self.window = ttgx.gui.window.Window(**kwargs)
+        self.window.setup()
+        self.gui_driver = ttgx.gui.driver.GUIDriver(self.window)
+

File ttgx/tests/test_process.py

+from unittest.mock import Mock, patch, call
+import pytest
+import ttgx.process
+import ttgx.dodecs
+import ttgx.gui.driver
+
+
+@pytest.fixture
+def proc():
+    return ttgx.process.Process()
+
+
+@pytest.mark.parametrize('res', [
+    'assets', 'gui_driver', 'universe', 'window'
+])
+def test_resource_not_created_at_init(proc, res):
+    assert getattr(proc, res) is None
+
+
+def test_create_assets(proc):
+    with patch('ttgx.assets') as massets:
+        proc.create_assets('/some/path')
+    assert massets.mock_calls == [call.AssetCollection('/some/path')]
+    assert proc.assets is massets.AssetCollection()
+
+
+def test_create_universe(proc):
+    proc.create_universe()
+    assert isinstance(proc.universe, ttgx.dodecs.Universe)
+
+
+def test_create_window(proc):
+    kwargs = dict(style=Mock(), width=80, height=60)
+    with patch('ttgx.gui.window.Window') as mwin:
+        proc.create_window(**kwargs)
+    assert mwin.mock_calls == [call(**kwargs), call().setup()]
+    assert proc.window is mwin()
+    assert isinstance(proc.gui_driver, ttgx.gui.driver.GUIDriver)
+