From 42f292b3cebd0849f36a5f76e5622fb7732d612a Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Thu, 15 Feb 2024 14:24:27 -0500 Subject: [PATCH] test_logreader: test interactive mode + fix typo in AUTO_INTERACTIVE (#31481) * fix spelling * test interactive * remove that * test taht * move that old-commit-hash: 8aee0d2af2c9e9c1755afa2b46f68b199958ccdb --- tools/lib/logreader.py | 4 ++-- tools/lib/tests/test_logreader.py | 19 ++++++++++++++++--- tools/plotjuggler/juggle.py | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/lib/logreader.py b/tools/lib/logreader.py index af2c23ef48..2269430792 100755 --- a/tools/lib/logreader.py +++ b/tools/lib/logreader.py @@ -73,7 +73,7 @@ class ReadMode(enum.StrEnum): QLOG = "q" # only read qlogs SANITIZED = "s" # read from the commaCarSegments database AUTO = "a" # default to rlogs, fallback to qlogs - AUTO_INTERACIVE = "i" # default to rlogs, fallback to qlogs with a prompt from the user + AUTO_INTERACTIVE = "i" # default to rlogs, fallback to qlogs with a prompt from the user LogPath = Optional[str] @@ -106,7 +106,7 @@ def apply_strategy(mode: ReadMode, rlog_paths: LogPaths, qlog_paths: LogPaths, v return qlog_paths elif mode == ReadMode.AUTO: return auto_strategy(rlog_paths, qlog_paths, False, valid_file) - elif mode == ReadMode.AUTO_INTERACIVE: + elif mode == ReadMode.AUTO_INTERACTIVE: return auto_strategy(rlog_paths, qlog_paths, True, valid_file) raise Exception(f"invalid mode: {mode}") diff --git a/tools/lib/tests/test_logreader.py b/tools/lib/tests/test_logreader.py index 53b78064ab..974182d638 100755 --- a/tools/lib/tests/test_logreader.py +++ b/tools/lib/tests/test_logreader.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import io import shutil import tempfile import os @@ -168,10 +169,22 @@ class TestLogReader(unittest.TestCase): with mock.patch("openpilot.tools.lib.route.Route.log_paths") as log_paths_mock: log_paths_mock.return_value = [None] * NUM_SEGS # Should fall back to qlogs since rlogs are not available - lr = LogReader(f"{TEST_ROUTE}/0/a", default_source=comma_api_source) - log_len = len(list(lr)) - self.assertEqual(qlog_len, log_len) + with self.subTest("interactive_yes"): + with mock.patch("sys.stdin", new=io.StringIO("y\n")): + lr = LogReader(f"{TEST_ROUTE}/0", default_mode=ReadMode.AUTO_INTERACTIVE, default_source=comma_api_source) + log_len = len(list(lr)) + self.assertEqual(qlog_len, log_len) + + with self.subTest("interactive_no"): + with mock.patch("sys.stdin", new=io.StringIO("n\n")): + with self.assertRaises(AssertionError): + lr = LogReader(f"{TEST_ROUTE}/0", default_mode=ReadMode.AUTO_INTERACTIVE, default_source=comma_api_source) + + with self.subTest("non_interactive"): + lr = LogReader(f"{TEST_ROUTE}/0", default_mode=ReadMode.AUTO, default_source=comma_api_source) + log_len = len(list(lr)) + self.assertEqual(qlog_len, log_len) if __name__ == "__main__": diff --git a/tools/plotjuggler/juggle.py b/tools/plotjuggler/juggle.py index cc21095414..dc94062801 100755 --- a/tools/plotjuggler/juggle.py +++ b/tools/plotjuggler/juggle.py @@ -73,7 +73,7 @@ def process(can, lr): return [d for d in lr if can or d.which() not in ['can', 'sendcan']] def juggle_route(route_or_segment_name, can, layout, dbc=None): - sr = LogReader(route_or_segment_name, default_mode=ReadMode.AUTO_INTERACIVE) + sr = LogReader(route_or_segment_name, default_mode=ReadMode.AUTO_INTERACTIVE) all_data = sr.run_across_segments(24, partial(process, can))