|
| 1 | +# --------------------------------------------------------- |
| 2 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +# --------------------------------------------------------- |
| 4 | + |
| 5 | +import pytest |
| 6 | +import json |
| 7 | + |
| 8 | +from azure.ai.ml.entities._assets._artifacts.feature_set import FeatureSet |
| 9 | +from azure.ai.ml.entities._load_functions import load_feature_set |
| 10 | +from azure.ai.ml._restclient.v2023_10_01.models import ( |
| 11 | + FeaturesetContainer, |
| 12 | + FeaturesetContainerProperties, |
| 13 | + FeaturesetVersion, |
| 14 | + FeaturesetVersionProperties, |
| 15 | +) |
| 16 | + |
| 17 | + |
| 18 | +@pytest.mark.unittest |
| 19 | +class TestFeatureSetEntity: |
| 20 | + FEATURE_SET = "./tests/test_configs/feature_set/feature_set_full.yaml" |
| 21 | + FEATURE_SET_REST = "./tests/test_configs/feature_set/feature_set_full_rest.json" |
| 22 | + FEATURE_SET_CONTAINER_REST = "./tests/test_configs/feature_set/feature_set_container_rest.json" |
| 23 | + |
| 24 | + def test_to_rest_object(self) -> None: |
| 25 | + feature_set = load_feature_set(self.FEATURE_SET) |
| 26 | + |
| 27 | + feature_set_rest = feature_set._to_rest_object() |
| 28 | + assert feature_set_rest.properties.description == feature_set.description |
| 29 | + assert feature_set_rest.properties.tags == feature_set.tags |
| 30 | + assert feature_set_rest.properties.entities == feature_set.entities |
| 31 | + assert feature_set_rest.properties.specification.path == feature_set.specification.path |
| 32 | + assert feature_set_rest.properties.stage == feature_set.stage |
| 33 | + assert ( |
| 34 | + str(feature_set_rest.properties.materialization_settings.store_type) == "MaterializationStoreType.OFFLINE" |
| 35 | + ) |
| 36 | + assert ( |
| 37 | + feature_set_rest.properties.materialization_settings.schedule.frequency |
| 38 | + == feature_set.materialization_settings.schedule.frequency |
| 39 | + ) |
| 40 | + assert ( |
| 41 | + feature_set_rest.properties.materialization_settings.schedule.interval |
| 42 | + == feature_set.materialization_settings.schedule.interval |
| 43 | + ) |
| 44 | + assert ( |
| 45 | + feature_set_rest.properties.materialization_settings.spark_configuration |
| 46 | + == feature_set.materialization_settings.spark_configuration |
| 47 | + ) |
| 48 | + assert ( |
| 49 | + feature_set_rest.properties.materialization_settings.resource.instance_type |
| 50 | + == feature_set.materialization_settings.resource.instance_type |
| 51 | + ) |
| 52 | + assert ( |
| 53 | + feature_set_rest.properties.materialization_settings.notification.email_on |
| 54 | + == feature_set.materialization_settings.notification.email_on |
| 55 | + ) |
| 56 | + assert ( |
| 57 | + feature_set_rest.properties.materialization_settings.notification.emails |
| 58 | + == feature_set.materialization_settings.notification.emails |
| 59 | + ) |
| 60 | + |
| 61 | + def test_from_rest_object(self) -> None: |
| 62 | + with open(self.FEATURE_SET_REST, "r") as f: |
| 63 | + feature_set_rest = FeaturesetVersion.deserialize(json.load(f)) |
| 64 | + feature_set = FeatureSet._from_rest_object(featureset_rest_object=feature_set_rest) |
| 65 | + assert feature_set.name == feature_set_rest.name |
| 66 | + assert feature_set.description == feature_set_rest.properties.description |
| 67 | + assert feature_set.tags == feature_set_rest.properties.tags |
| 68 | + assert feature_set.entities == feature_set_rest.properties.entities |
| 69 | + assert feature_set.specification.path == feature_set_rest.properties.specification.path |
| 70 | + assert feature_set.stage == feature_set_rest.properties.stage |
| 71 | + assert ( |
| 72 | + feature_set.materialization_settings.schedule.frequency |
| 73 | + == feature_set_rest.properties.materialization_settings.schedule.frequency.lower() |
| 74 | + ) |
| 75 | + assert ( |
| 76 | + feature_set.materialization_settings.schedule.interval |
| 77 | + == feature_set_rest.properties.materialization_settings.schedule.interval |
| 78 | + ) |
| 79 | + assert ( |
| 80 | + feature_set.materialization_settings.spark_configuration |
| 81 | + == feature_set_rest.properties.materialization_settings.spark_configuration |
| 82 | + ) |
| 83 | + assert ( |
| 84 | + feature_set.materialization_settings.resource.instance_type |
| 85 | + == feature_set_rest.properties.materialization_settings.resource.instance_type |
| 86 | + ) |
| 87 | + assert ( |
| 88 | + feature_set.materialization_settings.notification.email_on |
| 89 | + == feature_set_rest.properties.materialization_settings.notification.email_on |
| 90 | + ) |
| 91 | + assert ( |
| 92 | + feature_set.materialization_settings.notification.emails |
| 93 | + == feature_set_rest.properties.materialization_settings.notification.emails |
| 94 | + ) |
| 95 | + |
| 96 | + def test_from_container_rest_object(self) -> None: |
| 97 | + with open(self.FEATURE_SET_CONTAINER_REST, "r") as f: |
| 98 | + featureset_container_rest = FeaturesetContainer.deserialize(json.load(f)) |
| 99 | + feature_set = FeatureSet._from_container_rest_object(featureset_container_rest) |
| 100 | + assert feature_set.name == featureset_container_rest.name |
| 101 | + assert feature_set.description == featureset_container_rest.properties.description |
| 102 | + assert feature_set.tags == featureset_container_rest.properties.tags |
| 103 | + assert feature_set.entities == [] |
| 104 | + assert feature_set.specification.path == None |
| 105 | + assert feature_set.version == "" |
| 106 | + assert feature_set.latest_version == featureset_container_rest.properties.latest_version |
0 commit comments