Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix osi trace robustness #801

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions osi3trace/osi_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def retrieve_offsets(self, limit=None):
if not self.read_complete:
self.current_index = len(self.message_offsets) - 1
self.file.seek(self.message_offsets[-1], 0)
while (
not self.read_complete and not limit or len(self.message_offsets) <= limit
while not self.read_complete and (
not limit or len(self.message_offsets) <= limit
):
self.retrieve_message(skip=True)
return self.message_offsets
Expand Down
14 changes: 14 additions & 0 deletions tests/test_osi_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ def test_osi_trace(self):

self.assertTrue(os.path.exists(path_output))

def test_osi_trace_offsets_robustness(self):
with tempfile.TemporaryDirectory() as tmpdirname:
path_input = os.path.join(tmpdirname, "input.osi")
create_sample(path_input)

trace = OSITrace(path_input)
# Test whether the function can handle be run multiple times safely
offsets = trace.retrieve_offsets(None)
offsets2 = trace.retrieve_offsets(None)
trace.close()

self.assertEqual(len(offsets), 10)
self.assertEqual(offsets, offsets2)


def create_sample(path):
f = open(path, "ab")
Expand Down