<s> import os <EOL> from datetime import datetime <EOL> import warnings <EOL> import nose <EOL> import pandas as pd <EOL> from pandas import compat <EOL> from pandas . util . testing import network , assert_frame_equal , with_connectivity_check <EOL> from numpy . testing . decorators import slow <EOL> import pandas . util . testing as tm <EOL> if compat . PY3 : <EOL> raise nose . SkipTest ( "<STR_LIT>" ) <EOL> try : <EOL> import httplib2 <EOL> import apiclient <EOL> with warnings . catch_warnings ( record = True ) : <EOL> import pandas . io . ga as ga <EOL> from pandas . io . ga import GAnalytics , read_ga <EOL> from pandas . io . auth import AuthenticationConfigError , reset_default_token_store <EOL> from pandas . io import auth <EOL> except ImportError : <EOL> raise nose . SkipTest ( "<STR_LIT>" ) <EOL> class TestGoogle ( tm . TestCase ) : <EOL> _multiprocess_can_split_ = True <EOL> def test_remove_token_store ( self ) : <EOL> auth . DEFAULT_TOKEN_FILE = '<STR_LIT>' <EOL> with open ( auth . DEFAULT_TOKEN_FILE , '<STR_LIT:w>' ) as fh : <EOL> fh . write ( '<STR_LIT:test>' ) <EOL> reset_default_token_store ( ) <EOL> self . assertFalse ( os . path . exists ( auth . DEFAULT_TOKEN_FILE ) ) <EOL> @ with_connectivity_check ( "<STR_LIT>" ) <EOL> def test_getdata ( self ) : <EOL> try : <EOL> end_date = datetime . now ( ) <EOL> start_date = end_date - pd . offsets . Day ( ) * <NUM_LIT:5> <EOL> end_date = end_date . strftime ( '<STR_LIT>' ) <EOL> start_date = start_date . strftime ( '<STR_LIT>' ) <EOL> reader = GAnalytics ( ) <EOL> df = reader . get_data ( <EOL> metrics = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> start_date = start_date , <EOL> end_date = end_date , <EOL> dimensions = [ '<STR_LIT:date>' , '<STR_LIT>' ] , <EOL> parse_dates = { '<STR_LIT>' : [ '<STR_LIT:date>' , '<STR_LIT>' ] } , <EOL> index_col = <NUM_LIT:0> ) <EOL> self . assertIsInstance ( df , pd . DataFrame ) <EOL> self . assertIsInstance ( df . index , pd . DatetimeIndex ) <EOL> self . assertGreater ( len ( df ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( '<STR_LIT:date>' not in df ) <EOL> self . assertTrue ( '<STR_LIT>' not in df ) <EOL> self . assertEqual ( df . index . name , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> df2 = read_ga ( <EOL> metrics = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> start_date = start_date , <EOL> end_date = end_date , <EOL> dimensions = [ '<STR_LIT:date>' , '<STR_LIT>' ] , <EOL> parse_dates = { '<STR_LIT>' : [ '<STR_LIT:date>' , '<STR_LIT>' ] } , <EOL> index_col = <NUM_LIT:0> ) <EOL> assert_frame_equal ( df , df2 ) <EOL> except AuthenticationConfigError : <EOL> raise nose . SkipTest ( "<STR_LIT>" ) <EOL> @ with_connectivity_check ( "<STR_LIT>" ) <EOL> def test_iterator ( self ) : <EOL> try : <EOL> reader = GAnalytics ( ) <EOL> it = reader . get_data ( <EOL> metrics = '<STR_LIT>' , <EOL> start_date = '<STR_LIT>' , <EOL> dimensions = '<STR_LIT:date>' , <EOL> max_results = <NUM_LIT:10> , chunksize = <NUM_LIT:5> , <EOL> index_col = <NUM_LIT:0> ) <EOL> df1 = next ( it ) <EOL> df2 = next ( it ) <EOL> for df in [ df1 , df2 ] : <EOL> self . assertIsInstance ( df , pd . DataFrame ) <EOL> self . assertIsInstance ( df . index , pd . DatetimeIndex ) <EOL> self . assertEqual ( len ( df ) , <NUM_LIT:5> ) <EOL> self . assertTrue ( '<STR_LIT:date>' not in df ) <EOL> self . assertEqual ( df . index . name , '<STR_LIT:date>' ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> self . assertTrue ( ( df2 . index > df1 . index ) . all ( ) ) <EOL> except AuthenticationConfigError : <EOL> raise nose . SkipTest ( "<STR_LIT>" ) <EOL> def test_v2_advanced_segment_format ( self ) : <EOL> advanced_segment_id = <NUM_LIT> <EOL> query = ga . format_query ( '<STR_LIT>' , [ '<STR_LIT>' ] , '<STR_LIT>' , segment = advanced_segment_id ) <EOL> self . assertEqual ( query [ '<STR_LIT>' ] , '<STR_LIT>' + str ( advanced_segment_id ) , "<STR_LIT>" ) <EOL> def test_v2_dynamic_segment_format ( self ) : <EOL> dynamic_segment_id = '<STR_LIT>' <EOL> query = ga . format_query ( '<STR_LIT>' , [ '<STR_LIT>' ] , '<STR_LIT>' , segment = dynamic_segment_id ) <EOL> self . assertEqual ( query [ '<STR_LIT>' ] , '<STR_LIT>' + str ( dynamic_segment_id ) , "<STR_LIT>" ) <EOL> def test_v3_advanced_segment_common_format ( self ) : <EOL> advanced_segment_id = '<STR_LIT>' <EOL> query = ga . format_query ( '<STR_LIT>' , [ '<STR_LIT>' ] , '<STR_LIT>' , segment = advanced_segment_id ) <EOL> self . assertEqual ( query [ '<STR_LIT>' ] , '<STR_LIT>' + str ( advanced_segment_id ) , "<STR_LIT>" ) <EOL> def test_v3_advanced_segment_weird_format ( self ) : <EOL> advanced_segment_id = '<STR_LIT>' <EOL> query = ga . format_query ( '<STR_LIT>' , [ '<STR_LIT>' ] , '<STR_LIT>' , segment = advanced_segment_id ) <EOL> self . assertEqual ( query [ '<STR_LIT>' ] , '<STR_LIT>' + str ( advanced_segment_id ) , "<STR_LIT>" ) <EOL> def test_v3_advanced_segment_with_underscore_format ( self ) : <EOL> advanced_segment_id = '<STR_LIT>' <EOL> query = ga . format_query ( '<STR_LIT>' , [ '<STR_LIT>' ] , '<STR_LIT>' , segment = advanced_segment_id ) <EOL> self . assertEqual ( query [ '<STR_LIT>' ] , '<STR_LIT>' + str ( advanced_segment_id ) , "<STR_LIT>" ) <EOL> @ with_connectivity_check ( "<STR_LIT>" ) <EOL> def test_segment ( self ) : <EOL> try : <EOL> end_date = datetime . now ( ) <EOL> start_date = end_date - pd . offsets . Day ( ) * <NUM_LIT:5> <EOL> end_date = end_date . strftime ( '<STR_LIT>' ) <EOL> start_date = start_date . strftime ( '<STR_LIT>' ) <EOL> reader = GAnalytics ( ) <EOL> df = reader . get_data ( <EOL> metrics = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> start_date = start_date , <EOL> end_date = end_date , <EOL> segment = - <NUM_LIT:2> , <EOL> dimensions = [ '<STR_LIT:date>' , '<STR_LIT>' ] , <EOL> parse_dates = { '<STR_LIT>' : [ '<STR_LIT:date>' , '<STR_LIT>' ] } , <EOL> index_col = <NUM_LIT:0> ) <EOL> self . assertIsInstance ( df , pd . DataFrame ) <EOL> self . assertIsInstance ( df . index , pd . DatetimeIndex ) <EOL> self . assertGreater ( len ( df ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( '<STR_LIT:date>' not in df ) <EOL> self . assertTrue ( '<STR_LIT>' not in df ) <EOL> self . assertEqual ( df . index . name , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> df = read_ga ( <EOL> metrics = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> start_date = start_date , <EOL> end_date = end_date , <EOL> segment = "<STR_LIT>" , <EOL> dimensions = [ '<STR_LIT:date>' , '<STR_LIT>' ] , <EOL> parse_dates = { '<STR_LIT>' : [ '<STR_LIT:date>' , '<STR_LIT>' ] } , <EOL> index_col = <NUM_LIT:0> ) <EOL> assert isinstance ( df , pd . DataFrame ) <EOL> assert isinstance ( df . index , pd . DatetimeIndex ) <EOL> self . assertGreater ( len ( df ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( '<STR_LIT:date>' not in df ) <EOL> self . assertTrue ( '<STR_LIT>' not in df ) <EOL> self . assertEqual ( df . index . name , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> self . assertTrue ( '<STR_LIT>' in df ) <EOL> except AuthenticationConfigError : <EOL> raise nose . SkipTest ( "<STR_LIT>" ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> nose . runmodule ( argv = [ __file__ , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> exit = False ) </s>
