Support q exit in interval mode
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import io
|
||||
import signal
|
||||
import threading
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from rich.console import Console
|
||||
|
||||
@@ -14,6 +17,8 @@ from mm.cli import (
|
||||
load_machines,
|
||||
parse_nvidia_smi_csv,
|
||||
render_dashboard,
|
||||
refresh_dashboard,
|
||||
watch_quit_key,
|
||||
)
|
||||
|
||||
|
||||
@@ -105,6 +110,37 @@ class CLITests(unittest.TestCase):
|
||||
|
||||
self.assertEqual(args.interval, 15)
|
||||
|
||||
def test_watch_quit_key_sends_sigint_for_q_key(self) -> None:
|
||||
with (
|
||||
patch("mm.cli.read_key", return_value="q"),
|
||||
patch("mm.cli.os.getpid", return_value=123),
|
||||
patch("mm.cli.os.kill") as kill,
|
||||
):
|
||||
watch_quit_key(io.StringIO(), threading.Event())
|
||||
|
||||
kill.assert_called_once_with(123, signal.SIGINT)
|
||||
|
||||
def test_refresh_dashboard_sleeps_between_refreshes(self) -> None:
|
||||
console = Console(file=io.StringIO(), record=True, color_system=None, width=120)
|
||||
|
||||
with (
|
||||
patch("mm.cli.collect_status", return_value=[]) as collect_status,
|
||||
patch("mm.cli.render_dashboard"),
|
||||
patch("mm.cli.time.sleep", side_effect=KeyboardInterrupt) as sleep,
|
||||
):
|
||||
with self.assertRaises(KeyboardInterrupt):
|
||||
refresh_dashboard(
|
||||
[],
|
||||
Path("list.yaml"),
|
||||
timeout=1,
|
||||
interval=10,
|
||||
console=console,
|
||||
input_stream=io.StringIO(),
|
||||
)
|
||||
|
||||
collect_status.assert_called_once_with([], 1)
|
||||
sleep.assert_called_once()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user