Skip to content

Commit

Permalink
Swap _Monkey for mock.patch().
Browse files Browse the repository at this point in the history
  • Loading branch information
daspecster committed Nov 11, 2016
1 parent 0291dd4 commit f8e9679
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions monitoring/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ localdeps =
pip install --quiet --upgrade {toxinidir}/../core
deps =
pytest
mock
covercmd =
py.test --quiet \
--cov=google.cloud.monitoring \
Expand Down
6 changes: 3 additions & 3 deletions monitoring/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions monitoring/unit_tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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)
Expand Down

0 comments on commit f8e9679

Please sign in to comment.