shibosoftwaredev/f1c100s-linux-nema17-stepper-controller

A four-layer NEMA 17 motor-controller PCB combining an Allwinner F1C100S Linux computer, USB‑PD/buck power system, W5500 Ethernet, STM32 real-time motion control, DRV8825 stepper driver, protection/temperature/current telemetry, USB interfaces, and local LED/buzzer diagnostics.

Version
0.4.56
License
unset
Stars
0

scripts/test_fabrication_handoff.py

import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
from fabrication_handoff import promote_handoff


class FabricationHandoffTests(unittest.TestCase):
    def test_success_keeps_old_handoff_and_excludes_stale_files(self):
        with tempfile.TemporaryDirectory() as directory:
            root = Path(directory)
            old, new = root / "fabrication", root / "staging"
            old.mkdir(); new.mkdir()
            (old / "old.drl").write_bytes(b"previous drill")
            (new / "new.drl").write_bytes(b"validated drill")
            backup = promote_handoff(new, old)
            self.assertEqual((backup / "old.drl").read_bytes(), b"previous drill")
            self.assertEqual((old / "new.drl").read_bytes(), b"validated drill")
            self.assertFalse((old / "old.drl").exists())

    def test_failed_promotion_restores_old_handoff(self):
        with tempfile.TemporaryDirectory() as directory:
            root = Path(directory)
            old, new = root / "fabrication", root / "staging"
            old.mkdir(); new.mkdir()
            (old / "old.drl").write_bytes(b"previous drill")
            original = Path.replace

            def fail_staging(path, target):
                if path == new:
                    raise OSError("simulated promotion failure")
                return original(path, target)

            with patch.object(Path, "replace", fail_staging):
                with self.assertRaises(OSError):
                    promote_handoff(new, old)
            self.assertEqual((old / "old.drl").read_bytes(), b"previous drill")
            self.assertTrue(new.exists())


if __name__ == "__main__":
    unittest.main()