Skip to content

Commit

Permalink
Fix bug in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
niknetniko committed Jul 18, 2023
1 parent ce395a7 commit 0ecac74
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tested/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,30 +156,30 @@ class TextChannelType(StrEnum):
FILE = "file" # Path to a file


def _resolve_path(working_directory, file_path):
"""
Resolve a path to an absolute path. Relative paths will be resolved against
the given ``directory``, not the actual working directory.
"""
if path.isabs(file_path):
return path.abspath(file_path)
else:
return path.abspath(path.join(working_directory, file_path))


@dataclass
class TextData(WithFeatures):
"""Describes textual data: either directly or in a file."""

data: str
type: TextChannelType = TextChannelType.TEXT

@staticmethod
def _resolve_path(working_directory, file_path):
"""
Resolve a path to an absolute path. Relative paths will be resolved against
the given ``directory``, not the actual working directory.
"""
if path.isabs(file_path):
return path.abspath(file_path)
else:
return path.abspath(path.join(working_directory, file_path))

def get_data_as_string(self, working_directory: Path) -> str:
"""Get the data as a string, reading the file if necessary."""
if self.type == TextChannelType.TEXT:
return self.data
elif self.type == TextChannelType.FILE:
file_path = self._resolve_path(working_directory, self.data)
file_path = _resolve_path(working_directory, self.data)
with open(file_path, "r") as file:
return file.read()
else:
Expand Down Expand Up @@ -214,7 +214,7 @@ def get_used_features(self) -> FeatureSet:
return NOTHING

def get_data_as_string(self, resources: Path) -> str:
file_path = self._resolve_path(resources, self.expected_path)
file_path = _resolve_path(resources, self.expected_path)
with open(file_path, "r") as file:
return file.read()

Expand Down

0 comments on commit 0ecac74

Please sign in to comment.