<s> """<STR_LIT>""" <EOL> import os <EOL> import common <EOL> from pyalgotrade . tools import yahoofinance <EOL> from pyalgotrade import bar <EOL> from pyalgotrade . barfeed import yahoofeed <EOL> class ToolsTestCase ( common . TestCase ) : <EOL> def testDownloadAndParseDaily ( self ) : <EOL> instrument = "<STR_LIT>" <EOL> with common . TmpDir ( ) as tmp_path : <EOL> path = os . path . join ( tmp_path , "<STR_LIT>" ) <EOL> yahoofinance . download_daily_bars ( instrument , <NUM_LIT> , path ) <EOL> bf = yahoofeed . Feed ( ) <EOL> bf . addBarsFromCSV ( instrument , path ) <EOL> bf . loadAll ( ) <EOL> self . assertEqual ( round ( bf [ instrument ] [ - <NUM_LIT:1> ] . getOpen ( ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> self . assertEqual ( round ( bf [ instrument ] [ - <NUM_LIT:1> ] . getClose ( ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> def testDownloadAndParseWeekly ( self ) : <EOL> instrument = "<STR_LIT>" <EOL> with common . TmpDir ( ) as tmp_path : <EOL> path = os . path . join ( tmp_path , "<STR_LIT>" ) <EOL> yahoofinance . download_weekly_bars ( instrument , <NUM_LIT> , path ) <EOL> bf = yahoofeed . Feed ( frequency = bar . Frequency . WEEK ) <EOL> bf . addBarsFromCSV ( instrument , path ) <EOL> bf . loadAll ( ) <EOL> self . assertEqual ( round ( bf [ instrument ] [ - <NUM_LIT:1> ] . getOpen ( ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> self . assertEqual ( round ( bf [ instrument ] [ - <NUM_LIT:1> ] . getHigh ( ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> self . assertEqual ( round ( bf [ instrument ] [ - <NUM_LIT:1> ] . getLow ( ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> self . assertEqual ( round ( bf [ instrument ] [ - <NUM_LIT:1> ] . getClose ( ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> self . assertTrue ( bf [ instrument ] [ - <NUM_LIT:1> ] . getVolume ( ) in ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> def testBuildDailyFeed ( self ) : <EOL> with common . TmpDir ( ) as tmpPath : <EOL> instrument = "<STR_LIT>" <EOL> bf = yahoofinance . build_feed ( [ instrument ] , <NUM_LIT> , <NUM_LIT> , storage = tmpPath ) <EOL> bf . loadAll ( ) <EOL> self . assertEqual ( round ( bf [ instrument ] [ - <NUM_LIT:1> ] . getOpen ( ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> self . assertEqual ( round ( bf [ instrument ] [ - <NUM_LIT:1> ] . getClose ( ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> def testBuildWeeklyFeed ( self ) : <EOL> with common . TmpDir ( ) as tmpPath : <EOL> instrument = "<STR_LIT>" <EOL> bf = yahoofinance . build_feed ( [ instrument ] , <NUM_LIT> , <NUM_LIT> , storage = tmpPath , frequency = bar . Frequency . WEEK ) <EOL> bf . loadAll ( ) <EOL> self . assertEqual ( round ( bf [ instrument ] [ - <NUM_LIT:1> ] . getOpen ( ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> self . assertEqual ( round ( bf [ instrument ] [ - <NUM_LIT:1> ] . getHigh ( ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> self . assertEqual ( round ( bf [ instrument ] [ - <NUM_LIT:1> ] . getLow ( ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> self . assertEqual ( round ( bf [ instrument ] [ - <NUM_LIT:1> ] . getClose ( ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> self . assertTrue ( bf [ instrument ] [ - <NUM_LIT:1> ] . getVolume ( ) in ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> def testInvalidDates ( self ) : <EOL> instrument = "<STR_LIT>" <EOL> with self . assertRaisesRegexp ( Exception , "<STR_LIT>" ) : <EOL> with common . TmpDir ( ) as tmpPath : <EOL> bf = yahoofinance . build_feed ( [ instrument ] , <NUM_LIT> , <NUM_LIT> , storage = tmpPath , frequency = bar . Frequency . DAY ) <EOL> with common . TmpDir ( ) as tmpPath : <EOL> bf = yahoofinance . build_feed ( <EOL> [ instrument ] , <NUM_LIT> , <NUM_LIT> , storage = tmpPath , frequency = bar . Frequency . DAY , skipErrors = True <EOL> ) <EOL> bf . loadAll ( ) <EOL> self . assertNotIn ( instrument , bf ) </s>
