Files
trainer/pkg/initializers/utils/utils_test.py
T
Tariq HasanandGitHub 9183dfd24f chore(scripts): add copyright boilerplate verification (#3359)
* chore(scripts): add copyright boilerplate verification system

Signed-off-by: tariq-hasan <[email protected]>

* chore(ci): add boilerplate verification to CI pipeline

Signed-off-by: tariq-hasan <[email protected]>

* chore: regenerate files with year-less copyright headers

Signed-off-by: tariq-hasan <[email protected]>

* refactor(boilerplate): simplify verification logic

Signed-off-by: tariq-hasan <[email protected]>

* chore(boilerplate): add missing copyright headers

Signed-off-by: tariq-hasan <[email protected]>

* ci(boilerplate): move verifier to code-quality workflow and run unit tests

Signed-off-by: tariq-hasan <[email protected]>

* feat(boilerplate): accept license headers with any year and remove year validation logic

Signed-off-by: tariq-hasan <[email protected]>

* feat(boilerplate): add copyright headers to generated Python API

Signed-off-by: tariq-hasan <[email protected]>

* refactor(boilerplate): use block-comment header for generated Go files

Signed-off-by: tariq-hasan <[email protected]>

* feat(boilerplate): verify copyright headers in Rust files

Signed-off-by: tariq-hasan <[email protected]>

---------

Signed-off-by: tariq-hasan <[email protected]>
2026-05-29 10:50:56 +00:00

154 lines
5.1 KiB
Python

# Copyright The Kubeflow Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
import pkg.initializers.types.types as types
import pkg.initializers.utils.utils as utils
@pytest.mark.parametrize(
"config_class,env_vars,expected",
[
(
types.HuggingFaceModelInitializer,
{
"STORAGE_URI": "hf://test",
"IGNORE_PATTERNS": "*.msgpack,*.h5",
"ACCESS_TOKEN": "token",
},
{
"storage_uri": "hf://test",
"ignore_patterns": ["*.msgpack", "*.h5"],
"access_token": "token",
},
),
(
types.HuggingFaceModelInitializer,
{"STORAGE_URI": "hf://test"},
{
"storage_uri": "hf://test",
"ignore_patterns": None,
"access_token": None,
},
),
(
types.HuggingFaceDatasetInitializer,
{
"STORAGE_URI": "hf://test",
"IGNORE_PATTERNS": "*.log,*.txt",
"ACCESS_TOKEN": "token",
},
{
"storage_uri": "hf://test",
"ignore_patterns": ["*.log", "*.txt"],
"access_token": "token",
},
),
(
types.HuggingFaceDatasetInitializer,
{"STORAGE_URI": "hf://test"},
{"storage_uri": "hf://test", "ignore_patterns": None, "access_token": None},
),
(
types.S3DatasetInitializer,
{
"STORAGE_URI": "s3://bucket/path",
"ENDPOINT": "https://s3.amazonaws.com",
"ACCESS_KEY_ID": "test_key",
"SECRET_ACCESS_KEY": "test_secret",
"REGION": "us-east-1",
"ROLE_ARN": "arn:aws:iam::123456789012:role/TestRole",
},
{
"storage_uri": "s3://bucket/path",
"ignore_patterns": None,
"endpoint": "https://s3.amazonaws.com",
"access_key_id": "test_key",
"secret_access_key": "test_secret",
"region": "us-east-1",
"role_arn": "arn:aws:iam::123456789012:role/TestRole",
},
),
(
types.S3DatasetInitializer,
{"STORAGE_URI": "s3://bucket/path"},
{
"storage_uri": "s3://bucket/path",
"ignore_patterns": None,
"endpoint": None,
"access_key_id": None,
"secret_access_key": None,
"region": None,
"role_arn": None,
},
),
(
types.S3DatasetInitializer,
{
"STORAGE_URI": "s3://bucket/path",
"ACCESS_KEY_ID": "test_key",
"SECRET_ACCESS_KEY": "test_secret",
},
{
"storage_uri": "s3://bucket/path",
"ignore_patterns": None,
"endpoint": None,
"access_key_id": "test_key",
"secret_access_key": "test_secret",
"region": None,
"role_arn": None,
},
),
(
types.S3ModelInitializer,
{
"STORAGE_URI": "s3://bucket/path",
"IGNORE_PATTERNS": "*.log,*.txt",
"ENDPOINT": "https://s3.amazonaws.com",
"ACCESS_KEY_ID": "test_key",
"SECRET_ACCESS_KEY": "test_secret",
"REGION": "us-east-1",
"ROLE_ARN": "arn:aws:iam::123456789012:role/TestRole",
},
{
"storage_uri": "s3://bucket/path",
"ignore_patterns": ["*.log", "*.txt"],
"endpoint": "https://s3.amazonaws.com",
"access_key_id": "test_key",
"secret_access_key": "test_secret",
"region": "us-east-1",
"role_arn": "arn:aws:iam::123456789012:role/TestRole",
},
),
(
types.S3ModelInitializer,
{"STORAGE_URI": "s3://bucket/path"},
{
"storage_uri": "s3://bucket/path",
"ignore_patterns": None,
"endpoint": None,
"access_key_id": None,
"secret_access_key": None,
"region": None,
"role_arn": None,
},
),
],
)
def test_get_config_from_env(mock_env_vars, config_class, env_vars, expected):
mock_env_vars(**env_vars)
result = utils.get_config_from_env(config_class)
assert result == expected