Skip to content

Commit

Permalink
Merge pull request #215 from pyiron/file_object_str
Browse files Browse the repository at this point in the history
File object str
  • Loading branch information
samwaseda committed Mar 8, 2024
2 parents 5fa11b2 + 609d410 commit bb326ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pyiron_workflow/snippets/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def is_file(self):
def delete(self):
self.path.unlink()

def __str__(self):
return str(self.path.absolute())

def _resolve_directory_and_path(
self,
file_name: str,
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/snippets/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ def test_copy(self):
f.copy()


def test_str(self):
f = FileObject("test_copy.txt", self.directory)
if platform.system() == "Windows":
txt = f"my file: {self.directory.path.absolute()}\\test_copy.txt"
else:
txt = f"my file: {self.directory.path.absolute()}/test_copy.txt"
self.assertEqual(f"my file: {f}", txt)

if __name__ == '__main__':
unittest.main()

0 comments on commit bb326ec

Please sign in to comment.