Skip to content

Commit

Permalink
update to zone/region tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Marin committed Mar 2, 2018
1 parent be21e9e commit 1ebc19f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
16 changes: 16 additions & 0 deletions tests/mock_google/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
# limitations under the License.
"""Limited mock of google-cloud-sdk for tests
"""
from io import BytesIO

from google.oauth2.credentials import Credentials

from mrjob.fs.gcs import parse_gcs_uri

from .dataproc import MockGoogleDataprocClusterClient
from .dataproc import MockGoogleDataprocJobClient
from .storage import MockGoogleStorageClient
from tests.mr_two_step_job import MRTwoStepJob
from tests.py2 import patch
from tests.sandbox import SandboxedTestCase

Expand Down Expand Up @@ -71,6 +74,19 @@ def job_client(self, credentials=None):
def storage_client(self, project=None, credentials=None):
return MockGoogleStorageClient(mock_gcs_fs=self.mock_gcs_fs)

def make_runner(self, *args):
"""create a dummy job, and call make_runner() on it.
Use this in a with block:
with self.make_runner() as runner:
...
"""
stdin = BytesIO(b'foo\nbar\n')
mr_job = MRTwoStepJob(['-r', 'dataproc'] + list(args))
mr_job.sandbox(stdin=stdin)

return mr_job.make_runner()

def put_gcs_multi(self, gcs_uri_to_data_map):
client = self.storage_client()

Expand Down
21 changes: 10 additions & 11 deletions tests/test_dataproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,27 +361,26 @@ def test_hadoop_version_option_does_nothing(self):
self.assertEqual(runner.get_hadoop_version(), '2.7.2')


EXPECTED_ZONE = 'PUPPYLAND'
class AvailabilityZoneConfigTestCase(MockGoogleTestCase):


class ZoneTestCase(MockGoogleTestCase):
ZONE = 'puppy-land-1a'

MRJOB_CONF_CONTENTS = {'runners': {'dataproc': {
'check_cluster_every': 0.00,
'cloud_fs_sync_secs': 0.00,
'zone': EXPECTED_ZONE,
'zone': ZONE,
}}}

def test_availability_zone_config(self):
with self.make_runner() as runner:
with self.make_runner('--zone', self.ZONE) as runner:
runner.run()

cluster = runner._api_cluster_get(runner._cluster_id)
self.assertIn(EXPECTED_ZONE,
cluster = runner._get_cluster(runner._cluster_id)
self.assertIn(self.ZONE,
cluster['config']['gceClusterConfig']['zoneUri'])
self.assertIn(EXPECTED_ZONE,
self.assertIn(self.ZONE,
cluster['config']['masterConfig']['machineTypeUri'])
self.assertIn(EXPECTED_ZONE,
self.assertIn(self.ZONE,
cluster['config']['workerConfig']['machineTypeUri'])


Expand All @@ -400,10 +399,10 @@ def test_set_labels(self):
self.assertEqual(cluster['labels']['name'], 'wrench')


class RegionAndZoneTestCase(MockGoogleTestCase):
class RegionAndZoneOptsTestCase(MockGoogleTestCase):

def setUp(self):
super(RegionAndZoneTestCase, self).setUp()
super(RegionAndZoneOptsTestCase, self).setUp()
self.log = self.start(patch('mrjob.dataproc.log'))

def test_default(self):
Expand Down

0 comments on commit 1ebc19f

Please sign in to comment.