From 7a068ed38394d873e4de22c798adde5d43078a9d Mon Sep 17 00:00:00 2001 From: Jonathan Diamond Date: Tue, 3 Oct 2023 21:02:51 -0700 Subject: [PATCH] Fix unit tests. --- python/tests/test_data_loader.py | 26 +--------------------- python/tests/test_mixed_log_reader.py | 32 +++++---------------------- 2 files changed, 7 insertions(+), 51 deletions(-) diff --git a/python/tests/test_data_loader.py b/python/tests/test_data_loader.py index 4df56612..6a7cb827 100644 --- a/python/tests/test_data_loader.py +++ b/python/tests/test_data_loader.py @@ -155,12 +155,10 @@ def test_read_all(self, data_path): expected_result = message_list_to_dict(expected_messages) # Construct a reader. This will attempt to set t0 immediately by scanning the data file. If an index file - # exists, the reader will use the index file to find t0 quickly. If not, it'll read the file directly, but will - # _not_ attempt to generate an index (which requires reading the entire data file). + # exists, the reader will use the index file to find t0 quickly. reader = DataLoader(path=str(data_path)) assert reader.t0 is not None assert reader.system_t0 is not None - assert not reader.reader.have_index() # Now read the data itself. This _will_ generate an index file. result = reader.read() @@ -224,34 +222,12 @@ def test_read_pose_mixed_binary(self, data_path): assert len(reader.reader._original_index) == len(messages) assert len(reader.reader.index) == len(expected_messages) - def test_read_no_generate_index(self, data_path): - expected_result = generate_data(data_path=str(data_path), include_binary=False) - - # Construct a reader with index generation disabled. This never generates an index, but the read() call below - # would if we did not set this. - reader = DataLoader(path=str(data_path), generate_index=False) - assert reader.t0 is not None - assert reader.system_t0 is not None - assert not reader.reader.have_index() - - # Now read the data itself. This will _not_ generate an index file. - result = reader.read() - self._check_results(result, expected_result) - assert not reader.reader.have_index() - - # Do the same but this time using the disable argument to read(). - reader = DataLoader(path=str(data_path)) - result = reader.read(disable_index_generation=True) - self._check_results(result, expected_result) - assert not reader.reader.have_index() - def test_read_in_order(self, data_path): messages = generate_data(data_path=str(data_path), include_binary=False, return_dict=False) expected_messages = [m for m in messages if m.get_type() in (MessageType.POSE, MessageType.EVENT_NOTIFICATION)] expected_result = message_list_to_messagedata(expected_messages) reader = DataLoader(path=str(data_path)) - assert not reader.reader.have_index() result = reader.read(message_types=[PoseMessage, EventNotificationMessage], return_in_order=True) self._check_results(result, expected_result) diff --git a/python/tests/test_mixed_log_reader.py b/python/tests/test_mixed_log_reader.py index 79c48ad4..df8c5c6e 100644 --- a/python/tests/test_mixed_log_reader.py +++ b/python/tests/test_mixed_log_reader.py @@ -130,7 +130,6 @@ def test_read_all(self, data_path): messages = self._generate_mixed_data(data_path) reader = MixedLogReader(str(data_path)) - assert reader.index is None self._check_results(reader, messages) # Verify that we successfully generated an index file. @@ -145,7 +144,6 @@ def test_read_pose(self, data_path): expected_messages = [m for m in messages if isinstance(m, PoseMessage)] reader = MixedLogReader(str(data_path)) - assert reader.index is None reader.filter_in_place((PoseMessage,)) self._check_results(reader, expected_messages) @@ -175,7 +173,6 @@ def test_read_pose_mixed_binary(self, data_path): expected_messages = [m for m in messages if isinstance(m, PoseMessage)] reader = MixedLogReader(str(data_path)) - assert reader.index is None reader.filter_in_place((PoseMessage,)) self._check_results(reader, expected_messages) @@ -220,10 +217,8 @@ def test_read_no_generate_index(self, data_path): expected_messages = [m for m in messages if isinstance(m, PoseMessage)] reader = MixedLogReader(str(data_path), generate_index=False) - assert reader.index is None reader.filter_in_place((PoseMessage,)) self._check_results(reader, expected_messages) - assert reader.index is None def test_read_with_index(self, data_path): messages = self._generate_mixed_data(data_path) @@ -256,16 +251,11 @@ def test_read_overwrite_index(self, data_path): MixedLogReader.generate_index_file(str(data_path)) reader = MixedLogReader(str(data_path), ignore_index=True) - # By default, we will be generating an index file, overwriting the existing one, so the reader should have - # deleted the existing one. - assert reader.index is None - assert not os.path.exists(reader.index_path) - reader.filter_in_place((PoseMessage,)) self._check_results(reader, expected_messages) # Check that we generated a new index. - assert os.path.exists(reader.index_path) + assert os.path.exists(FileIndex.get_path(data_path)) assert reader.index is not None and len(reader.index) == len(expected_messages) assert len(reader._original_index) == len(messages) @@ -275,17 +265,13 @@ def test_read_ignore_index(self, data_path): MixedLogReader.generate_index_file(str(data_path)) reader = MixedLogReader(str(data_path), ignore_index=True, generate_index=False) - assert reader.index is None # This time, we are not generating an index so we do _not_ delete the existing file and leave it intact. - assert reader.index is None - assert os.path.exists(reader.index_path) + assert os.path.exists(FileIndex.get_path(data_path)) reader.filter_in_place((PoseMessage,)) self._check_results(reader, expected_messages) - assert reader.index is None - # Note: TimeRange objects keep internal state, so we can't use them here since the state will remain across multiple # calls for different use_index values. Instead we store range strings and parse them on each call. @pytest.mark.parametrize("time_range", [ @@ -319,10 +305,8 @@ def _test_rewind(self, data_path, use_index): _, message = next(reader) self._check_message(message, expected_messages[i]) - if use_index: - assert reader.index is not None - else: - assert reader.index is None + + assert reader.index is not None reader.rewind() self._check_results(reader, expected_messages) @@ -425,12 +409,8 @@ def _test_seek_to_eof(self, data_path, use_index): _, message = next(reader) self._check_message(message, expected_messages[i]) - # Now jump to EOF. If we're generating an index file, this is illegal. - if use_index: - reader.seek_to_eof() - else: - with pytest.raises(ValueError): - reader.seek_to_eof() + # Now jump to EOF. + reader.seek_to_eof() def test_seek_to_eof_no_index(self, data_path): self._test_seek_to_eof(data_path, use_index=False)