mirror of https://github.com/commaai/openpilot.git
test_logreader: test interactive mode + fix typo in AUTO_INTERACTIVE (#31481)
* fix spelling
* test interactive
* remove that
* test taht
* move that
old-commit-hash: 8aee0d2af2
This commit is contained in:
parent
7089ac644b
commit
42f292b3ce
|
@ -73,7 +73,7 @@ class ReadMode(enum.StrEnum):
|
||||||
QLOG = "q" # only read qlogs
|
QLOG = "q" # only read qlogs
|
||||||
SANITIZED = "s" # read from the commaCarSegments database
|
SANITIZED = "s" # read from the commaCarSegments database
|
||||||
AUTO = "a" # default to rlogs, fallback to qlogs
|
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]
|
LogPath = Optional[str]
|
||||||
|
@ -106,7 +106,7 @@ def apply_strategy(mode: ReadMode, rlog_paths: LogPaths, qlog_paths: LogPaths, v
|
||||||
return qlog_paths
|
return qlog_paths
|
||||||
elif mode == ReadMode.AUTO:
|
elif mode == ReadMode.AUTO:
|
||||||
return auto_strategy(rlog_paths, qlog_paths, False, valid_file)
|
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)
|
return auto_strategy(rlog_paths, qlog_paths, True, valid_file)
|
||||||
raise Exception(f"invalid mode: {mode}")
|
raise Exception(f"invalid mode: {mode}")
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import io
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
|
@ -168,10 +169,22 @@ class TestLogReader(unittest.TestCase):
|
||||||
with mock.patch("openpilot.tools.lib.route.Route.log_paths") as log_paths_mock:
|
with mock.patch("openpilot.tools.lib.route.Route.log_paths") as log_paths_mock:
|
||||||
log_paths_mock.return_value = [None] * NUM_SEGS
|
log_paths_mock.return_value = [None] * NUM_SEGS
|
||||||
# Should fall back to qlogs since rlogs are not available
|
# 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__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -73,7 +73,7 @@ def process(can, lr):
|
||||||
return [d for d in lr if can or d.which() not in ['can', 'sendcan']]
|
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):
|
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))
|
all_data = sr.run_across_segments(24, partial(process, can))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue