LogReader: retain old behavior for direct parsing of files (#31419)

* maintain exception

* test that head is not called

* annoying mock

* test with cache
pull/31464/head
Justin Newberry 1 year ago committed by GitHub
parent 991d02ba27
commit 1436f576df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      tools/lib/logreader.py
  2. 12
      tools/lib/tests/test_logreader.py

@ -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}---",),

Loading…
Cancel
Save