test_sagemaker.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. """Test Task SageMaker."""
  18. import json
  19. from unittest.mock import patch
  20. import pytest
  21. from pydolphinscheduler.tasks.sagemaker import SageMaker
  22. sagemaker_request_json = json.dumps(
  23. {
  24. "ParallelismConfiguration": {"MaxParallelExecutionSteps": 1},
  25. "PipelineExecutionDescription": "test Pipeline",
  26. "PipelineExecutionDisplayName": "AbalonePipeline",
  27. "PipelineName": "AbalonePipeline",
  28. "PipelineParameters": [
  29. {"Name": "ProcessingInstanceType", "Value": "ml.m4.xlarge"},
  30. {"Name": "ProcessingInstanceCount", "Value": "2"},
  31. ],
  32. },
  33. indent=2,
  34. )
  35. @pytest.mark.parametrize(
  36. "attr, expect",
  37. [
  38. (
  39. {"sagemaker_request_json": sagemaker_request_json},
  40. {
  41. "sagemakerRequestJson": sagemaker_request_json,
  42. "localParams": [],
  43. "resourceList": [],
  44. "dependence": {},
  45. "waitStartTimeout": {},
  46. "conditionResult": {"successNode": [""], "failedNode": [""]},
  47. },
  48. )
  49. ],
  50. )
  51. @patch(
  52. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  53. return_value=(123, 1),
  54. )
  55. def test_property_task_params(mock_code_version, attr, expect):
  56. """Test task sagemaker task property."""
  57. task = SageMaker("test-sagemaker-task-params", **attr)
  58. assert expect == task.task_params
  59. def test_sagemaker_get_define():
  60. """Test task sagemaker function get_define."""
  61. code = 123
  62. version = 1
  63. name = "test_sagemaker_get_define"
  64. expect = {
  65. "code": code,
  66. "name": name,
  67. "version": 1,
  68. "description": None,
  69. "delayTime": 0,
  70. "taskType": "SAGEMAKER",
  71. "taskParams": {
  72. "resourceList": [],
  73. "localParams": [],
  74. "sagemakerRequestJson": sagemaker_request_json,
  75. "dependence": {},
  76. "conditionResult": {"successNode": [""], "failedNode": [""]},
  77. "waitStartTimeout": {},
  78. },
  79. "flag": "YES",
  80. "taskPriority": "MEDIUM",
  81. "workerGroup": "default",
  82. "environmentCode": None,
  83. "failRetryTimes": 0,
  84. "failRetryInterval": 1,
  85. "timeoutFlag": "CLOSE",
  86. "timeoutNotifyStrategy": None,
  87. "timeout": 0,
  88. }
  89. with patch(
  90. "pydolphinscheduler.core.task.Task.gen_code_and_version",
  91. return_value=(code, version),
  92. ):
  93. sagemaker = SageMaker(name, sagemaker_request_json)
  94. assert sagemaker.get_define() == expect