Skip to content

Commit

Permalink
Fix validator info csv: Add explicit seek for StringIO
Browse files Browse the repository at this point in the history
  • Loading branch information
lord-haffi committed Nov 15, 2023
1 parent 6f84eac commit 51a6cf2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/pvframework/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from dataclasses import dataclass
from datetime import timedelta
from enum import IntEnum, StrEnum
from io import StringIO
from io import SEEK_END, StringIO
from typing import Generic, Iterable, Iterator, Optional

import networkx as nx
Expand Down Expand Up @@ -167,6 +167,7 @@ def get_csv_formatted_validator_infos(
"""
if initial_value is None or isinstance(initial_value, str):
output = StringIO(initial_value=initial_value)
output.seek(0, SEEK_END)
else:
output = initial_value
csv_writer = csv.writer(output)
Expand Down
11 changes: 11 additions & 0 deletions unittests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,23 @@ def test_validator_info_table(self):

csv_table = validation_manager.get_csv_formatted_validator_infos()

validation_manager2 = ValidationManager[DataSetTest](manager_id="TestValidationManager2")
validation_manager2.register(PathMappedValidator(validator_check_y_positive, {"y": "y"}))
validation_manager2.register(
PathMappedValidator(validator_check_required_and_optional_with_utility, {"z": "z"}),
mode=ValidationMode.WARNING,
)

csv_table = validation_manager.get_csv_formatted_validator_infos()
csv_table = validation_manager2.get_csv_formatted_validator_infos(headings=None, initial_value=csv_table)

assert isinstance(csv_table, str)
assert (
"Just a heavy task to validate x.\\n"
"This docstring is used to test the output of the csv renderer of the ValidationManager."
) in csv_table
assert "TestValidationManager" in csv_table
assert "TestValidationManager2" in csv_table
assert "check_x_expensive" in csv_table
assert ValidationMode.ERROR.value in csv_table
assert ValidationMode.WARNING.value in csv_table

0 comments on commit 51a6cf2

Please sign in to comment.