<s> from pyiso import client_factory <EOL> from unittest import TestCase <EOL> import pytz <EOL> from datetime import datetime <EOL> from io import StringIO <EOL> class TestBPABase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . wind_tsv = StringIO ( u"<STR_LIT>" ) <EOL> self . wind_xls = StringIO ( u"<STR_LIT>" ) <EOL> def test_request_latest ( self ) : <EOL> c = client_factory ( '<STR_LIT>' ) <EOL> response = c . request ( '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , response . text ) <EOL> def test_parse_to_df ( self ) : <EOL> c = client_factory ( '<STR_LIT>' ) <EOL> df = c . parse_to_df ( self . wind_tsv , skiprows = <NUM_LIT:6> , header = <NUM_LIT:0> , delimiter = '<STR_LIT:\t>' , <EOL> index_col = <NUM_LIT:0> , parse_dates = True ) <EOL> self . assertEqual ( list ( df . columns ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( df ) , <NUM_LIT:12> ) <EOL> def test_utcify ( self ) : <EOL> ts_str = '<STR_LIT>' <EOL> c = client_factory ( '<STR_LIT>' ) <EOL> ts = c . utcify ( ts_str ) <EOL> self . assertEqual ( ts , datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:15> , <NUM_LIT:10> + <NUM_LIT:7> , <NUM_LIT:10> , tzinfo = pytz . utc ) ) <EOL> def test_utcify_index ( self ) : <EOL> c = client_factory ( '<STR_LIT>' ) <EOL> df = c . parse_to_df ( self . wind_tsv , skiprows = <NUM_LIT:6> , header = <NUM_LIT:0> , delimiter = '<STR_LIT:\t>' , <EOL> index_col = <NUM_LIT:0> , parse_dates = True ) <EOL> utc_index = c . utcify_index ( df . index ) <EOL> self . assertEqual ( utc_index [ <NUM_LIT:0> ] . to_pydatetime ( ) , datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:15> , <NUM_LIT:10> + <NUM_LIT:7> , <NUM_LIT:10> , tzinfo = pytz . utc ) ) <EOL> self . assertEqual ( len ( df ) , len ( utc_index ) ) <EOL> def test_slice_latest ( self ) : <EOL> c = client_factory ( '<STR_LIT>' ) <EOL> df = c . parse_to_df ( self . wind_tsv , skiprows = <NUM_LIT:6> , header = <NUM_LIT:0> , delimiter = '<STR_LIT:\t>' , <EOL> index_col = <NUM_LIT:0> , parse_dates = True ) <EOL> df . index = c . utcify_index ( df . index ) <EOL> sliced = c . slice_times ( df , { '<STR_LIT>' : True } ) <EOL> self . assertEqual ( list ( sliced . values [ <NUM_LIT:0> ] ) , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_slice_startend ( self ) : <EOL> c = client_factory ( '<STR_LIT>' ) <EOL> df = c . parse_to_df ( self . wind_tsv , skiprows = <NUM_LIT:6> , header = <NUM_LIT:0> , delimiter = '<STR_LIT:\t>' , <EOL> index_col = <NUM_LIT:0> , parse_dates = True ) <EOL> df . index = c . utcify_index ( df . index ) <EOL> sliced = c . slice_times ( df , { '<STR_LIT>' : datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:15> , <NUM_LIT:10> + <NUM_LIT:7> , <NUM_LIT> , tzinfo = pytz . utc ) , <EOL> '<STR_LIT>' : datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:15> , <NUM_LIT:11> + <NUM_LIT:7> , <NUM_LIT:30> , tzinfo = pytz . utc ) } ) <EOL> self . assertEqual ( len ( sliced ) , <NUM_LIT:9> ) <EOL> self . assertEqual ( list ( sliced . iloc [ <NUM_LIT:0> ] . values ) , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_serialize_gen ( self ) : <EOL> c = client_factory ( '<STR_LIT>' ) <EOL> df = c . parse_to_df ( self . wind_tsv , skiprows = <NUM_LIT:6> , header = <NUM_LIT:0> , delimiter = '<STR_LIT:\t>' , <EOL> index_col = <NUM_LIT:0> , parse_dates = True , usecols = [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> df . index = c . utcify_index ( df . index ) <EOL> renamed = df . rename ( columns = c . fuels , inplace = False ) <EOL> pivoted = c . unpivot ( renamed ) <EOL> data = c . serialize ( pivoted , header = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( data ) , len ( pivoted ) ) <EOL> self . assertEqual ( data [ <NUM_LIT:0> ] , { '<STR_LIT>' : datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT:10> , tzinfo = pytz . utc ) , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_serialize_load ( self ) : <EOL> c = client_factory ( '<STR_LIT>' ) <EOL> df = c . parse_to_df ( self . wind_tsv , skiprows = <NUM_LIT:6> , header = <NUM_LIT:0> , delimiter = '<STR_LIT:\t>' , <EOL> index_col = <NUM_LIT:0> , parse_dates = True , usecols = [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> df . index = c . utcify_index ( df . index ) <EOL> data = c . serialize ( df , header = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( data ) , len ( df ) ) <EOL> self . assertEqual ( data [ <NUM_LIT:0> ] , { '<STR_LIT>' : datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT:10> , tzinfo = pytz . utc ) , '<STR_LIT>' : <NUM_LIT> } ) <EOL> def test_parse_xls ( self ) : <EOL> c = client_factory ( '<STR_LIT>' ) <EOL> xd = c . fetch_xls ( c . base_url + '<STR_LIT>' ) <EOL> df = c . parse_to_df ( xd , mode = '<STR_LIT>' , sheet_names = xd . sheet_names , skiprows = <NUM_LIT> , <EOL> index_col = <NUM_LIT:0> , parse_dates = True , <EOL> parse_cols = [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:5> ] , header_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertEqual ( list ( df . columns ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertGreater ( len ( df ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( df . iloc [ <NUM_LIT:0> ] . name , datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) </s>
