51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
"""Zustandsmaschine der Druckwarteschlange mit Fake-Moonraker."""
|
|
|
|
import unittest
|
|
from pathlib import Path
|
|
import sys
|
|
from unittest import mock
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from grotti.print_queue import PRINT_START_TIMEOUT_S, PrintQueueDispatcher, _cool_wait_text
|
|
|
|
|
|
class CoolTextTests(unittest.TestCase):
|
|
def test_wait_text(self):
|
|
cool = {"bed_max": 30, "nozzle_max": 45}
|
|
text = _cool_wait_text({"bed": 40, "nozzle": 50}, cool)
|
|
self.assertIn("Düse", text)
|
|
self.assertIn("Bett", text)
|
|
self.assertNotIn(" · ", text)
|
|
|
|
|
|
class DispatcherHelpers(unittest.TestCase):
|
|
def test_timeout_constant(self):
|
|
self.assertGreaterEqual(PRINT_START_TIMEOUT_S, 300)
|
|
|
|
def test_worker_busy_empty(self):
|
|
d = PrintQueueDispatcher("postgresql://x", {}, watcher=None)
|
|
self.assertFalse(d._worker_busy(1))
|
|
|
|
def test_auto_enabled_default(self):
|
|
d = PrintQueueDispatcher("postgresql://x", {}, watcher=None)
|
|
self.assertTrue(d._auto_enabled())
|
|
d.cfg = {"auto_queue": False}
|
|
self.assertFalse(d._auto_enabled())
|
|
|
|
|
|
class ResolveSpoolTests(unittest.TestCase):
|
|
def test_material_match(self):
|
|
from grotti.jobs import assert_material_match
|
|
from grotti.errors import GrottiError
|
|
|
|
file_row = {"filaments": [{"type": "PLA"}]}
|
|
assert_material_match(file_row, [{"material_type": "PLA"}])
|
|
with self.assertRaises(GrottiError):
|
|
assert_material_match(file_row, [{"material_type": "PETG"}])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|