This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 1eb3bfe513 Add test cases for ObjectStoragePath 
relative_to/is_relative_to methods (#37770)
1eb3bfe513 is described below

commit 1eb3bfe51347f158e5814ecc34c8e590b07c988b
Author: Andrey Anshin <[email protected]>
AuthorDate: Wed Feb 28 17:07:39 2024 +0400

    Add test cases for ObjectStoragePath relative_to/is_relative_to methods 
(#37770)
---
 tests/io/test_path.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/tests/io/test_path.py b/tests/io/test_path.py
index b631d2ba78..a2f4a59c99 100644
--- a/tests/io/test_path.py
+++ b/tests/io/test_path.py
@@ -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
@@ -200,6 +201,26 @@ class TestFs:
 
         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())}")

Reply via email to