Grotti 2.10.0: Orca-Senden, Slice-Ordner, ED-Strom, Hygiene.
Slice-Watch mit Ordnern/Filtern, Orca-Nachbearbeitung, Cockpit-Verlauf mit ED, Zeitzone im Browser. Tasten-Grenze und README-API angeglichen, toter Code entfernt, Requirements gepinnt.
This commit is contained in:
1 parent
efd0801cd1
commit
9e22cebb81
48 files changed
+2259
-422
No files matched your search
@@ -0,0 +1,103 @@
|
||||
"""Tests für scripts/orca_senden.py ohne laufenden Server."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from scripts import orca_senden as orca # noqa: E402
|
||||
|
||||
|
||||
class OrcaSendenHelpersTest(unittest.TestCase):
|
||||
def test_send_page_url(self):
|
||||
self.assertEqual(
|
||||
orca.send_page_url("http://127.0.0.1:8770/", 42),
|
||||
"http://127.0.0.1:8770/dateien?file=42",
|
||||
)
|
||||
|
||||
def test_find_gcode_arg_last_matching(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
folder = Path(tmp)
|
||||
gcode = folder / "teil.gcode"
|
||||
gcode.write_text("; test\n", encoding="utf-8")
|
||||
other = folder / "notes.txt"
|
||||
other.write_text("x", encoding="utf-8")
|
||||
found = orca.find_gcode_arg(["orca_senden.py", str(other), str(gcode)])
|
||||
self.assertEqual(found, gcode.resolve())
|
||||
|
||||
def test_find_gcode_arg_pp_temp(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
pp = Path(tmp) / "platte.gcode.pp"
|
||||
pp.write_text("; temp\n", encoding="utf-8")
|
||||
found = orca.find_gcode_arg(["orca_senden.py", str(pp)])
|
||||
self.assertEqual(found, pp.resolve())
|
||||
self.assertEqual(orca.upload_name_for(pp), "platte.gcode")
|
||||
|
||||
def test_under_watch_subfolder(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp) / "slice"
|
||||
dest = root / "Gridfinity" / "teil.gcode"
|
||||
dest.parent.mkdir(parents=True)
|
||||
dest.write_text("; x\n", encoding="utf-8")
|
||||
placed = orca.under_watch(root, dest)
|
||||
self.assertEqual(placed, ("Gridfinity", "teil.gcode"))
|
||||
|
||||
def test_under_watch_outside(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp) / "slice"
|
||||
root.mkdir()
|
||||
other = Path(tmp) / "elsewhere" / "teil.gcode"
|
||||
other.parent.mkdir()
|
||||
other.write_text("; x\n", encoding="utf-8")
|
||||
self.assertIsNone(orca.under_watch(root, other))
|
||||
|
||||
def test_find_gcode_arg_missing(self):
|
||||
with self.assertRaises(ValueError):
|
||||
orca.find_gcode_arg(["orca_senden.py"])
|
||||
|
||||
def test_find_gcode_arg_file_gone(self):
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
orca.find_gcode_arg(["orca_senden.py", r"C:\gibt\es\nicht.gcode"])
|
||||
|
||||
def test_load_config_ok(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = Path(tmp) / "orca-senden.json"
|
||||
path.write_text(
|
||||
json.dumps({"url": "http://127.0.0.1:8770/", "token": "grt_abc"}),
|
||||
encoding="utf-8",
|
||||
)
|
||||
cfg = orca.load_config(path)
|
||||
self.assertEqual(cfg["url"], "http://127.0.0.1:8770")
|
||||
self.assertEqual(cfg["token"], "grt_abc")
|
||||
|
||||
def test_load_config_missing(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = Path(tmp) / "fehlt.json"
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
orca.load_config(path)
|
||||
|
||||
def test_load_config_empty_token(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = Path(tmp) / "orca-senden.json"
|
||||
path.write_text(json.dumps({"url": "http://x", "token": ""}), encoding="utf-8")
|
||||
with self.assertRaises(ValueError):
|
||||
orca.load_config(path)
|
||||
|
||||
def test_main_shows_error_without_config(self):
|
||||
with patch.object(orca, "CONFIG_PATH", Path("/tmp/does-not-exist-orca.json")):
|
||||
with patch.object(orca, "show_error") as shown:
|
||||
code = orca.main(["orca_senden.py", "x.gcode"])
|
||||
self.assertEqual(code, 1)
|
||||
self.assertTrue(shown.called)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user