Skip to content

Commit

Permalink
Update import spacing in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
daspecster committed Jan 18, 2017
1 parent 7f64d75 commit 163d578
Show file tree
Hide file tree
Showing 37 changed files with 221 additions and 14 deletions.
5 changes: 5 additions & 0 deletions monitoring/unit_tests/test__dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
def parse_timestamps(): # pragma: NO COVER
import datetime
from google.cloud._helpers import _RFC3339_MICROS

return [datetime.datetime.strptime(t, _RFC3339_MICROS)
for t in TIMESTAMPS]

Expand Down Expand Up @@ -88,6 +89,7 @@ class Test__build_dataframe(unittest.TestCase): # pragma: NO COVER

def _call_fut(self, *args, **kwargs):
from google.cloud.monitoring._dataframe import _build_dataframe

return _build_dataframe(*args, **kwargs)

def test_both_label_and_labels_illegal(self):
Expand Down Expand Up @@ -209,18 +211,21 @@ class Test__sorted_resource_labels(unittest.TestCase):

def _call_fut(self, labels):
from google.cloud.monitoring._dataframe import _sorted_resource_labels

return _sorted_resource_labels(labels)

def test_empty(self):
self.assertEqual(self._call_fut([]), [])

def test_sorted(self):
from google.cloud.monitoring._dataframe import TOP_RESOURCE_LABELS

EXPECTED = TOP_RESOURCE_LABELS + ('other-1', 'other-2')
self.assertSequenceEqual(self._call_fut(EXPECTED), EXPECTED)

def test_reversed(self):
from google.cloud.monitoring._dataframe import TOP_RESOURCE_LABELS

EXPECTED = TOP_RESOURCE_LABELS + ('other-1', 'other-2')
INPUT = list(reversed(EXPECTED))
self.assertSequenceEqual(self._call_fut(INPUT), EXPECTED)
6 changes: 6 additions & 0 deletions monitoring/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

def _make_credentials():
import google.auth.credentials

return mock.Mock(spec=google.auth.credentials.Credentials)


