Skip to content

Commit 8cce79f

Browse files
committed
add unit test
1 parent fb50755 commit 8cce79f

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

ads/feature_store/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ def _update_from_oci_dataset_model(self, oci_dataset: OCIDataset) -> "Dataset":
785785
for infra_attr, dsc_attr in self.attribute_map.items():
786786
if infra_attr in dataset_details:
787787
if infra_attr == self.CONST_OUTPUT_FEATURE_DETAILS:
788-
# May not need if we fix the backend and add feature_group_id to the output_feature
788+
# May not need if we fix the backend and add dataset_id to the output_feature
789789
features_list = []
790790
for output_feature in dataset_details[infra_attr]["items"]:
791791
output_feature["datasetId"] = dataset_details[self.CONST_ID]

tests/unitary/with_extras/feature_store/test_feature_group.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from ads.feature_store.feature_store import FeatureStore
2121
from ads.feature_store.input_feature_detail import FeatureDetail, FeatureType
2222
from ads.feature_store.service.oci_feature_group import OCIFeatureGroup
23+
from ads.feature_store.service.oci_feature_group_job import OCIFeatureGroupJob
2324
from ads.feature_store.service.oci_feature_store import OCIFeatureStore
2425
from tests.unitary.with_extras.feature_store.test_feature_group_job import (
2526
FEATURE_GROUP_JOB_PAYLOAD,
@@ -44,6 +45,14 @@
4445
"isInferSchema": False,
4546
}
4647

48+
FEATURE_GROUP_JOB_RESPONSE_PAYLOAD = {
49+
"compartmentId": "ocid1.compartment.oc1.iad.xxx",
50+
"featureGroupId": "861AA4E9C8E811A79D74C464A01CDF42",
51+
"id": "d40265b7-d66e-49a3-ae26-699012e0df5d",
52+
"ingestionMode": "OVERWRITE",
53+
"lifecycleState": "SUCCEEDED",
54+
}
55+
4756

4857
@pytest.fixture(autouse=True)
4958
def dataframe_fixture_basic():
@@ -211,14 +220,14 @@ def test_from_id(self, mock_oci_from_id, mock__update_from_oci_fs_model):
211220

212221
@patch.object(OCIFeatureGroup, "create")
213222
def test_create_success(
214-
self,
215-
mock_oci_dsc_model_create,
223+
self,
224+
mock_oci_dsc_model_create,
216225
):
217226
"""Tests creating datascience feature_group."""
218227
oci_dsc_model = OCIFeatureGroup(**FEATURE_GROUP_PAYLOAD)
219228
mock_oci_dsc_model_create.return_value = oci_dsc_model
220229

221-
# to check rundom display name
230+
# to check random display name
222231
self.mock_dsc_feature_group.with_name("")
223232
result = self.mock_dsc_feature_group.create()
224233
mock_oci_dsc_model_create.assert_called()
@@ -281,7 +290,7 @@ def test__to_oci_fs_entity(self, mock_load_key_file, mock_config_from_file):
281290
@patch.object(SparkSessionSingleton, "__init__", return_value=None)
282291
@patch.object(SparkSessionSingleton, "get_spark_session")
283292
def test_materialise(
284-
self, spark_session, get_spark_session, mocke_update, dataframe_fixture_basic
293+
self, spark_session, get_spark_session, mocke_update, dataframe_fixture_basic
285294
):
286295
with patch.object(FeatureGroupJob, "create") as mock_feature_group_job:
287296
with patch.object(FeatureStore, "from_id"):
@@ -324,10 +333,20 @@ def test_history(self, feature_store, spark_session, get_spark_session):
324333
@patch.object(SparkSessionSingleton, "get_spark_session")
325334
@patch.object(OCIFeatureStore, "from_id")
326335
def test_restore(
327-
self, feature_store, spark_session, get_spark_session, mock_update
336+
self, feature_store, spark_session, get_spark_session, mock_update
328337
):
329338
with patch.object(SparkEngine, "sql") as mock_execution_strategy:
330339
mock_execution_strategy.return_value = None
331340
self.mock_dsc_feature_group.with_id(FEATURE_GROUP_OCID)
332341
self.mock_dsc_feature_group.restore(1)
333342
mock_execution_strategy.assert_called_once()
343+
344+
def test_get_last_job(self):
345+
"""Tests getting most recent feature group job for a feature group."""
346+
with patch.object(FeatureGroupJob, "list") as mock_feature_group_job:
347+
self.mock_dsc_feature_group.with_id(FEATURE_GROUP_OCID)
348+
mock_feature_group_job.return_value = [
349+
FeatureGroupJob.from_dict({"spec": FEATURE_GROUP_JOB_RESPONSE_PAYLOAD})
350+
]
351+
fg_job = self.mock_dsc_feature_group.get_last_job()
352+
assert fg_job is not None

0 commit comments

Comments
 (0)