Skip to content

Commit

Permalink
Merge pull request #2725 from daspecster/drop-monkey-for-mock-in-moni…
Browse files Browse the repository at this point in the history
…toring

Swap _Monkey for mock.patch().
  • Loading branch information
daspecster authored Nov 14, 2016
2 parents 2f49740 + f8e9679 commit 945a221
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 @@ -8,6 +8,7 @@ localdeps =
deps =
{toxinidir}/../core
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 @@ -130,8 +130,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 @@ -141,7 +140,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 945a221

Please sign in to comment.