Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#4008] improvement(client-python): Add __init__.py in unittests in client-python (#4009)

noidname01c43d9f5ea6ac
diff --git a/clients/client-python/gravitino/filesystem/gvfs.py b/clients/client-python/gravitino/filesystem/gvfs.py
index f184f0e6f5..f723e781fd 100644
--- a/clients/client-python/gravitino/filesystem/gvfs.py
+++ b/clients/client-python/gravitino/filesystem/gvfs.py
@@ -95,6 +95,10 @@ class GravitinoVirtualFileSystem(fsspec.AbstractFileSystem):
super().__init__(**kwargs)
+ @property
+ def cache(self):
+ return self._cache
+
@property
def fsid(self):
return PROTOCOL_NAME
diff --git a/clients/client-python/tests/unittests/__init__.py b/clients/client-python/tests/unittests/__init__.py
new file mode 100644
index 0000000000..5779a3ad25
--- /dev/null
+++ b/clients/client-python/tests/unittests/__init__.py
@@ -0,0 +1,4 @@
+"""
+Copyright 2024 Datastrato Pvt Ltd.
+This software is licensed under the Apache License version 2.
+"""
diff --git a/clients/client-python/tests/unittests/mock_base.py b/clients/client-python/tests/unittests/mock_base.py
index dd9bc3382f..64bec0b738 100644
--- a/clients/client-python/tests/unittests/mock_base.py
+++ b/clients/client-python/tests/unittests/mock_base.py
@@ -3,14 +3,14 @@ Copyright 2024 Datastrato Pvt Ltd.
This software is licensed under the Apache License version 2.
"""
+from unittest.mock import patch
+
from gravitino import GravitinoMetalake, Catalog, Fileset
from gravitino.catalog.fileset_catalog import FilesetCatalog
from gravitino.dto.fileset_dto import FilesetDTO
from gravitino.dto.audit_dto import AuditDTO
from gravitino.dto.metalake_dto import MetalakeDTO
-from unittest.mock import patch
-
def mock_load_metalake():
audit_dto = AuditDTO(
diff --git a/clients/client-python/tests/unittests/test_gvfs_with_local.py b/clients/client-python/tests/unittests/test_gvfs_with_local.py
index ab967eb6e7..706e0ec11f 100644
--- a/clients/client-python/tests/unittests/test_gvfs_with_local.py
+++ b/clients/client-python/tests/unittests/test_gvfs_with_local.py
@@ -3,16 +3,20 @@ Copyright 2024 Datastrato Pvt Ltd.
This software is licensed under the Apache License version 2.
"""
+# pylint: disable=protected-access
+
import random
import string
import time
import unittest
-import mock_base
+from unittest.mock import patch
+
import pandas
import pyarrow as pa
import pyarrow.dataset as dt
import pyarrow.parquet as pq
-from unittest.mock import patch
+from fsspec.implementations.local import LocalFileSystem
+from llama_index.core import SimpleDirectoryReader
from gravitino import gvfs
from gravitino import NameIdentifier
@@ -20,8 +24,8 @@ from gravitino.dto.audit_dto import AuditDTO
from gravitino.dto.fileset_dto import FilesetDTO
from gravitino.filesystem.gvfs import FilesetContext, StorageType
from gravitino.exceptions.gravitino_runtime_exception import GravitinoRuntimeException
-from fsspec.implementations.local import LocalFileSystem
-from llama_index.core import SimpleDirectoryReader
+
+from tests.unittests import mock_base
def generate_unique_random_string(length):
@@ -53,7 +57,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_cache", f"{_fileset_dir}/test_cache"
),
)
- def test_cache(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_cache(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_cache"
fileset_virtual_location = "fileset/fileset_catalog/tmp/test_cache"
@@ -70,7 +74,7 @@ class TestLocalFilesystem(unittest.TestCase):
# wait 2 seconds
time.sleep(2)
self.assertIsNone(
- fs._cache.get(
+ fs.cache.get(
NameIdentifier.of_fileset(
"metalake_demo", "fileset_catalog", "tmp", "test_cache"
)
@@ -81,7 +85,7 @@ class TestLocalFilesystem(unittest.TestCase):
"gravitino.catalog.fileset_catalog.FilesetCatalog.load_fileset",
return_value=mock_base.mock_load_fileset("test_ls", f"{_fileset_dir}/test_ls"),
)
- def test_ls(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_ls(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_ls"
fileset_virtual_location = "fileset/fileset_catalog/tmp/test_ls"
@@ -127,7 +131,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_info", f"{_fileset_dir}/test_info"
),
)
- def test_info(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_info(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_info"
fileset_virtual_location = "fileset/fileset_catalog/tmp/test_info"
@@ -158,7 +162,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_exist", f"{_fileset_dir}/test_exist"
),
)
- def test_exist(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_exist(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_exist"
fileset_virtual_location = "fileset/fileset_catalog/tmp/test_exist"
@@ -187,7 +191,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_cp_file", f"{_fileset_dir}/test_cp_file"
),
)
- def test_cp_file(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_cp_file(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_cp_file"
local_fs.mkdir(fileset_storage_location)
@@ -234,7 +238,7 @@ class TestLocalFilesystem(unittest.TestCase):
"gravitino.catalog.fileset_catalog.FilesetCatalog.load_fileset",
return_value=mock_base.mock_load_fileset("test_mv", f"{_fileset_dir}/test_mv"),
)
- def test_mv(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_mv(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_mv"
local_fs.mkdir(fileset_storage_location)
@@ -291,7 +295,7 @@ class TestLocalFilesystem(unittest.TestCase):
"gravitino.catalog.fileset_catalog.FilesetCatalog.load_fileset",
return_value=mock_base.mock_load_fileset("test_rm", f"{_fileset_dir}/test_rm"),
)
- def test_rm(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_rm(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_rm"
local_fs.mkdir(fileset_storage_location)
@@ -333,7 +337,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_rm_file", f"{_fileset_dir}/test_rm_file"
),
)
- def test_rm_file(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_rm_file(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_rm_file"
local_fs.mkdir(fileset_storage_location)
@@ -371,7 +375,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_rmdir", f"{_fileset_dir}/test_rmdir"
),
)
- def test_rmdir(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_rmdir(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_rmdir"
local_fs.mkdir(fileset_storage_location)
@@ -409,7 +413,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_open", f"{_fileset_dir}/test_open"
),
)
- def test_open(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_open(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_open"
local_fs.mkdir(fileset_storage_location)
@@ -452,7 +456,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_mkdir", f"{_fileset_dir}/test_mkdir"
),
)
- def test_mkdir(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_mkdir(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_mkdir"
local_fs.mkdir(fileset_storage_location)
@@ -492,7 +496,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_makedirs", f"{_fileset_dir}/test_makedirs"
),
)
- def test_makedirs(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_makedirs(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_makedirs"
local_fs.mkdir(fileset_storage_location)
@@ -526,7 +530,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_created", f"{_fileset_dir}/test_created"
),
)
- def test_created(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_created(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_created"
local_fs.mkdir(fileset_storage_location)
@@ -553,7 +557,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_modified", f"{_fileset_dir}/test_modified"
),
)
- def test_modified(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_modified(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_modified"
local_fs.mkdir(fileset_storage_location)
@@ -580,7 +584,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_cat_file", f"{_fileset_dir}/test_cat_file"
),
)
- def test_cat_file(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_cat_file(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_cat_file"
local_fs.mkdir(fileset_storage_location)
@@ -623,7 +627,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_get_file", f"{_fileset_dir}/test_get_file"
),
)
- def test_get_file(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_get_file(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_get_file"
local_fs.mkdir(fileset_storage_location)
@@ -669,7 +673,7 @@ class TestLocalFilesystem(unittest.TestCase):
with self.assertRaises(GravitinoRuntimeException):
fs.get_file(file_virtual_path, remote_path)
- def test_convert_actual_path(self, mock_method1, mock_method2, mock_method3):
+ def test_convert_actual_path(self, *mock_methods):
# test convert actual hdfs path
audit_dto = AuditDTO(
_creator="test",
@@ -750,7 +754,7 @@ class TestLocalFilesystem(unittest.TestCase):
"fileset/test_catalog/test_schema/test_f1/actual_path", virtual_path
)
- def test_convert_info(self, mock_method1, mock_method2, mock_method3):
+ def test_convert_info(self, *mock_methods3):
# test convert actual hdfs path
audit_dto = AuditDTO(
_creator="test",
@@ -831,7 +835,7 @@ class TestLocalFilesystem(unittest.TestCase):
"fileset/test_catalog/test_schema/test_f1/actual_path", virtual_path
)
- def test_extract_identifier(self, mock_method1, mock_method2, mock_method3):
+ def test_extract_identifier(self, *mock_methods):
fs = gvfs.GravitinoVirtualFileSystem(
server_uri="http://localhost:9090", metalake_name="metalake_demo"
)
@@ -855,7 +859,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_pandas", f"{_fileset_dir}/test_pandas"
),
)
- def test_pandas(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_pandas(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_pandas"
local_fs.mkdir(fileset_storage_location)
@@ -898,7 +902,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_pyarrow", f"{_fileset_dir}/test_pyarrow"
),
)
- def test_pyarrow(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_pyarrow(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_pyarrow"
local_fs.mkdir(fileset_storage_location)
@@ -934,7 +938,7 @@ class TestLocalFilesystem(unittest.TestCase):
"test_llama_index", f"{_fileset_dir}/test_llama_index"
),
)
- def test_llama_index(self, mock_method1, mock_method2, mock_method3, mock_method4):
+ def test_llama_index(self, *mock_methods):
local_fs = LocalFileSystem()
fileset_storage_location = f"{self._fileset_dir}/test_llama_index"
local_fs.mkdir(fileset_storage_location)
diff --git a/clients/client-python/tests/unittests/test_metalake.py b/clients/client-python/tests/unittests/test_metalake.py
index 3c465a2530..dde4ac6a7b 100644
--- a/clients/client-python/tests/unittests/test_metalake.py
+++ b/clients/client-python/tests/unittests/test_metalake.py
@@ -17,10 +17,10 @@ class TestMetalake(unittest.TestCase):
)
metalake_response = MetalakeResponse.from_json(str_json, infer_missing=True)
self.assertEqual(metalake_response.code(), 0)
- self.assertIsNotNone(metalake_response._metalake)
- self.assertEqual(metalake_response._metalake.name(), "example_name18")
+ self.assertIsNotNone(metalake_response.metalake())
+ self.assertEqual(metalake_response.metalake().name(), "example_name18")
self.assertEqual(
- metalake_response._metalake.audit_info().creator(), "anonymous"
+ metalake_response.metalake().audit_info().creator(), "anonymous"
)
def test_from_error_json_metalake_response(self):
@@ -32,8 +32,8 @@ class TestMetalake(unittest.TestCase):
)
metalake_response = MetalakeResponse.from_json(str_json, infer_missing=True)
self.assertEqual(metalake_response.code(), 0)
- self.assertIsNotNone(metalake_response._metalake)
- self.assertEqual(metalake_response._metalake.name(), "example_name18")
+ self.assertIsNotNone(metalake_response.metalake())
+ self.assertEqual(metalake_response.metalake().name(), "example_name18")
self.assertEqual(
- metalake_response._metalake.audit_info().creator(), "anonymous"
+ metalake_response.metalake().audit_info().creator(), "anonymous"
)