Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(sdk): Components tests - Made test_load_component_from_url hermetic #4121

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 18 additions & 6 deletions sdk/python/kfp/components_tests/test_components.py
Expand Up @@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import mock
import os
import requests
import sys
import textwrap
import unittest
Expand Down Expand Up @@ -52,13 +54,23 @@ def test_load_component_from_zipped_yaml_file(self):
self._test_load_component_from_file(str(component_path))

def test_load_component_from_url(self):
url = 'https://raw.githubusercontent.com/kubeflow/pipelines/e54fe675432cfef1d115a7a2909f08ed95ea8933/sdk/python/tests/components/test_data/python_add.component.yaml'
component_path = Path(__file__).parent / 'test_data' / 'python_add.component.yaml'
component_url = 'https://raw.githubusercontent.com/some/repo/components/component_group/python_add/component.yaml'
component_bytes = component_path.read_bytes()
component_dict = load_yaml(component_bytes)

def mock_response_factory(url, params=None, **kwargs):
if url == component_url:
response = requests.Response()
response.url = component_url
response.status_code = 200
response._content = component_bytes
return response
raise RuntimeError('Unexpected URL "{}"'.format(url))

with mock.patch('requests.get', mock_response_factory):
task_factory1 = comp.load_component_from_url(component_url)

import requests
resp = requests.get(url)
component_text = resp.content
component_dict = load_yaml(component_text)
task_factory1 = comp.load_component_from_url(url)
self.assertEqual(task_factory1.__doc__, component_dict['name'] + '\n' + component_dict['description'])

arg1 = 3
Expand Down