update
This commit is contained in:
169
AzA march 2026/_test_minidiktat_reliable_start_stop.py
Normal file
169
AzA march 2026/_test_minidiktat_reliable_start_stop.py
Normal file
@@ -0,0 +1,169 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Gezielte Tests: Diktat idle-open + Mini-Diktat Start/Stop-Zyklus."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
ROOT = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def _func_body(src: str, name: str) -> str:
|
||||
marker = f"def {name}"
|
||||
idx = src.find(marker)
|
||||
if idx < 0:
|
||||
return ""
|
||||
rest = src[idx + len(marker) :]
|
||||
nxt = rest.find("\n def ")
|
||||
if nxt < 0:
|
||||
nxt = rest.find("\n def ")
|
||||
return rest[:nxt] if nxt >= 0 else rest
|
||||
|
||||
|
||||
class DiktatIdleOpenTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
import aza_diktat_mixin as dm
|
||||
|
||||
cls.dm_src = inspect.getsource(dm.AzaDiktatMixin.open_diktat_window)
|
||||
|
||||
def test_no_auto_start_after_open(self):
|
||||
self.assertNotIn("win.after(350, toggle_diktat)", self.dm_src)
|
||||
self.assertNotIn("diktat_auto_start", self.dm_src)
|
||||
|
||||
def test_initial_status_bereit(self):
|
||||
self.assertIn('status_var = tk.StringVar(value="Bereit.")', self.dm_src)
|
||||
|
||||
def test_central_phase_function(self):
|
||||
self.assertIn("def _diktat_recorder_phase", self.dm_src)
|
||||
self.assertIn('win._aza_diktat_phase = _diktat_recorder_phase', self.dm_src)
|
||||
|
||||
def test_refresh_updates_command(self):
|
||||
body = _func_body(self.dm_src, "_refresh_diktat_controls")
|
||||
self.assertIn("command=toggle_diktat", body)
|
||||
self.assertIn("command=lambda: None", body)
|
||||
|
||||
def test_start_button_idle_label(self):
|
||||
self.assertIn('"Diktat starten"', self.dm_src)
|
||||
self.assertIn('"Diktat stoppen"', self.dm_src)
|
||||
|
||||
|
||||
class MiniDiktatCommandSwitchTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
import aza_mini_diktat_window as md
|
||||
import aza_diktat_mixin as dm
|
||||
|
||||
cls.md_open = inspect.getsource(md.open_mini_diktat_window)
|
||||
cls.md_sync = inspect.getsource(md.sync_mini_diktat_window)
|
||||
cls.md_close = inspect.getsource(md.close_mini_diktat_window)
|
||||
cls.dm_src = inspect.getsource(dm.AzaDiktatMixin.open_diktat_window)
|
||||
|
||||
def test_separate_stop_and_weiter_handlers(self):
|
||||
self.assertIn("def _on_mini_stop", self.md_open)
|
||||
self.assertIn("def _on_mini_weiterfahren", self.md_open)
|
||||
self.assertIn("_mini_diktat_on_stop", self.md_open)
|
||||
self.assertIn("_mini_diktat_on_weiterfahren", self.md_open)
|
||||
|
||||
def test_sync_sets_command_not_only_text(self):
|
||||
self.assertIn('command=stop_cmd', self.md_sync)
|
||||
self.assertIn('command=weiter_cmd', self.md_sync)
|
||||
self.assertIn('"Stoppen"', self.md_sync)
|
||||
self.assertIn('"Weiterfahren"', self.md_sync)
|
||||
|
||||
def test_stop_handler_calls_toggle(self):
|
||||
body = _func_body(self.md_open, "_on_mini_stop")
|
||||
self.assertIn("_aza_diktat_toggle", body)
|
||||
self.assertIn("_diktat_neu_busy", body)
|
||||
|
||||
def test_weiterfahren_does_not_call_weiter_during_recording(self):
|
||||
body = _func_body(self.md_open, "_on_mini_weiterfahren")
|
||||
self.assertIn('_diktat_phase(diktat_win) == "recording"', body)
|
||||
self.assertIn("_on_mini_stop", body)
|
||||
|
||||
def test_logo_blocked_or_stops_during_recording(self):
|
||||
body = _func_body(self.md_open, "_on_logo_click")
|
||||
self.assertIn("_mini_diktat_logo_active", body)
|
||||
self.assertIn("_on_mini_stop", body)
|
||||
|
||||
def test_close_waits_for_stop(self):
|
||||
self.assertIn("_skip_stop", self.md_close)
|
||||
self.assertIn("_wait_recording_stopped", self.md_close)
|
||||
self.assertIn("_aza_diktat_toggle", self.md_close)
|
||||
|
||||
def test_weiterfahren_mixin_stops_if_recording(self):
|
||||
body = _func_body(self.dm_src, "_diktat_weiterfahren")
|
||||
self.assertIn("_diktat_recorder_phase()", body)
|
||||
self.assertIn("toggle_diktat()", body)
|
||||
|
||||
def test_busy_guard_and_finally_reset(self):
|
||||
self.assertIn("self._diktat_neu_busy = True", self.dm_src)
|
||||
self.assertIn("def _after_finalize", self.dm_src)
|
||||
self.assertIn("finally:", self.dm_src)
|
||||
|
||||
|
||||
class MiniDiktatMockCycleTests(unittest.TestCase):
|
||||
def test_phase_idle_recording_finalizing(self):
|
||||
import aza_mini_diktat_window as md
|
||||
|
||||
class FakeWin:
|
||||
_phase = "idle"
|
||||
|
||||
def _aza_diktat_phase(self):
|
||||
return self._phase
|
||||
|
||||
win = FakeWin()
|
||||
win._phase = "idle"
|
||||
self.assertEqual(md._diktat_phase(win), "idle")
|
||||
win._phase = "recording"
|
||||
self.assertEqual(md._diktat_phase(win), "recording")
|
||||
self.assertTrue(md._is_diktat_recording(win))
|
||||
win._phase = "finalizing"
|
||||
self.assertEqual(md._diktat_phase(win), "finalizing")
|
||||
self.assertFalse(md._is_diktat_recording(win))
|
||||
|
||||
def test_stop_command_not_weiterfahren(self):
|
||||
import aza_mini_diktat_window as md
|
||||
|
||||
calls = {"toggle": 0, "weiter": 0}
|
||||
|
||||
class DWin:
|
||||
def _aza_diktat_toggle(self):
|
||||
calls["toggle"] += 1
|
||||
|
||||
def _aza_diktat_weiterfahren(self):
|
||||
calls["weiter"] += 1
|
||||
|
||||
def _aza_diktat_phase(self):
|
||||
return "recording"
|
||||
|
||||
app = mock.Mock()
|
||||
app._diktat_neu_busy = False
|
||||
dw = DWin()
|
||||
stop_fn = getattr(md, "open_mini_diktat_window") # noqa: sanity import
|
||||
|
||||
# Direkt die Stop-Logik spiegeln
|
||||
def mini_stop():
|
||||
if getattr(app, "_diktat_neu_busy", False):
|
||||
return
|
||||
fn = getattr(dw, "_aza_diktat_toggle", None)
|
||||
if callable(fn):
|
||||
fn()
|
||||
|
||||
mini_stop()
|
||||
self.assertEqual(calls["toggle"], 1)
|
||||
self.assertEqual(calls["weiter"], 0)
|
||||
|
||||
|
||||
class StartScriptV9Tests(unittest.TestCase):
|
||||
def test_points_to_v9(self):
|
||||
ps1 = (ROOT / "start_doku_prompt_test.ps1").read_text(encoding="utf-8-sig")
|
||||
self.assertIn("test_final_release_candidate_v9", ps1)
|
||||
self.assertNotIn("test_final_release_candidate_v8", ps1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user