<s> import unittest2 <EOL> METRIC_TYPE = '<STR_LIT>' <EOL> METRIC_LABELS = { '<STR_LIT>' : '<STR_LIT>' } <EOL> RESOURCE_TYPE = '<STR_LIT>' <EOL> RESOURCE_LABELS = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> METRIC_KIND = '<STR_LIT>' <EOL> VALUE_TYPE = '<STR_LIT>' <EOL> TS0 = '<STR_LIT>' <EOL> TS1 = '<STR_LIT>' <EOL> TS2 = '<STR_LIT>' <EOL> class TestTimeSeries ( unittest2 . TestCase ) : <EOL> def _getTargetClass ( self ) : <EOL> from gcloud . monitoring . timeseries import TimeSeries <EOL> return TimeSeries <EOL> def _makeOne ( self , * args , ** kwargs ) : <EOL> return self . _getTargetClass ( ) ( * args , ** kwargs ) <EOL> def test_constructor ( self ) : <EOL> from gcloud . monitoring . metric import Metric <EOL> from gcloud . monitoring . resource import Resource <EOL> from gcloud . monitoring . timeseries import Point <EOL> VALUE = <NUM_LIT> <EOL> METRIC = Metric ( type = METRIC_TYPE , labels = METRIC_LABELS ) <EOL> RESOURCE = Resource ( type = RESOURCE_TYPE , labels = RESOURCE_LABELS ) <EOL> POINTS = [ <EOL> Point ( start_time = TS0 , end_time = TS1 , value = VALUE ) , <EOL> Point ( start_time = TS1 , end_time = TS2 , value = VALUE ) , <EOL> ] <EOL> series = self . _makeOne ( metric = METRIC , <EOL> resource = RESOURCE , <EOL> metric_kind = METRIC_KIND , <EOL> value_type = VALUE_TYPE , <EOL> points = POINTS ) <EOL> self . assertEqual ( series . metric , METRIC ) <EOL> self . assertEqual ( series . resource , RESOURCE ) <EOL> self . assertEqual ( series . metric_kind , METRIC_KIND ) <EOL> self . assertEqual ( series . value_type , VALUE_TYPE ) <EOL> self . assertEqual ( series . points , POINTS ) <EOL> def test_from_dict ( self ) : <EOL> VALUE = <NUM_LIT> <EOL> info = { <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : METRIC_TYPE , '<STR_LIT>' : METRIC_LABELS } , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : RESOURCE_TYPE , '<STR_LIT>' : RESOURCE_LABELS } , <EOL> '<STR_LIT>' : METRIC_KIND , <EOL> '<STR_LIT>' : VALUE_TYPE , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : { '<STR_LIT>' : TS0 , '<STR_LIT>' : TS1 } , <EOL> '<STR_LIT:value>' : { '<STR_LIT>' : VALUE } , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : { '<STR_LIT>' : TS1 , '<STR_LIT>' : TS2 } , <EOL> '<STR_LIT:value>' : { '<STR_LIT>' : VALUE } , <EOL> } , <EOL> ] , <EOL> } <EOL> series = self . _getTargetClass ( ) . _from_dict ( info ) <EOL> self . assertEqual ( series . metric . type , METRIC_TYPE ) <EOL> self . assertEqual ( series . metric . labels , METRIC_LABELS ) <EOL> self . assertEqual ( series . resource . type , RESOURCE_TYPE ) <EOL> self . assertEqual ( series . resource . labels , RESOURCE_LABELS ) <EOL> self . assertEqual ( series . metric_kind , METRIC_KIND ) <EOL> self . assertEqual ( series . value_type , VALUE_TYPE ) <EOL> self . assertEqual ( len ( series . points ) , <NUM_LIT:2> ) <EOL> point1 , point2 = series . points <EOL> self . assertEqual ( point1 . start_time , TS0 ) <EOL> self . assertEqual ( point1 . end_time , TS1 ) <EOL> self . assertEqual ( point1 . value , VALUE ) <EOL> self . assertEqual ( point2 . start_time , TS1 ) <EOL> self . assertEqual ( point2 . end_time , TS2 ) <EOL> self . assertEqual ( point2 . value , VALUE ) <EOL> def test_from_dict_no_points ( self ) : <EOL> info = { <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : METRIC_TYPE , '<STR_LIT>' : METRIC_LABELS } , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : RESOURCE_TYPE , '<STR_LIT>' : RESOURCE_LABELS } , <EOL> '<STR_LIT>' : METRIC_KIND , <EOL> '<STR_LIT>' : VALUE_TYPE , <EOL> } <EOL> series = self . _getTargetClass ( ) . _from_dict ( info ) <EOL> self . assertEqual ( series . metric . type , METRIC_TYPE ) <EOL> self . assertEqual ( series . metric . labels , METRIC_LABELS ) <EOL> self . assertEqual ( series . resource . type , RESOURCE_TYPE ) <EOL> self . assertEqual ( series . resource . labels , RESOURCE_LABELS ) <EOL> self . assertEqual ( series . metric_kind , METRIC_KIND ) <EOL> self . assertEqual ( series . value_type , VALUE_TYPE ) <EOL> self . assertEqual ( series . points , [ ] ) <EOL> def test_labels ( self ) : <EOL> info = { <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : METRIC_TYPE , '<STR_LIT>' : METRIC_LABELS } , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : RESOURCE_TYPE , '<STR_LIT>' : RESOURCE_LABELS } , <EOL> '<STR_LIT>' : METRIC_KIND , <EOL> '<STR_LIT>' : VALUE_TYPE , <EOL> } <EOL> series = self . _getTargetClass ( ) . _from_dict ( info ) <EOL> labels = { '<STR_LIT>' : RESOURCE_TYPE } <EOL> labels . update ( RESOURCE_LABELS ) <EOL> labels . update ( METRIC_LABELS ) <EOL> self . assertIsNone ( series . _labels ) <EOL> self . assertEqual ( series . labels , labels ) <EOL> self . assertIsNotNone ( series . _labels ) <EOL> self . assertEqual ( series . labels , labels ) <EOL> class TestPoint ( unittest2 . TestCase ) : <EOL> def _getTargetClass ( self ) : <EOL> from gcloud . monitoring . timeseries import Point <EOL> return Point <EOL> def _makeOne ( self , * args , ** kwargs ) : <EOL> return self . _getTargetClass ( ) ( * args , ** kwargs ) <EOL> def test_constructor ( self ) : <EOL> VALUE = <NUM_LIT> <EOL> point = self . _makeOne ( start_time = TS0 , end_time = TS1 , value = VALUE ) <EOL> self . assertEqual ( point . start_time , TS0 ) <EOL> self . assertEqual ( point . end_time , TS1 ) <EOL> self . assertEqual ( point . value , VALUE ) <EOL> def test_from_dict ( self ) : <EOL> VALUE = <NUM_LIT> <EOL> info = { <EOL> '<STR_LIT>' : { '<STR_LIT>' : TS0 , '<STR_LIT>' : TS1 } , <EOL> '<STR_LIT:value>' : { '<STR_LIT>' : VALUE } , <EOL> } <EOL> point = self . _getTargetClass ( ) . _from_dict ( info ) <EOL> self . assertEqual ( point . start_time , TS0 ) <EOL> self . assertEqual ( point . end_time , TS1 ) <EOL> self . assertEqual ( point . value , VALUE ) <EOL> def test_from_dict_defaults ( self ) : <EOL> VALUE = <NUM_LIT> <EOL> info = { <EOL> '<STR_LIT>' : { '<STR_LIT>' : TS1 } , <EOL> '<STR_LIT:value>' : { '<STR_LIT>' : VALUE } , <EOL> } <EOL> point = self . _getTargetClass ( ) . _from_dict ( info ) <EOL> self . assertIsNone ( point . start_time ) <EOL> self . assertEqual ( point . end_time , TS1 ) <EOL> self . assertEqual ( point . value , VALUE ) <EOL> def test_from_dict_int64 ( self ) : <EOL> VALUE = <NUM_LIT:2> ** <NUM_LIT> - <NUM_LIT:1> <EOL> info = { <EOL> '<STR_LIT>' : { '<STR_LIT>' : TS1 } , <EOL> '<STR_LIT:value>' : { '<STR_LIT>' : str ( VALUE ) } , <EOL> } <EOL> point = self . _getTargetClass ( ) . _from_dict ( info ) <EOL> self . assertIsNone ( point . start_time ) <EOL> self . assertEqual ( point . end_time , TS1 ) <EOL> self . assertEqual ( point . value , VALUE ) </s>
