Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Der ESC-Waechter ist das Cockpit - ohne ihn ist ESC taub (hand/notaus.py: esc_waechter).
|
|
|
|
ESC als Not-Aus faengt nicht der Laeufer, sondern der Tastenwaechter im Cockpit
|
|
(`mac/Sources/Cockpit/Tasten.swift`); er schreibt die Stopp-Dateien. Laeuft das Cockpit nicht,
|
|
geht ein ESC ins Leere - 31.10. passiert: der Laeufer klickte weiter, der Nutzer drueckte
|
|
mehrfach ESC, und niemand hoerte zu.
|
|
|
|
Der Waechter nennt sich in `sicht/scratch/cockpit-instanz.json` (pid). Lebt der Prozess, ist ESC
|
|
bewaffnet.
|
|
|
|
python3 tests/notaus_waechter_spec.py -v
|
|
"""
|
|
import json
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
_w = os.path.dirname(os.path.abspath(__file__))
|
|
while _w != "/" and not os.path.isdir(os.path.join(_w, "lesen")):
|
|
_w = os.path.dirname(_w)
|
|
sys.path.insert(0, os.path.join(_w, "hand"))
|
|
sys.path.insert(0, os.path.join(_w, "client"))
|
|
|
|
import notaus
|
|
|
|
|
|
class Waechter(unittest.TestCase):
|
|
def test_app_laeuft_gilt_als_waechter(self):
|
|
liste = " 4711 /Applications/x/Cockpit.app/Contents/MacOS/Cockpit\n 22 /usr/bin/ps\n"
|
|
self.assertEqual(notaus.esc_waechter(liste), 4711)
|
|
|
|
def test_ohne_app_kein_waechter(self):
|
|
self.assertIsNone(notaus.esc_waechter(" 22 /usr/bin/ps\n 33 python3 betrieb/runner.py\n"))
|
|
|
|
def test_leere_liste_kein_waechter(self):
|
|
self.assertIsNone(notaus.esc_waechter(""))
|
|
|
|
def test_aehnlicher_name_zaehlt_nicht(self):
|
|
self.assertIsNone(notaus.esc_waechter(" 9 /usr/bin/Cockpit\n"))
|
|
|
|
def test_ohne_waechter_ist_der_hinweis_da(self):
|
|
self.assertIn("Cockpit", notaus.ESC_HINWEIS)
|
|
|
|
def test_ohne_strenge_geht_es_ohne_waechter(self):
|
|
alt = notaus.STRENG
|
|
notaus.STRENG = False
|
|
self.assertTrue(notaus.darf_klicken(""))
|
|
notaus.STRENG = alt
|
|
|
|
def test_streng_braucht_einen_waechter(self):
|
|
alt = notaus.STRENG
|
|
notaus.STRENG = True
|
|
self.assertFalse(notaus.darf_klicken(" 9 /usr/bin/ps\n"))
|
|
self.assertTrue(notaus.darf_klicken(" 4711 x/" + notaus.COCKPIT + "\n"))
|
|
notaus.STRENG = alt
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|