Skip to content

Commit 5bcc0b0

Browse files
authored
Merge pull request #801 from OpenSimulationInterface/fix/osi-trace-robustness
Fix osi trace robustness
2 parents 70f79a7 + ee47d49 commit 5bcc0b0

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Diff for: osi3trace/osi_trace.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def retrieve_offsets(self, limit=None):
5555
if not self.read_complete:
5656
self.current_index = len(self.message_offsets) - 1
5757
self.file.seek(self.message_offsets[-1], 0)
58-
while (
59-
not self.read_complete and not limit or len(self.message_offsets) <= limit
58+
while not self.read_complete and (
59+
not limit or len(self.message_offsets) <= limit
6060
):
6161
self.retrieve_message(skip=True)
6262
return self.message_offsets

Diff for: tests/test_osi_trace.py

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ def test_osi_trace(self):
2222

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

25+
def test_osi_trace_offsets_robustness(self):
26+
with tempfile.TemporaryDirectory() as tmpdirname:
27+
path_input = os.path.join(tmpdirname, "input.osi")
28+
create_sample(path_input)
29+
30+
trace = OSITrace(path_input)
31+
# Test whether the function can handle be run multiple times safely
32+
offsets = trace.retrieve_offsets(None)
33+
offsets2 = trace.retrieve_offsets(None)
34+
trace.close()
35+
36+
self.assertEqual(len(offsets), 10)
37+
self.assertEqual(offsets, offsets2)
38+
2539

2640
def create_sample(path):
2741
f = open(path, "ab")

0 commit comments

Comments
 (0)