Skip to content

Commit de7e29a

Browse files
committed
test_prepare_spark_location
1 parent 9ffa117 commit de7e29a

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

python/tests/test_feature_group.py

+48-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
)
3333
from hsfs.client.exceptions import FeatureStoreException, RestAPIError
3434
from hsfs.core.constants import HAS_GREAT_EXPECTATIONS
35-
from hsfs.engine import python
35+
from hsfs.engine import python, spark
3636
from hsfs.transformation_function import TransformationType
3737

3838

@@ -908,3 +908,50 @@ def test_from_response_json_transformation_functions(self, backend_fixtures):
908908
assert (
909909
fg.expectation_suite.expectation_suite_name == "test_expectation_suite_name"
910910
)
911+
912+
def test_prepare_spark_location(self, mocker, backend_fixtures):
913+
# Arrange
914+
engine = spark.Engine()
915+
engine_instance = mocker.patch("hsfs.engine.get_instance", return_value=engine)
916+
json = backend_fixtures["feature_group"]["get_basic_info"]["response"]
917+
fg = feature_group.FeatureGroup.from_response_json(json)
918+
fg._location = f"{fg.name}_{fg.version}"
919+
920+
# Act
921+
path = fg.prepare_spark_location()
922+
923+
# Assert
924+
assert fg.location == path
925+
engine_instance.assert_not_called()
926+
927+
def test_prepare_spark_location_with_s3_connector(self, mocker, backend_fixtures):
928+
# Arrange
929+
engine = spark.Engine()
930+
engine_instance = mocker.patch("hsfs.engine.get_instance", return_value=engine)
931+
json = backend_fixtures["feature_group"]["get_basic_info"]["response"]
932+
fg = feature_group.FeatureGroup.from_response_json(json)
933+
fg._location = f"{fg.name}_{fg.version}"
934+
fg._storage_connector = storage_connector.S3Connector(id=1, name="s3_conn", featurestore_id=fg.feature_store_id)
935+
936+
# Act
937+
path = fg.prepare_spark_location()
938+
939+
# Assert
940+
assert fg.location == path
941+
engine_instance.assert_called_once()
942+
943+
def test_prepare_spark_location_with_s3_connector_python(self, mocker, backend_fixtures):
944+
# Arrange
945+
engine = python.Engine()
946+
engine_instance = mocker.patch("hsfs.engine.get_instance", return_value=engine)
947+
json = backend_fixtures["feature_group"]["get_basic_info"]["response"]
948+
fg = feature_group.FeatureGroup.from_response_json(json)
949+
fg._location = f"{fg.name}_{fg.version}"
950+
fg._storage_connector = storage_connector.S3Connector(id=1, name="s3_conn", featurestore_id=fg.feature_store_id)
951+
952+
# Act
953+
with pytest.raises(AttributeError):
954+
fg.prepare_spark_location()
955+
956+
# Assert
957+
engine_instance.assert_called_once()

0 commit comments

Comments
 (0)