11# -*- coding: utf-8 -*-
2- # Copyright 2022 Google LLC
2+ # Copyright 2023 Google LLC
33#
44# Licensed under the Apache License, Version 2.0 (the "License");
55# you may not use this file except in compliance with the License.
2222from unittest import mock
2323from unittest .mock import patch
2424
25+ import constants as test_constants
26+
2527from google .protobuf import duration_pb2 # type: ignore
2628from google .rpc import status_pb2
2729
28- import test_training_jobs
29- from test_training_jobs import ( # noqa: F401
30- mock_python_package_to_gcs ,
31- )
32-
3330from google .cloud import aiplatform
3431from google .cloud .aiplatform import base
3532from google .cloud .aiplatform .compat .types import (
7976
8077_TEST_PYTHON_PACKAGE_SPEC = gca_custom_job_compat .PythonPackageSpec (
8178 executor_image_uri = _TEST_PREBUILT_CONTAINER_IMAGE ,
82- package_uris = [test_training_jobs ._TEST_OUTPUT_PYTHON_PACKAGE_PATH ],
83- python_module = test_training_jobs ._TEST_MODULE_NAME ,
79+ package_uris = [test_constants . TrainingJobConstants ._TEST_OUTPUT_PYTHON_PACKAGE_PATH ],
80+ python_module = test_constants . TrainingJobConstants ._TEST_MODULE_NAME ,
8481)
8582
8683_TEST_CONTAINER_SPEC = gca_custom_job_compat .ContainerSpec (
8986 "sh" ,
9087 "-c" ,
9188 "pip install --upgrade pip && "
92- + f"pip3 install -q --user { test_training_jobs ._TEST_OUTPUT_PYTHON_PACKAGE_PATH } && " .replace (
89+ + f"pip3 install -q --user { test_constants . TrainingJobConstants ._TEST_OUTPUT_PYTHON_PACKAGE_PATH } && " .replace (
9390 "gs://" , "/gcs/"
9491 )
95- + f"python3 -m { test_training_jobs ._TEST_MODULE_NAME } " ,
92+ + f"python3 -m { test_constants . TrainingJobConstants ._TEST_MODULE_NAME } " ,
9693 ],
9794)
9895
@@ -615,7 +612,7 @@ def test_create_from_local_script_prebuilt_container(
615612 # configuration on this is tested in test_training_jobs.py
616613 job = aiplatform .CustomJob .from_local_script (
617614 display_name = _TEST_DISPLAY_NAME ,
618- script_path = test_training_jobs ._TEST_LOCAL_SCRIPT_FILE_NAME ,
615+ script_path = test_constants . TrainingJobConstants ._TEST_LOCAL_SCRIPT_FILE_NAME ,
619616 container_uri = _TEST_PREBUILT_CONTAINER_IMAGE ,
620617 base_output_dir = _TEST_BASE_OUTPUT_DIR ,
621618 labels = _TEST_LABELS ,
@@ -649,7 +646,7 @@ def test_create_from_local_script_custom_container(
649646 # configuration on this is tested in test_training_jobs.py
650647 job = aiplatform .CustomJob .from_local_script (
651648 display_name = _TEST_DISPLAY_NAME ,
652- script_path = test_training_jobs ._TEST_LOCAL_SCRIPT_FILE_NAME ,
649+ script_path = test_constants . TrainingJobConstants ._TEST_LOCAL_SCRIPT_FILE_NAME ,
653650 container_uri = _TEST_TRAINING_CONTAINER_IMAGE ,
654651 base_output_dir = _TEST_BASE_OUTPUT_DIR ,
655652 labels = _TEST_LABELS ,
@@ -681,7 +678,7 @@ def test_create_from_local_script_raises_with_no_staging_bucket(
681678 # configuration on this is tested in test_training_jobs.py
682679 job = aiplatform .CustomJob .from_local_script ( # noqa: F841
683680 display_name = _TEST_DISPLAY_NAME ,
684- script_path = test_training_jobs ._TEST_LOCAL_SCRIPT_FILE_NAME ,
681+ script_path = test_constants . TrainingJobConstants ._TEST_LOCAL_SCRIPT_FILE_NAME ,
685682 container_uri = _TEST_TRAINING_CONTAINER_IMAGE ,
686683 )
687684
@@ -700,20 +697,20 @@ def test_create_from_local_script_prebuilt_container_with_all_args(
700697 # configuration on this is tested in test_training_jobs.py
701698 job = aiplatform .CustomJob .from_local_script (
702699 display_name = _TEST_DISPLAY_NAME ,
703- script_path = test_training_jobs ._TEST_LOCAL_SCRIPT_FILE_NAME ,
700+ script_path = test_constants . TrainingJobConstants ._TEST_LOCAL_SCRIPT_FILE_NAME ,
704701 container_uri = _TEST_PREBUILT_CONTAINER_IMAGE ,
705702 args = _TEST_RUN_ARGS ,
706- requirements = test_training_jobs ._TEST_REQUIREMENTS ,
707- environment_variables = test_training_jobs ._TEST_ENVIRONMENT_VARIABLES ,
708- replica_count = test_training_jobs ._TEST_REPLICA_COUNT ,
709- machine_type = test_training_jobs ._TEST_MACHINE_TYPE ,
710- accelerator_type = test_training_jobs ._TEST_ACCELERATOR_TYPE ,
711- accelerator_count = test_training_jobs ._TEST_ACCELERATOR_COUNT ,
712- boot_disk_type = test_training_jobs ._TEST_BOOT_DISK_TYPE ,
713- boot_disk_size_gb = test_training_jobs ._TEST_BOOT_DISK_SIZE_GB ,
714- reduction_server_replica_count = test_training_jobs ._TEST_REDUCTION_SERVER_REPLICA_COUNT ,
715- reduction_server_machine_type = test_training_jobs ._TEST_REDUCTION_SERVER_MACHINE_TYPE ,
716- reduction_server_container_uri = test_training_jobs ._TEST_REDUCTION_SERVER_CONTAINER_URI ,
703+ requirements = test_constants . TrainingJobConstants ._TEST_REQUIREMENTS ,
704+ environment_variables = test_constants . TrainingJobConstants ._TEST_ENVIRONMENT_VARIABLES ,
705+ replica_count = test_constants . TrainingJobConstants ._TEST_REPLICA_COUNT ,
706+ machine_type = test_constants . TrainingJobConstants ._TEST_MACHINE_TYPE ,
707+ accelerator_type = test_constants . TrainingJobConstants ._TEST_ACCELERATOR_TYPE ,
708+ accelerator_count = test_constants . TrainingJobConstants ._TEST_ACCELERATOR_COUNT ,
709+ boot_disk_type = test_constants . TrainingJobConstants ._TEST_BOOT_DISK_TYPE ,
710+ boot_disk_size_gb = test_constants . TrainingJobConstants ._TEST_BOOT_DISK_SIZE_GB ,
711+ reduction_server_replica_count = test_constants . TrainingJobConstants ._TEST_REDUCTION_SERVER_REPLICA_COUNT ,
712+ reduction_server_machine_type = test_constants . TrainingJobConstants ._TEST_REDUCTION_SERVER_MACHINE_TYPE ,
713+ reduction_server_container_uri = test_constants . TrainingJobConstants ._TEST_REDUCTION_SERVER_CONTAINER_URI ,
717714 base_output_dir = _TEST_BASE_OUTPUT_DIR ,
718715 labels = _TEST_LABELS ,
719716 )
@@ -722,7 +719,7 @@ def test_create_from_local_script_prebuilt_container_with_all_args(
722719 expected_python_package_spec .args = _TEST_RUN_ARGS
723720 expected_python_package_spec .env = [
724721 {"name" : key , "value" : value }
725- for key , value in test_training_jobs ._TEST_ENVIRONMENT_VARIABLES .items ()
722+ for key , value in test_constants . TrainingJobConstants ._TEST_ENVIRONMENT_VARIABLES .items ()
726723 ]
727724
728725 assert (
@@ -752,20 +749,20 @@ def test_create_from_local_script_custom_container_with_all_args(
752749 # configuration on this is tested in test_training_jobs.py
753750 job = aiplatform .CustomJob .from_local_script (
754751 display_name = _TEST_DISPLAY_NAME ,
755- script_path = test_training_jobs ._TEST_LOCAL_SCRIPT_FILE_NAME ,
752+ script_path = test_constants . TrainingJobConstants ._TEST_LOCAL_SCRIPT_FILE_NAME ,
756753 container_uri = _TEST_TRAINING_CONTAINER_IMAGE ,
757754 args = _TEST_RUN_ARGS ,
758- requirements = test_training_jobs ._TEST_REQUIREMENTS ,
759- environment_variables = test_training_jobs ._TEST_ENVIRONMENT_VARIABLES ,
760- replica_count = test_training_jobs ._TEST_REPLICA_COUNT ,
761- machine_type = test_training_jobs ._TEST_MACHINE_TYPE ,
762- accelerator_type = test_training_jobs ._TEST_ACCELERATOR_TYPE ,
763- accelerator_count = test_training_jobs ._TEST_ACCELERATOR_COUNT ,
764- boot_disk_type = test_training_jobs ._TEST_BOOT_DISK_TYPE ,
765- boot_disk_size_gb = test_training_jobs ._TEST_BOOT_DISK_SIZE_GB ,
766- reduction_server_replica_count = test_training_jobs ._TEST_REDUCTION_SERVER_REPLICA_COUNT ,
767- reduction_server_machine_type = test_training_jobs ._TEST_REDUCTION_SERVER_MACHINE_TYPE ,
768- reduction_server_container_uri = test_training_jobs ._TEST_REDUCTION_SERVER_CONTAINER_URI ,
755+ requirements = test_constants . TrainingJobConstants ._TEST_REQUIREMENTS ,
756+ environment_variables = test_constants . TrainingJobConstants ._TEST_ENVIRONMENT_VARIABLES ,
757+ replica_count = test_constants . TrainingJobConstants ._TEST_REPLICA_COUNT ,
758+ machine_type = test_constants . TrainingJobConstants ._TEST_MACHINE_TYPE ,
759+ accelerator_type = test_constants . TrainingJobConstants ._TEST_ACCELERATOR_TYPE ,
760+ accelerator_count = test_constants . TrainingJobConstants ._TEST_ACCELERATOR_COUNT ,
761+ boot_disk_type = test_constants . TrainingJobConstants ._TEST_BOOT_DISK_TYPE ,
762+ boot_disk_size_gb = test_constants . TrainingJobConstants ._TEST_BOOT_DISK_SIZE_GB ,
763+ reduction_server_replica_count = test_constants . TrainingJobConstants ._TEST_REDUCTION_SERVER_REPLICA_COUNT ,
764+ reduction_server_machine_type = test_constants . TrainingJobConstants ._TEST_REDUCTION_SERVER_MACHINE_TYPE ,
765+ reduction_server_container_uri = test_constants . TrainingJobConstants ._TEST_REDUCTION_SERVER_CONTAINER_URI ,
769766 base_output_dir = _TEST_BASE_OUTPUT_DIR ,
770767 labels = _TEST_LABELS ,
771768 )
@@ -774,7 +771,7 @@ def test_create_from_local_script_custom_container_with_all_args(
774771 expected_container_spec .args = _TEST_RUN_ARGS
775772 expected_container_spec .env = [
776773 {"name" : key , "value" : value }
777- for key , value in test_training_jobs ._TEST_ENVIRONMENT_VARIABLES .items ()
774+ for key , value in test_constants . TrainingJobConstants ._TEST_ENVIRONMENT_VARIABLES .items ()
778775 ]
779776
780777 assert (
0 commit comments