Skip to content

Commit

Permalink
Add test cases for ObjectStoragePath relative_to/is_relative_to metho…
Browse files Browse the repository at this point in the history
…ds (apache#37770)
  • Loading branch information
Taragolis authored Feb 28, 2024
1 parent 382a961 commit 1eb3bfe
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/io/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# under the License.
from __future__ import annotations

import sys
import uuid
from stat import S_ISDIR, S_ISREG
from tempfile import NamedTemporaryFile
Expand Down Expand Up @@ -200,6 +201,26 @@ def test_replace(self):

e.unlink()

@pytest.mark.skipif(sys.version_info < (3, 9), reason="`is_relative_to` new in version 3.9")
def test_is_relative_to(self):
uuid_dir = f"/tmp/{str(uuid.uuid4())}"
o1 = ObjectStoragePath(f"file://{uuid_dir}/aaa")
o2 = ObjectStoragePath(f"file://{uuid_dir}")
o3 = ObjectStoragePath(f"file://{str(uuid.uuid4())}")
assert o1.is_relative_to(o2)
assert not o1.is_relative_to(o3)

def test_relative_to(self):
uuid_dir = f"/tmp/{str(uuid.uuid4())}"
o1 = ObjectStoragePath(f"file://{uuid_dir}/aaa")
o2 = ObjectStoragePath(f"file://{uuid_dir}")
o3 = ObjectStoragePath(f"file://{str(uuid.uuid4())}")

_ = o1.relative_to(o2) # Should not raise any error

with pytest.raises(ValueError):
o1.relative_to(o3)

def test_move_local(self):
_from = ObjectStoragePath(f"file:///tmp/{str(uuid.uuid4())}")
_to = ObjectStoragePath(f"file:///tmp/{str(uuid.uuid4())}")
Expand Down

0 comments on commit 1eb3bfe

Please sign in to comment.