Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions elements/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def write_text(self, content):
def write_bytes(self, content):
self.write(content, mode='wb')

def with_suffix(self, suffix):
path = str(self.parent / self.stem) + suffix
return type(self)(path)

def open(self, mode='r'):
raise NotImplementedError

Expand Down
11 changes: 11 additions & 0 deletions tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,14 @@ def test_parent(self):
assert (empty / 'foo' / 'bar.txt').parent.parent == empty
assert root.parent == root
assert empty.parent == empty

def test_with_suffix(self):
examples = [
('foo.a', '.b', 'foo.b'),
('foo/bar.a.b', '.c', 'foo/bar.c'),
('foo', '.abc', 'foo.abc'),
('foo.xyz', '', 'foo'),
('foo', '', 'foo'),
]
for path, suffix, output in examples:
assert str(elements.Path(path).with_suffix(suffix)) == output