VictorPlusC commented on a change in pull request #16691: URL: https://github.com/apache/beam/pull/16691#discussion_r798989018
########## File path: sdks/python/apache_beam/runners/interactive/dataproc/dataproc_cluster_manager_test.py ########## @@ -0,0 +1,159 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +# pytype: skip-file + +import unittest +from unittest.mock import patch + +try: + from google.cloud import dataproc_v1 + from apache_beam.runners.interactive.dataproc import dataproc_cluster_manager +except ImportError: + _dataproc_imported = False +else: + _dataproc_imported = True + + +class MockException(Exception): + def __init__(self, code=-1): + self.code = code + + [email protected](not _dataproc_imported, 'dataproc package was not imported.') +class DataprocClusterManagerTest(unittest.TestCase): + """Unit test for DataprocClusterManager""" + @patch( + 'google.cloud.dataproc_v1.ClusterControllerClient.create_cluster', + side_effect=MockException(409)) + def test_create_cluster_default_already_exists(self, mock_cluster_client): + """ + Tests that no exception is thrown when a cluster already exists, + but is using DataprocClusterManager.DEFAULT_NAME. + """ + cluster_manager = dataproc_cluster_manager.DataprocClusterManager() + from apache_beam.runners.interactive.dataproc.dataproc_cluster_manager import _LOGGER + with self.assertLogs(_LOGGER, level='INFO') as context_manager: + cluster_manager._create_cluster({}) + self.assertTrue( + 'Cluster {} already exists'.format(cluster_manager.DEFAULT_NAME) in + context_manager.output[0]) Review comment: Noted. I've indented the uses of the context_manager to be inside the "with ... as ..." statement. Thanks! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
