Skip to content

Commit

Permalink
Revert "refactor: allow str in resource stream (#371)" (#372)
Browse files Browse the repository at this point in the history
This reverts commit fe9f3f2.

Overlooked the parameters given to read, i.e. size is passed to read but
ignored for str type.
  • Loading branch information
jsolaas committed Feb 5, 2024
1 parent fe9f3f2 commit 2fd3a2b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/libecalc/presentation/yaml/yaml_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ class YamlTimeseriesResource:
@dataclass
class ResourceStream:
name: str
stream: Union[TextIO, str]
stream: TextIO

# Implement read to make resource behave as a stream.
def read(self, *args, **kwargs):
if isinstance(self.stream, str):
return self.stream
return self.stream.read(*args, **kwargs)


Expand Down
3 changes: 2 additions & 1 deletion src/tests/ecalc_cli/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,8 @@ def test_yaml_file_error(self):

yaml_wrong_name = (Path("test.name.yaml")).absolute()
yaml_reader = PyYamlYamlModel.YamlReader(loader=yaml.SafeLoader)
yaml_stream = ResourceStream(name=yaml_wrong_name.name, stream="")
stream = StringIO("")
yaml_stream = ResourceStream(name=yaml_wrong_name.name, stream=stream)

with pytest.raises(EcalcError) as ee:
yaml_reader.load(yaml_file=yaml_stream)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/libecalc/input/test_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def test_dump_yaml_include(self, yaml_resource):
)

dump_yaml = PyYamlYamlModel.dump_and_load_yaml(main_yaml=main_yaml, resources=resources)
assert dump_yaml == yaml_resource.read()
assert dump_yaml == yaml_resource.stream.getvalue()


def valid_ecalc_file(
Expand Down

0 comments on commit 2fd3a2b

Please sign in to comment.