Skip to content

Commit

Permalink
Merge pull request #801 from OpenSimulationInterface/fix/osi-trace-ro…
Browse files Browse the repository at this point in the history
…bustness

Fix osi trace robustness
  • Loading branch information
pmai authored May 6, 2024
2 parents 70f79a7 + ee47d49 commit 5bcc0b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit 5bcc0b0

Please sign in to comment.