Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
filipkotoucek committed Aug 14, 2024
1 parent a0a91e1 commit 746b4b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 4 additions & 3 deletions prusaerrors/sl1/codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from prusaerrors.shared.codes import Category, Code, Printer, unique_codes, Codes

PRINTER_MODEL_PATH = Path("/run/model")

if "_" not in vars(builtins):

def _(value):
Expand All @@ -32,14 +34,13 @@ def decor(cls):
assert "Errors" in data

printer = Printer.SL1
path = Path("/run/model")
model = [x.name for x in path.iterdir() if x.is_file()]
model = [x.name for x in PRINTER_MODEL_PATH.iterdir() if x.is_file()]
if len(model) == 1:
a = Printer.M1.name.lower()
if a in model:
printer = Printer.M1
else:
raise KeyError("None or multiple model files found. Check /run/model folder.")
raise KeyError("None or multiple model files found. Check %s folder.", PRINTER_MODEL_PATH)

re = re_compile(
r"^(?P<printer>([0-9][0-9]|XX))"
Expand Down
14 changes: 13 additions & 1 deletion tests/test_sl1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
# pylint: disable = missing-class-docstring
# pylint: disable = missing-module-docstring

from tempfile import TemporaryDirectory
import unittest
from unittest.mock import MagicMock, PropertyMock, patch

from prusaerrors.sl1.codes import Sl1Codes

Expand All @@ -15,8 +17,18 @@ class TestErrors(unittest.TestCase):
def test_str_conversion(self):
self.assertEqual("#10500", str(Sl1Codes.NONE))


def test_code_lookup(self):
self.assertEqual(Sl1Codes.NONE, Sl1Codes.get("#10500"))
with patch("prusaerrors.sl1.codes.PRINTER_MODEL_PATH") as mock:
with TemporaryDirectory() as dir:
mock.return_value = dir

with open(str(dir) + "/sl1", "w+", encoding="utf-8") as f:
self.assertEqual(Sl1Codes.NONE, Sl1Codes.get("#10500"))
with open(str(dir) + "/sl1s", "w+", encoding="utf-8") as f:
self.assertEqual(Sl1Codes.NONE, Sl1Codes.get("#10500"))
with open(str(dir) + "/m1", "w+", encoding="utf-8") as f:
self.assertEqual(Sl1Codes.NONE, Sl1Codes.get("#29500"))

def test_unknown_code_lookup(self):
self.assertEqual(Sl1Codes.UNKNOWN, Sl1Codes.get("random string"))
Expand Down

0 comments on commit 746b4b2

Please sign in to comment.