1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- try :
16- import pandas
17- except ImportError :
18- HAVE_PANDAS = False
19- else :
20- HAVE_PANDAS = True # pragma: NO COVER
2115
16+ import pandas
2217import unittest
2318
19+ from google .api import metric_pb2
20+ from google .api import monitored_resource_pb2
21+ from google .api_core import datetime_helpers
22+ from google .cloud import monitoring_v3
23+ from google .cloud .monitoring_v3 import _dataframe
24+
2425
2526PROJECT = "my-project"
2627
@@ -58,20 +59,22 @@ def parse_timestamps():
5859
5960
6061def generate_query_results ():
61- from google .cloud .monitoring_v3 import types
62-
6362 def P (timestamp , value ):
64- interval = types .TimeInterval ()
65- interval .start_time .FromJsonString (timestamp )
66- interval .end_time .FromJsonString (timestamp )
67- return types .Point (interval = interval , value = {"double_value" : value })
63+ interval = monitoring_v3 .TimeInterval ()
64+ interval .start_time = datetime_helpers .from_rfc3339 (timestamp ).replace (
65+ tzinfo = None
66+ )
67+ interval .end_time = datetime_helpers .from_rfc3339 (timestamp ).replace (
68+ tzinfo = None
69+ )
70+ return monitoring_v3 .Point (interval = interval , value = {"double_value" : value })
6871
6972 for metric_labels , resource_labels , value in zip (
7073 METRIC_LABELS , RESOURCE_LABELS , VALUES
7174 ):
72- yield types .TimeSeries (
73- metric = types .Metric (type = METRIC_TYPE , labels = metric_labels ),
74- resource = types .MonitoredResource (
75+ yield monitoring_v3 .TimeSeries (
76+ metric = metric_pb2 .Metric (type = METRIC_TYPE , labels = metric_labels ),
77+ resource = monitored_resource_pb2 .MonitoredResource (
7578 type = RESOURCE_TYPE , labels = resource_labels
7679 ),
7780 metric_kind = METRIC_KIND ,
@@ -80,12 +83,9 @@ def P(timestamp, value):
8083 )
8184
8285
83- @unittest .skipUnless (HAVE_PANDAS , "No pandas" )
8486class Test__build_dataframe (unittest .TestCase ):
8587 def _call_fut (self , * args , ** kwargs ):
86- from google .cloud .monitoring_v3 ._dataframe import _build_dataframe
87-
88- return _build_dataframe (* args , ** kwargs )
88+ return _dataframe ._build_dataframe (* args , ** kwargs )
8989
9090 def test_both_label_and_labels_illegal (self ):
9191 with self .assertRaises (ValueError ):
0 commit comments