From f8e9679e897dd43a0f4f9ba7feb9c7a47d1466c0 Mon Sep 17 00:00:00 2001 From: Thomas Schultz Date: Fri, 11 Nov 2016 17:02:02 -0500 Subject: [PATCH] Swap _Monkey for mock.patch(). --- monitoring/tox.ini | 1 + monitoring/unit_tests/test_client.py | 6 +++--- monitoring/unit_tests/test_query.py | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/monitoring/tox.ini b/monitoring/tox.ini index d825482792cd..136b074cd430 100644 --- a/monitoring/tox.ini +++ b/monitoring/tox.ini @@ -7,6 +7,7 @@ localdeps = pip install --quiet --upgrade {toxinidir}/../core deps = pytest + mock covercmd = py.test --quiet \ --cov=google.cloud.monitoring \ diff --git a/monitoring/unit_tests/test_client.py b/monitoring/unit_tests/test_client.py index 5911924c3259..bc0ed7cc60cf 100644 --- a/monitoring/unit_tests/test_client.py +++ b/monitoring/unit_tests/test_client.py @@ -185,8 +185,7 @@ def test_resource_factory(self): def test_timeseries_factory_gauge(self): import datetime - from google.cloud._testing import _Monkey - import google.cloud.monitoring.client + import mock from google.cloud._helpers import _datetime_to_rfc3339 METRIC_TYPE = 'custom.googleapis.com/my_metric' METRIC_LABELS = { @@ -222,7 +221,8 @@ def test_timeseries_factory_gauge(self): TIME2_STR = _datetime_to_rfc3339(TIME2, ignore_zone=False) # Construct a time series assuming a gauge metric using the current # time - with _Monkey(google.cloud.monitoring.client, _UTCNOW=lambda: TIME2): + with mock.patch('google.cloud.monitoring.client._UTCNOW', + new=lambda: TIME2): timeseries_no_end = client.time_series(metric, resource, VALUE) self.assertEqual(timeseries_no_end.points[0].end_time, TIME2_STR) diff --git a/monitoring/unit_tests/test_query.py b/monitoring/unit_tests/test_query.py index 6354933bcf2a..15fde9daa4c3 100644 --- a/monitoring/unit_tests/test_query.py +++ b/monitoring/unit_tests/test_query.py @@ -129,8 +129,7 @@ def test_constructor_maximal(self): def test_constructor_default_end_time(self): import datetime - from google.cloud._testing import _Monkey - from google.cloud.monitoring import query as MUT + import mock MINUTES = 5 NOW, T0, T1 = [ @@ -140,7 +139,8 @@ def test_constructor_default_end_time(self): ] client = _Client(project=PROJECT, connection=_Connection()) - with _Monkey(MUT, _UTCNOW=lambda: NOW): + with mock.patch('google.cloud.monitoring.query._UTCNOW', + new=lambda: NOW): query = self._make_one(client, METRIC_TYPE, minutes=MINUTES) self.assertEqual(query._start_time, T0)