Skip to content

Commit

Permalink
#158: Implemented operator __eq__ for BucketPath to compare string r…
Browse files Browse the repository at this point in the history
…epresentation (#159)

* #158: Implemented operator `__eq__` for BucketPath to compare string representation

* Added negative test
  • Loading branch information
ckunki authored Aug 12, 2024
1 parent 1f0f53f commit c9e203d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Unreleased

## Bugfixes

* #158: Implemented operator `__eq__` for BucketPath to compare string representation
5 changes: 5 additions & 0 deletions exasol/bucketfs/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@ def __truediv__(self, other):
new_path = self._path / (other._path if isinstance(other, cls) else other)
return cls(new_path, self._bucket_api)

def __eq__(self, other) -> bool:
if not isinstance(other, BucketPath):
return False
return (self._path, self._bucket_api) == (other._path, other._bucket_api)

def __str__(self):
return str(self._path)

Expand Down
13 changes: 13 additions & 0 deletions test/unit/test_bucket_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,16 @@ def test_write_and_create_parent(bucket_fake):
def test_archive_as_udf_path(bucket_fake):
path = bfs.path.BucketPath('container/my_container.tar.gz', bucket_api=bucket_fake)
assert path.as_udf_path().endswith('container/my_container')


@pytest.mark.parametrize(
"file1,file2,expectation",
[
('a.txt', 'b.txt', False),
('a.txt', 'a.txt', True),
])
def test_eq(bucket_fake, file1, file2, expectation):
path = bfs.path.BucketPath('dir', bucket_api=bucket_fake)
a = path / file1
b = path / file2
assert (a == b) == expectation

0 comments on commit c9e203d

Please sign in to comment.