Expand All @@ -30,6 +31,7 @@ class TestClient(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.client import Client

return Client

def _make_one(self, *args, **kwargs):
Expand Down Expand Up @@ -198,6 +200,7 @@ def test_resource_factory(self):
def test_timeseries_factory_gauge(self):
import datetime
from google.cloud._helpers import _datetime_to_rfc3339

METRIC_TYPE = 'custom.googleapis.com/my_metric'
METRIC_LABELS = {
'status': 'successful'
Expand Down Expand Up @@ -243,6 +246,7 @@ def test_timeseries_factory_gauge(self):
def test_timeseries_factory_cumulative(self):
import datetime
from google.cloud._helpers import _datetime_to_rfc3339

MY_CUMULATIVE_METRIC = 'custom.googleapis.com/my_cumulative_metric'
METRIC_LABELS = {
'status': 'successful'
Expand Down Expand Up @@ -615,6 +619,7 @@ def test_write_time_series(self):

def test_write_point(self):
import datetime

PATH = '/projects/{project}/timeSeries/'.format(project=PROJECT)
client = self._make_one(
project=PROJECT, credentials=_make_credentials())
Expand Down Expand Up @@ -654,6 +659,7 @@ def __init__(self, *responses):

def api_request(self, **kwargs):
from google.cloud.exceptions import NotFound

self._requested.append(kwargs)
try:
return self._responses.pop(0)
Expand Down
1 change: 1 addition & 0 deletions monitoring/unit_tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestConnection(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.connection import Connection

return Connection

def _make_one(self, *args, **kwargs):
Expand Down
4 changes: 4 additions & 0 deletions monitoring/unit_tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Test_group_id_from_name(unittest.TestCase):

def _call_fut(self, path, project):
from google.cloud.monitoring.group import _group_id_from_name

return _group_id_from_name(path, project)

def test_w_empty_name(self):
Expand Down Expand Up @@ -87,6 +88,7 @@ def setUp(self):

def _setUpResources(self):
from google.cloud.monitoring.resource import Resource

info1 = {
'type': 'gce_instance',
'labels': {
Expand All @@ -110,6 +112,7 @@ def _setUpResources(self):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.group import Group

return Group

def _make_one(self, *args, **kwargs):
Expand Down Expand Up @@ -534,6 +537,7 @@ def __init__(self, *responses):

def api_request(self, **kwargs):
from google.cloud.exceptions import NotFound

self._requested.append(kwargs)
try:
return self._responses.pop(0)
Expand Down
2 changes: 2 additions & 0 deletions monitoring/unit_tests/test_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestLabelValueType(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.label import LabelValueType

return LabelValueType

def test_one(self):
Expand All @@ -36,6 +37,7 @@ class TestLabelDescriptor(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.label import LabelDescriptor

return LabelDescriptor

def _make_one(self, *args, **kwargs):
Expand Down
5 changes: 5 additions & 0 deletions monitoring/unit_tests/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestMetricKind(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.metric import MetricKind

return MetricKind

def test_one(self):
Expand All @@ -36,6 +37,7 @@ class TestValueType(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.metric import ValueType

return ValueType

def test_one(self):
Expand All @@ -52,6 +54,7 @@ class TestMetricDescriptor(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.metric import MetricDescriptor

return MetricDescriptor

def _make_one(self, *args, **kwargs):
Expand Down Expand Up @@ -500,6 +503,7 @@ class TestMetric(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.metric import Metric

return Metric

def _make_one(self, *args, **kwargs):
Expand Down Expand Up @@ -555,6 +559,7 @@ def __init__(self, *responses):

def api_request(self, **kwargs):
from google.cloud.exceptions import NotFound

self._requested.append(kwargs)
try:
return self._responses.pop(0)
Expand Down
8 changes: 8 additions & 0 deletions monitoring/unit_tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TestAligner(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.query import Aligner

return Aligner

def test_one(self):
Expand All @@ -62,6 +63,7 @@ class TestReducer(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.query import Reducer

return Reducer

def test_one(self):
Expand All @@ -79,6 +81,7 @@ class TestQuery(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.query import Query

return Query

def _make_one(self, *args, **kwargs):
Expand All @@ -87,6 +90,7 @@ def _make_one(self, *args, **kwargs):
@staticmethod
def _make_timestamp(value):
from google.cloud._helpers import _datetime_to_rfc3339

return _datetime_to_rfc3339(value)

def test_constructor_minimal(self):
Expand Down Expand Up @@ -149,6 +153,7 @@ def test_constructor_default_end_time(self):

def test_constructor_nonzero_duration_illegal(self):
import datetime

T1 = datetime.datetime(2016, 4, 7, 2, 30, 30)
client = _Client(project=PROJECT, connection=_Connection())
with self.assertRaises(ValueError):
Expand Down Expand Up @@ -506,6 +511,7 @@ class Test_Filter(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.query import _Filter

return _Filter

def _make_one(self, metric_type):
Expand Down Expand Up @@ -540,6 +546,7 @@ class Test__build_label_filter(unittest.TestCase):

def _call_fut(self, *args, **kwargs):
from google.cloud.monitoring.query import _build_label_filter

return _build_label_filter(*args, **kwargs)

def test_no_labels(self):
Expand Down Expand Up @@ -636,6 +643,7 @@ def __init__(self, *responses):

def api_request(self, **kwargs):
from google.cloud.exceptions import NotFound

self._requested.append(kwargs)
try:
return self._responses.pop(0)
Expand Down
3 changes: 3 additions & 0 deletions monitoring/unit_tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestResourceDescriptor(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.resource import ResourceDescriptor

return ResourceDescriptor

def _make_one(self, *args, **kwargs):
Expand Down Expand Up @@ -280,6 +281,7 @@ class TestResource(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.resource import Resource

return Resource

def _make_one(self, *args, **kwargs):
Expand Down Expand Up @@ -340,6 +342,7 @@ def __init__(self, *responses):

def api_request(self, **kwargs):
from google.cloud.exceptions import NotFound

self._requested.append(kwargs)
try:
return self._responses.pop(0)
Expand Down
4 changes: 4 additions & 0 deletions monitoring/unit_tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TestTimeSeries(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.timeseries import TimeSeries

return TimeSeries

def _make_one(self, *args, **kwargs):
Expand Down Expand Up @@ -184,6 +185,7 @@ class TestPoint(unittest.TestCase):
@staticmethod
def _get_target_class():
from google.cloud.monitoring.timeseries import Point

return Point

def _make_one(self, *args, **kwargs):
Expand Down Expand Up @@ -232,6 +234,7 @@ def test_from_dict_int64(self):
def test_to_dict_int64(self):
import datetime
from google.cloud._helpers import _datetime_to_rfc3339

VALUE = 42
end_time = datetime.datetime.now()
end_time_str = _datetime_to_rfc3339(end_time, ignore_zone=False)
Expand All @@ -248,6 +251,7 @@ def test_to_dict_int64(self):
def test_to_dict_float_with_start_time(self):
import datetime
from google.cloud._helpers import _datetime_to_rfc3339

VALUE = 1.6180339
start_time = datetime.datetime.now()
start_time_str = _datetime_to_rfc3339(start_time, ignore_zone=False)
Expand Down
Loading

0 comments on commit 163d578

Please sign in to comment.