mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-08-05 08:16:03 +08:00
LogReader: retain old behavior for direct parsing of files (#31419)
* maintain exception * test that head is not called * annoying mock * test with cache old-commit-hash: 1436f576df5f43f78b9253b5b2072fbf1414d9be
This commit is contained in:
@@ -223,7 +223,12 @@ class LogReader:
|
||||
mode = self.default_mode if sr.selector is None else ReadMode(sr.selector)
|
||||
source = self.default_source if source is None else source
|
||||
|
||||
return source(sr, mode)
|
||||
identifiers = source(sr, mode)
|
||||
|
||||
invalid_count = len(list(get_invalid_files(identifiers)))
|
||||
assert invalid_count == 0, f"{invalid_count}/{len(identifiers)} invalid log(s) found, please ensure all logs \
|
||||
are uploaded or auto fallback to qlogs with '/a' selector at the end of the route name."
|
||||
return identifiers
|
||||
|
||||
def __init__(self, identifier: str | List[str], default_mode=ReadMode.RLOG, default_source=auto_source, sort_by_time=False, only_union_types=False):
|
||||
self.default_mode = default_mode
|
||||
@@ -258,9 +263,6 @@ class LogReader:
|
||||
|
||||
def reset(self):
|
||||
self.logreader_identifiers = self._parse_identifiers(self.identifier)
|
||||
invalid_count = len(list(get_invalid_files(self.logreader_identifiers)))
|
||||
assert invalid_count == 0, f"{invalid_count}/{len(self.logreader_identifiers)} invalid log(s) found, please ensure all logs \
|
||||
are uploaded or auto fallback to qlogs with '/a' selector at the end of the route name."
|
||||
|
||||
@staticmethod
|
||||
def from_bytes(dat):
|
||||
|
||||
@@ -11,6 +11,7 @@ from unittest import mock
|
||||
|
||||
from openpilot.tools.lib.logreader import LogIterable, LogReader, comma_api_source, parse_indirect, ReadMode
|
||||
from openpilot.tools.lib.route import SegmentRange
|
||||
from openpilot.tools.lib.url_file import URLFileException
|
||||
|
||||
NUM_SEGS = 17 # number of segments in the test route
|
||||
ALL_SEGS = list(range(NUM_SEGS))
|
||||
@@ -65,7 +66,10 @@ class TestLogReader(unittest.TestCase):
|
||||
sr = SegmentRange(identifier)
|
||||
self.assertEqual(str(sr), expected)
|
||||
|
||||
def test_direct_parsing(self):
|
||||
@parameterized.expand([(True,), (False,)])
|
||||
@mock.patch("openpilot.tools.lib.logreader.file_exists")
|
||||
def test_direct_parsing(self, cache_enabled, file_exists_mock):
|
||||
os.environ["FILEREADER_CACHE"] = "1" if cache_enabled else "0"
|
||||
qlog = tempfile.NamedTemporaryFile(mode='wb', delete=False)
|
||||
|
||||
with requests.get(QLOG_FILE, stream=True) as r:
|
||||
@@ -76,6 +80,12 @@ class TestLogReader(unittest.TestCase):
|
||||
l = len(list(LogReader(f)))
|
||||
self.assertGreater(l, 100)
|
||||
|
||||
with self.assertRaises(URLFileException) if not cache_enabled else self.assertRaises(AssertionError):
|
||||
l = len(list(LogReader(QLOG_FILE.replace("/3/", "/200/"))))
|
||||
|
||||
# file_exists should not be called for direct files
|
||||
self.assertEqual(file_exists_mock.call_count, 0)
|
||||
|
||||
@parameterized.expand([
|
||||
(f"{TEST_ROUTE}///",),
|
||||
(f"{TEST_ROUTE}---",),
|
||||
|
||||
Reference in New Issue
Block a user