<s> from pyiso import client_factory , BALANCING_AUTHORITIES <EOL> from pyiso . base import BaseClient <EOL> from unittest import TestCase <EOL> import pytz <EOL> from datetime import datetime , timedelta <EOL> class TestBaseLMP ( 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_lmp ( ** 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>' , '<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> now = pytz . utc . localize ( datetime . utcnow ( ) ) <EOL> if c . options [ '<STR_LIT>' ] : <EOL> self . assertGreaterEqual ( dp [ '<STR_LIT>' ] , now ) <EOL> elif c . options [ '<STR_LIT>' ] : <EOL> delta = now - dp [ '<STR_LIT>' ] <EOL> self . assertLess ( abs ( delta . total_seconds ( ) ) , <NUM_LIT> * <NUM_LIT> ) <EOL> else : <EOL> self . assertLess ( dp [ '<STR_LIT>' ] , now ) <EOL> return data <EOL> def _run_notimplemented_test ( self , ba_name , ** kwargs ) : <EOL> c = client_factory ( ba_name ) <EOL> self . assertRaises ( NotImplementedError , c . get_lmp ) <EOL> class TestCAISOLMP ( TestBaseLMP ) : <EOL> def test_latest ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , node_id = '<STR_LIT>' , <EOL> 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>' , node_id = '<STR_LIT>' , <EOL> 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> now = pytz . utc . localize ( datetime . utcnow ( ) ) <EOL> data = self . _run_test ( '<STR_LIT>' , node_id = '<STR_LIT>' , <EOL> start_at = now + timedelta ( hours = <NUM_LIT:20> ) , <EOL> end_at = now + timedelta ( days = <NUM_LIT:2> ) , <EOL> market = self . MARKET_CHOICES . dam ) <EOL> timestamps = [ d [ '<STR_LIT>' ] for d in data ] <EOL> self . assertGreater ( len ( set ( timestamps ) ) , <NUM_LIT:1> ) <EOL> def test_bad_node ( self ) : <EOL> self . _run_test ( '<STR_LIT>' , node_id = '<STR_LIT>' , expect_data = False , latest = True ) <EOL> class TestISONELMP ( TestBaseLMP ) : <EOL> def test_latest ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , node_id = '<STR_LIT>' , <EOL> 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>' , node_id = '<STR_LIT>' , <EOL> 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> class TestNYISOLMP ( TestBaseLMP ) : <EOL> def test_latest ( self ) : <EOL> data = self . _run_test ( '<STR_LIT>' , node_id = '<STR_LIT>' , <EOL> 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> now = pytz . utc . localize ( datetime . utcnow ( ) ) <EOL> data = self . _run_test ( '<STR_LIT>' , node_id = '<STR_LIT>' , <EOL> start_at = now , end_at = now + timedelta ( days = <NUM_LIT:1> ) ) <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 . dam ) <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>' , node_id = '<STR_LIT>' , <EOL> 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> ) </s>
