<s> from pyiso import client_factory , BALANCING_AUTHORITIES <EOL> from pyiso . base import BaseClient <EOL> from pyiso . eu import EUClient <EOL> from unittest import TestCase <EOL> import pytz <EOL> from datetime import datetime , timedelta <EOL> class TestBaseLoad ( TestCase ) : <EOL> def setUp ( self ) : <EOL> bc = BaseClient ( ) <EOL> self . MARKET_CHOICES = bc . MARKET_CHOICES <EOL> self . FREQUENCY_CHOICES = bc . FREQUENCY_CHOICES <EOL> self . BA_CHOICES = BALANCING_AUTHORITIES . keys ( ) <EOL> def _run_test ( self , ba_name , expect_data = True , ** kwargs ) : <EOL> c = client_factory ( ba_name ) <EOL> data = c . get_load ( ** kwargs ) <EOL> if expect_data : <EOL> self . assertGreaterEqual ( len ( data ) , <NUM_LIT:1> ) <EOL> else : <EOL> self . assertEqual ( data , [ ] ) <EOL> for dp in data : <EOL> self . assertEqual ( set ( [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> set ( dp . keys ( ) ) ) <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] . tzinfo , pytz . utc ) <EOL> self . assertIn ( dp [ '<STR_LIT>' ] , self . BA_CHOICES ) <EOL> self . assertGreaterEqual ( dp [ '<STR_LIT>' ] + <NUM_LIT:1> , dp [ '<STR_LIT>' ] ) <EOL> if c . options [ '<STR_LIT>' ] : <EOL> self . assertGreaterEqual ( dp [ '<STR_LIT>' ] , pytz . utc . localize ( datetime . utcnow ( ) ) ) <EOL> else : <EOL> self . assertLess ( dp [ '<STR_LIT>' ] , pytz . utc . localize ( datetime . utcnow ( ) ) ) <EOL> return data <EOL> def _run_notimplemented_test ( self , ba_name , ** kwargs ) : <EOL> c = client_factory ( ba_name ) <EOL> self . assertRaises ( NotImplementedError , c . get_load ) <EOL> class TestBPALoad ( TestBaseLoad ) : <EOL> def test_latest ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , latest = True , market = self . MARKET_CHOICES . fivemin ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertEqual ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> for dp in data : <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . MARKET_CHOICES . fivemin ) <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . FREQUENCY_CHOICES . fivemin ) <EOL> def test_date_range ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today - timedelta ( days = <NUM_LIT:2> ) , <EOL> end_at = today - timedelta ( days = <NUM_LIT:1> ) ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> def test_date_range_farpast ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today - timedelta ( days = <NUM_LIT:20> ) , <EOL> end_at = today - timedelta ( days = <NUM_LIT:10> ) ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> class TestCAISOLoad ( TestBaseLoad ) : <EOL> def test_latest ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , latest = True , market = self . MARKET_CHOICES . fivemin ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertEqual ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> for dp in data : <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . MARKET_CHOICES . fivemin ) <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . FREQUENCY_CHOICES . fivemin ) <EOL> def test_date_range ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today - timedelta ( days = <NUM_LIT:2> ) , <EOL> end_at = today - timedelta ( days = <NUM_LIT:1> ) ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> def test_forecast ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today + timedelta ( hours = <NUM_LIT:20> ) , <EOL> end_at = today + timedelta ( days = <NUM_LIT:2> ) ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> class TestERCOTLoad ( TestBaseLoad ) : <EOL> def test_latest ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , latest = True , market = self . MARKET_CHOICES . fivemin ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertEqual ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> for dp in data : <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . MARKET_CHOICES . fivemin ) <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . FREQUENCY_CHOICES . fivemin ) <EOL> def test_forecast ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today + timedelta ( hours = <NUM_LIT:20> ) , <EOL> end_at = today + timedelta ( days = <NUM_LIT:2> ) ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> self . assertGreaterEqual ( min ( timestamps ) , today + timedelta ( hours = <NUM_LIT:20> ) ) <EOL> self . assertLessEqual ( min ( timestamps ) , today + timedelta ( days = <NUM_LIT:2> ) ) <EOL> class TestISONELoad ( TestBaseLoad ) : <EOL> def test_latest ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , latest = True ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertEqual ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> for dp in data : <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . MARKET_CHOICES . fivemin ) <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . FREQUENCY_CHOICES . fivemin ) <EOL> def test_date_range ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today - timedelta ( days = <NUM_LIT:2> ) , <EOL> end_at = today - timedelta ( days = <NUM_LIT:1> ) ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> def test_forecast ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , forecast = True , market = '<STR_LIT>' , freq = '<STR_LIT>' ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> class TestMISOLoad ( TestBaseLoad ) : <EOL> def test_forecast ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today + timedelta ( hours = <NUM_LIT:10> ) , <EOL> end_at = today + timedelta ( days = <NUM_LIT:2> ) ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> self . assertGreaterEqual ( min ( timestamps ) , today + timedelta ( hours = <NUM_LIT:10> ) ) <EOL> self . assertLessEqual ( min ( timestamps ) , today + timedelta ( days = <NUM_LIT:2> ) ) <EOL> class TestNEVPLoad ( TestBaseLoad ) : <EOL> def test_latest ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , latest = True ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertEqual ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> for dp in data : <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . MARKET_CHOICES . hourly ) <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . FREQUENCY_CHOICES . hourly ) <EOL> def test_date_range ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today - timedelta ( days = <NUM_LIT:1> ) , <EOL> end_at = today ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> def test_date_range_farpast ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today - timedelta ( days = <NUM_LIT> ) , <EOL> end_at = today - timedelta ( days = <NUM_LIT> ) ) <EOL> class TestNYISOLoad ( TestBaseLoad ) : <EOL> def test_latest ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , latest = True , market = self . MARKET_CHOICES . fivemin ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertEqual ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> for dp in data : <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . MARKET_CHOICES . fivemin ) <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . FREQUENCY_CHOICES . fivemin ) <EOL> def test_date_range ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today - timedelta ( days = <NUM_LIT:2> ) , <EOL> end_at = today - timedelta ( days = <NUM_LIT:1> ) ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> def test_forecast ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today + timedelta ( hours = <NUM_LIT:20> ) , <EOL> end_at = today + timedelta ( days = <NUM_LIT:2> ) ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> self . assertGreaterEqual ( min ( timestamps ) , today + timedelta ( hours = <NUM_LIT:20> ) ) <EOL> self . assertLessEqual ( min ( timestamps ) , today + timedelta ( days = <NUM_LIT:2> ) ) <EOL> class TestPJMLoad ( TestBaseLoad ) : <EOL> def test_latest ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , latest = True , market = self . MARKET_CHOICES . fivemin ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertEqual ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> for dp in data : <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . MARKET_CHOICES . fivemin ) <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . FREQUENCY_CHOICES . fivemin ) <EOL> def test_forecast ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today + timedelta ( hours = <NUM_LIT:20> ) , <EOL> end_at = today + timedelta ( days = <NUM_LIT:2> ) ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> self . assertGreaterEqual ( min ( timestamps ) , today + timedelta ( hours = <NUM_LIT:20> ) ) <EOL> self . assertLessEqual ( min ( timestamps ) , today + timedelta ( days = <NUM_LIT:2> ) ) <EOL> class TestSPPLoad ( TestBaseLoad ) : <EOL> def test_failing ( self ) : <EOL> self . _run_notimplemented_test ( '<STR_LIT>' ) <EOL> class TestSPPCLoad ( TestBaseLoad ) : <EOL> def test_latest ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , latest = True ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertEqual ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> for dp in data : <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . MARKET_CHOICES . hourly ) <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . FREQUENCY_CHOICES . hourly ) <EOL> def test_date_range ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today - timedelta ( days = <NUM_LIT:1> ) , <EOL> end_at = today ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> def test_date_range_farpast ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today - timedelta ( days = <NUM_LIT> ) , <EOL> end_at = today - timedelta ( days = <NUM_LIT> ) ) <EOL> class TestSVERILoad ( TestBaseLoad ) : <EOL> def setUp ( self ) : <EOL> super ( TestSVERILoad , self ) . setUp ( ) <EOL> self . bas = [ k for k , v in BALANCING_AUTHORITIES . items ( ) if v [ '<STR_LIT>' ] == '<STR_LIT>' ] <EOL> def test_latest_all ( self ) : <EOL> for ba in self . bas : <EOL> self . _test_latest ( ba ) <EOL> def test_date_range_all ( self ) : <EOL> for ba in self . bas : <EOL> self . _test_date_range ( ba ) <EOL> def _test_latest ( self , ba ) : <EOL> data = self . _run_test ( ba , latest = True ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertEqual ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> for dp in data : <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . MARKET_CHOICES . fivemin ) <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . FREQUENCY_CHOICES . fivemin ) <EOL> def _test_date_range ( self , ba ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( ba , start_at = today - timedelta ( days = <NUM_LIT:3> ) , <EOL> end_at = today - timedelta ( days = <NUM_LIT:2> ) , market = self . MARKET_CHOICES . fivemin ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> for dp in data : <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . MARKET_CHOICES . fivemin ) <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . FREQUENCY_CHOICES . fivemin ) <EOL> class TestEULoad ( TestBaseLoad ) : <EOL> def setUp ( self ) : <EOL> super ( TestEULoad , self ) . setUp ( ) <EOL> self . BA_CHOICES = EUClient . CONTROL_AREAS . keys ( ) <EOL> def test_latest ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , latest = True , market = self . MARKET_CHOICES . hourly , <EOL> control_area = '<STR_LIT>' ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertEqual ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> for dp in data : <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . MARKET_CHOICES . hourly ) <EOL> self . assertEqual ( dp [ '<STR_LIT>' ] , self . FREQUENCY_CHOICES . hourly ) <EOL> def test_date_range ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today - timedelta ( days = <NUM_LIT:2> ) , <EOL> end_at = today - timedelta ( days = <NUM_LIT:1> ) , <EOL> control_area = '<STR_LIT>' ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> def test_forecast ( self ) : <EOL> today = datetime . today ( ) . replace ( tzinfo = pytz . utc ) <EOL> data = self . _run_test ( '<STR_LIT>' , start_at = today + timedelta ( hours = <NUM_LIT:20> ) , <EOL> end_at = today + timedelta ( days = <NUM_LIT:1> ) , <EOL> control_area = '<STR_LIT>' ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) </s>
