<s> try : <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> import unittest <EOL> from mock import Mock , patch <EOL> from shiva . indexer . lastfm import LastFM <EOL> class LastFMTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> import sys <EOL> sys . modules [ "<STR_LIT>" ] = Mock ( ) <EOL> api_key = '<STR_LIT>' <EOL> self . lastfm = LastFM ( api_key ) <EOL> def test_caches_artists ( self ) : <EOL> artist = self . lastfm . get_artist ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . lastfm . get_artist ( '<STR_LIT>' ) , artist ) <EOL> self . assertEqual ( self . lastfm . cache , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:object>' : artist <EOL> } <EOL> } ) <EOL> def test_clear_cache ( self ) : <EOL> self . lastfm . get_artist ( '<STR_LIT>' ) <EOL> _cache = self . lastfm . cache <EOL> self . lastfm . clear_cache ( ) <EOL> self . assertNotEqual ( self . lastfm . cache , _cache ) <EOL> def test_caches_albums ( self ) : <EOL> artist = self . lastfm . get_artist ( '<STR_LIT>' ) <EOL> artist . name = '<STR_LIT>' <EOL> album = self . lastfm . get_album ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> album . name = '<STR_LIT>' <EOL> self . assertEqual ( self . lastfm . get_album ( '<STR_LIT>' , '<STR_LIT>' ) , album ) <EOL> self . assertEqual ( self . lastfm . cache , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : album <EOL> } <EOL> } <EOL> } ) </s>
