-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/migrate to pydantic v2 (#176)
* Assign default values to fields, update grouping config cls field validator. * Skip validating invalid grouping config in the test. * Fix order of fields in grouping config. * Fix how the test config is accessed. * Cleanup old values from test config. * Specify that pydantic version should be smaller than 3. * Update changelog.
- Loading branch information
1 parent
1d3645c
commit 59075c0
Showing
11 changed files
with
181 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,9 @@ | |
description: "My awesome pipeline" | ||
service_account: [email protected] | ||
grouping: | ||
cls: kedro_vertexai.grouping.IdentityNodeGrouper | ||
cls: "kedro_vertexai.grouping.IdentityNodeGrouper" | ||
params: | ||
tag_prefix: "group." | ||
ttl: 300 | ||
network: | ||
vpc: my-vpc | ||
|
@@ -49,26 +51,25 @@ | |
|
||
class TestPluginConfig(unittest.TestCase): | ||
def test_grouping_config(self): | ||
cfg = PluginConfig.parse_obj(yaml.safe_load(CONFIG_MINIMAL)) | ||
cfg = PluginConfig.model_validate(yaml.safe_load(CONFIG_MINIMAL)) | ||
assert cfg.run_config.grouping is not None | ||
assert ( | ||
cfg.run_config.grouping.cls == "kedro_vertexai.grouping.IdentityNodeGrouper" | ||
) | ||
c_obj = dynamic_init_class(cfg.run_config.grouping.cls, None) | ||
assert isinstance(c_obj, IdentityNodeGrouper) | ||
|
||
cfg_tag_group = """ | ||
project_id: some-project | ||
region: some-region | ||
run_config: | ||
image: test | ||
experiment_name: test | ||
grouping: | ||
cls: "kedro_vertexai.grouping.TagNodeGrouper" | ||
cls: kedro_vertexai.grouping.TagNodeGrouper | ||
params: | ||
tag_prefix: "group." | ||
""" | ||
cfg = PluginConfig.parse_obj(yaml.safe_load(cfg_tag_group)) | ||
cfg = PluginConfig.model_validate(yaml.safe_load(cfg_tag_group)) | ||
assert cfg.run_config.grouping is not None | ||
c_obj = dynamic_init_class( | ||
cfg.run_config.grouping.cls, None, **cfg.run_config.grouping.params | ||
|
@@ -89,16 +90,18 @@ def test_grouping_config_error(self, log_error): | |
params: | ||
foo: "bar:" | ||
""" | ||
cfg = PluginConfig.parse_obj(yaml.safe_load(cfg_tag_group)) | ||
cfg = yaml.safe_load(cfg_tag_group) | ||
c = dynamic_init_class( | ||
cfg.run_config.grouping.cls, None, **cfg.run_config.grouping.params | ||
cfg["run_config"]["grouping"]["cls"], | ||
None, | ||
**cfg["run_config"]["grouping"]["params"] | ||
) | ||
assert c is None | ||
log_error.assert_called_once() | ||
|
||
def test_plugin_config(self): | ||
obj = yaml.safe_load(CONFIG_FULL) | ||
cfg = PluginConfig.parse_obj(obj) | ||
cfg = PluginConfig.model_validate(obj) | ||
assert cfg.run_config.image == "gcr.io/project-image/test" | ||
assert cfg.run_config.experiment_name == "Test Experiment" | ||
assert cfg.run_config.experiment_description == "Test Experiment Description." | ||
|
@@ -116,16 +119,16 @@ def test_plugin_config(self): | |
assert cfg.run_config.ttl == 300 | ||
|
||
def test_defaults(self): | ||
cfg = PluginConfig.parse_obj(yaml.safe_load(CONFIG_MINIMAL)) | ||
cfg = PluginConfig.model_validate(yaml.safe_load(CONFIG_MINIMAL)) | ||
assert cfg.run_config.description is None | ||
assert cfg.run_config.ttl == 3600 * 24 * 7 | ||
|
||
def test_missing_required_config(self): | ||
with self.assertRaises(ValidationError): | ||
PluginConfig.parse_obj({}) | ||
PluginConfig.model_validate({}) | ||
|
||
def test_resources_default_only(self): | ||
cfg = PluginConfig.parse_obj(yaml.safe_load(CONFIG_MINIMAL)) | ||
cfg = PluginConfig.model_validate(yaml.safe_load(CONFIG_MINIMAL)) | ||
assert cfg.run_config.resources_for("node2") == { | ||
"cpu": "500m", | ||
"gpu": None, | ||
|
@@ -138,7 +141,7 @@ def test_resources_default_only(self): | |
} | ||
|
||
def test_node_selectors_default_only(self): | ||
cfg = PluginConfig.parse_obj(yaml.safe_load(CONFIG_MINIMAL)) | ||
cfg = PluginConfig.model_validate(yaml.safe_load(CONFIG_MINIMAL)) | ||
assert cfg.run_config.node_selectors_for("node2") == {} | ||
assert cfg.run_config.node_selectors_for("node3") == {} | ||
|
||
|
@@ -147,7 +150,7 @@ def test_resources_no_default(self): | |
obj["run_config"].update( | ||
{"resources": {"__default__": {"cpu": None, "memory": None}}} | ||
) | ||
cfg = PluginConfig.parse_obj(obj) | ||
cfg = PluginConfig.model_validate(obj) | ||
assert cfg.run_config.resources_for("node2") == { | ||
"cpu": None, | ||
"gpu": None, | ||
|
@@ -164,7 +167,7 @@ def test_resources_default_and_node_specific(self): | |
} | ||
} | ||
) | ||
cfg = PluginConfig.parse_obj(obj) | ||
cfg = PluginConfig.model_validate(obj) | ||
assert cfg.run_config.resources_for("node2") == { | ||
"cpu": "100m", | ||
"gpu": None, | ||
|
@@ -186,7 +189,7 @@ def test_resources_default_and_tag_specific(self): | |
} | ||
} | ||
) | ||
cfg = PluginConfig.parse_obj(obj) | ||
cfg = PluginConfig.model_validate(obj) | ||
assert cfg.run_config.resources_for("node2", {"tag1"}) == { | ||
"cpu": "100m", | ||
"gpu": "2", | ||
|
@@ -209,7 +212,7 @@ def test_resources_node_and_tag_specific(self): | |
} | ||
} | ||
) | ||
cfg = PluginConfig.parse_obj(obj) | ||
cfg = PluginConfig.model_validate(obj) | ||
assert cfg.run_config.resources_for("node2", {"tag1"}) == { | ||
"cpu": "300m", | ||
"gpu": "2", | ||
|
@@ -226,7 +229,7 @@ def test_node_selectors_node_and_tag_specific(self): | |
} | ||
} | ||
) | ||
cfg = PluginConfig.parse_obj(obj) | ||
cfg = PluginConfig.model_validate(obj) | ||
assert cfg.run_config.node_selectors_for("node2", {"tag1"}) == { | ||
"cloud.google.com/gke-accelerator": "NVIDIA_TESLA_K80", | ||
} | ||
|
@@ -246,7 +249,7 @@ def test_parse_network_config(self): | |
} | ||
} | ||
) | ||
cfg = PluginConfig.parse_obj(obj) | ||
cfg = PluginConfig.model_validate(obj) | ||
assert ( | ||
cfg.run_config.network.vpc | ||
== "projects/some-project-id/global/networks/some-vpc-name" | ||
|
@@ -255,15 +258,15 @@ def test_parse_network_config(self): | |
assert "mlflow.internal" in cfg.run_config.network.host_aliases[0].hostnames | ||
|
||
def test_accept_default_vertex_ai_networking_config(self): | ||
cfg = PluginConfig.parse_obj(yaml.safe_load(CONFIG_MINIMAL)) | ||
cfg = PluginConfig.model_validate(yaml.safe_load(CONFIG_MINIMAL)) | ||
assert cfg.run_config.network.vpc is None | ||
assert cfg.run_config.network.host_aliases == [] | ||
|
||
@unittest.skip( | ||
"Scheduling feature is temporarily disabled https://github.com/getindata/kedro-vertexai/issues/4" | ||
) | ||
def test_reuse_run_name_for_scheduled_run_name(self): | ||
cfg = PluginConfig.parse_obj( | ||
cfg = PluginConfig.model_validate( | ||
{ | ||
"run_config": { | ||
"scheduled_run_name": "some run", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.