<s> from unittest import TestCase <EOL> from zipline . utils import tradingcalendar <EOL> from zipline . utils import tradingcalendar_lse <EOL> from zipline . utils import tradingcalendar_tse <EOL> from zipline . utils import tradingcalendar_bmf <EOL> import pytz <EOL> import datetime <EOL> from zipline . finance . trading import TradingEnvironment <EOL> from nose . tools import nottest <EOL> class TestTradingCalendar ( TestCase ) : <EOL> def test_calendar_vs_environment ( self ) : <EOL> """<STR_LIT>""" <EOL> env = TradingEnvironment ( ) <EOL> bench_days = env . benchmark_returns [ tradingcalendar . start : ] . index <EOL> bounds = env . trading_days . slice_locs ( start = tradingcalendar . start , <EOL> end = bench_days [ - <NUM_LIT:1> ] ) <EOL> env_days = env . trading_days [ bounds [ <NUM_LIT:0> ] : bounds [ <NUM_LIT:1> ] ] <EOL> self . check_days ( env_days , bench_days ) <EOL> @ nottest <EOL> def test_lse_calendar_vs_environment ( self ) : <EOL> env = TradingEnvironment ( <EOL> bm_symbol = '<STR_LIT>' , <EOL> exchange_tz = '<STR_LIT>' <EOL> ) <EOL> env_start_index = env . trading_days . searchsorted ( tradingcalendar_lse . start ) <EOL> env_days = env . trading_days [ env_start_index : ] <EOL> cal_days = tradingcalendar_lse . trading_days <EOL> self . check_days ( env_days , cal_days ) <EOL> @ nottest <EOL> def test_tse_calendar_vs_environment ( self ) : <EOL> env = TradingEnvironment ( <EOL> bm_symbol = '<STR_LIT>' , <EOL> exchange_tz = '<STR_LIT>' <EOL> ) <EOL> env_start_index = env . trading_days . searchsorted ( tradingcalendar_tse . start ) <EOL> env_days = env . trading_days [ env_start_index : ] <EOL> cal_days = tradingcalendar_tse . trading_days <EOL> self . check_days ( env_days , cal_days ) <EOL> @ nottest <EOL> def test_bmf_calendar_vs_environment ( self ) : <EOL> env = TradingEnvironment ( <EOL> bm_symbol = '<STR_LIT>' , <EOL> exchange_tz = '<STR_LIT>' <EOL> ) <EOL> env_start_index = env . trading_days . searchsorted ( tradingcalendar_bmf . start ) <EOL> env_days = env . trading_days [ env_start_index : ] <EOL> cal_days = tradingcalendar_bmf . trading_days <EOL> self . check_days ( env_days , cal_days ) <EOL> def check_days ( self , env_days , cal_days ) : <EOL> diff = env_days . difference ( cal_days ) <EOL> self . assertEqual ( <EOL> len ( diff ) , <EOL> <NUM_LIT:0> , <EOL> "<STR_LIT>" . format ( diff = diff ) <EOL> ) <EOL> diff2 = cal_days . difference ( env_days ) <EOL> self . assertEqual ( <EOL> len ( diff2 ) , <EOL> <NUM_LIT:0> , <EOL> "<STR_LIT>" . format ( diff = diff2 ) <EOL> ) <EOL> def test_newyears ( self ) : <EOL> """<STR_LIT>""" <EOL> day_after_new_years_sunday = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> , tzinfo = pytz . utc ) <EOL> self . assertNotIn ( day_after_new_years_sunday , <EOL> tradingcalendar . trading_days , <EOL> """<STR_LIT>""" . strip ( ) . format ( day_after_new_years_sunday ) <EOL> ) <EOL> first_trading_day_after_new_years_sunday = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> , tzinfo = pytz . utc ) <EOL> self . assertIn ( first_trading_day_after_new_years_sunday , <EOL> tradingcalendar . trading_days , <EOL> """<STR_LIT>""" . strip ( ) . format ( first_trading_day_after_new_years_sunday ) <EOL> ) <EOL> new_years_day = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , tzinfo = pytz . utc ) <EOL> self . assertNotIn ( new_years_day , <EOL> tradingcalendar . trading_days , <EOL> """<STR_LIT>""" . strip ( ) . format ( new_years_day ) <EOL> ) <EOL> first_trading_day_after_new_years = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> , tzinfo = pytz . utc ) <EOL> self . assertIn ( first_trading_day_after_new_years , <EOL> tradingcalendar . trading_days , <EOL> """<STR_LIT>""" . strip ( ) . format ( first_trading_day_after_new_years ) <EOL> ) <EOL> def test_thanksgiving ( self ) : <EOL> """<STR_LIT>""" <EOL> thanksgiving_with_four_weeks = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT> , tzinfo = pytz . utc ) <EOL> self . assertNotIn ( thanksgiving_with_four_weeks , <EOL> tradingcalendar . trading_days , <EOL> """<STR_LIT>""" . strip ( ) . format ( thanksgiving_with_four_weeks ) <EOL> ) <EOL> thanksgiving_with_five_weeks = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT> , tzinfo = pytz . utc ) <EOL> self . assertNotIn ( thanksgiving_with_five_weeks , <EOL> tradingcalendar . trading_days , <EOL> """<STR_LIT>""" . strip ( ) . format ( thanksgiving_with_five_weeks ) <EOL> ) <EOL> first_trading_day_after_new_years_sunday = datetime . datetime ( <EOL> <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:3> , tzinfo = pytz . utc ) <EOL> self . assertIn ( first_trading_day_after_new_years_sunday , <EOL> tradingcalendar . trading_days , <EOL> """<STR_LIT>""" . strip ( ) . format ( first_trading_day_after_new_years_sunday ) <EOL> ) <EOL> def test_day_after_thanksgiving ( self ) : <EOL> early_closes = tradingcalendar . get_early_closes ( <EOL> tradingcalendar . start , <EOL> tradingcalendar . end . replace ( year = tradingcalendar . end . year + <NUM_LIT:1> ) <EOL> ) <EOL> fourth_friday = datetime . datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT> , tzinfo = pytz . utc ) <EOL> self . assertIn ( fourth_friday , early_closes ) <EOL> fifth_friday = datetime . datetime ( <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT> , tzinfo = pytz . utc ) <EOL> self . assertIn ( fifth_friday , early_closes ) <EOL> def test_early_close_independence_day_thursday ( self ) : <EOL> """<STR_LIT>""" <EOL> early_closes = tradingcalendar . get_early_closes ( <EOL> tradingcalendar . start , <EOL> tradingcalendar . end . replace ( year = tradingcalendar . end . year + <NUM_LIT:1> ) <EOL> ) <EOL> wednesday_before = datetime . datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:3> , tzinfo = pytz . utc ) <EOL> friday_after = datetime . datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:5> , tzinfo = pytz . utc ) <EOL> self . assertNotIn ( wednesday_before , early_closes ) <EOL> self . assertIn ( friday_after , early_closes ) <EOL> wednesday_before = datetime . datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:3> , tzinfo = pytz . utc ) <EOL> friday_after = datetime . datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:5> , tzinfo = pytz . utc ) <EOL> self . assertIn ( wednesday_before , early_closes ) <EOL> self . assertNotIn ( friday_after , early_closes ) </s>
