Skip to content

Commit

Permalink
Change mathrace_interaction.determine_journal_version to take a strea…
Browse files Browse the repository at this point in the history
…m as input
  • Loading branch information
francesco-ballarin committed Feb 13, 2024
1 parent 0bf839d commit da1a574
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Determine the version of a mathrace journal."""

import pathlib
import typing


def determine_journal_version(journal_filename: pathlib.Path) -> str:
def determine_journal_version(journal_stream: typing.TextIO) -> str:
"""
Determine the version of a mathrace journal.
Parameters
----------
journal_filename
The filename of a journal generated by mathrace or simdis.
journal_stream
The I/O stream that reads the journal generated by mathrace or simdis.
The I/O stream is typically generated by open().
Returns
-------
Expand Down Expand Up @@ -98,8 +98,7 @@ def determine_journal_version(journal_filename: pathlib.Path) -> str:
This change affects all race event codes.
"""
with open(journal_filename) as journal_file:
journal = [line.strip("\n") for line in journal_file.readlines()]
journal = [line.strip("\n") for line in journal_stream.readlines()]

# Since all versions after the fallback one use the event code 200 for the race start,
# a journal containing the code 002 is a fallback journal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def test_determine_journal_version(
) -> None:
"""Test determine_journal_version with all journals in the data directory."""
for journal in data_journals_all:
actual_version = determine_journal_version(journal)
with open(journal) as journal_stream:
actual_version = determine_journal_version(journal_stream)
expected_version = expected_journal_versions_all[journal]
assert actual_version == expected_version, (
f"{journal} version was determined as {actual_version}, but the expected version was {expected_version}")

0 comments on commit da1a574

Please sign in to comment.