<s> """<STR_LIT>""" <EOL> from django . test import TestCase <EOL> from seed import decorators <EOL> from seed . utils . cache import make_key , get_cache , get_lock , increment_cache , clear_cache <EOL> class TestException ( Exception ) : <EOL> pass <EOL> class TestDecorators ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> locked = <NUM_LIT:1> <EOL> unlocked = <NUM_LIT:0> <EOL> pk = <NUM_LIT> <EOL> def setUp ( self ) : <EOL> clear_cache ( ) <EOL> def test_get_prog_key ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = make_key ( '<STR_LIT>' + str ( self . pk ) ) <EOL> self . assertEqual ( decorators . get_prog_key ( '<STR_LIT>' , self . pk ) , expected ) <EOL> def test_increment_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> expected = <NUM_LIT> <EOL> test_key = make_key ( '<STR_LIT>' ) <EOL> increment = <NUM_LIT> <EOL> increment_cache ( test_key , increment ) <EOL> self . assertEqual ( float ( get_cache ( test_key ) [ '<STR_LIT>' ] ) , expected ) <EOL> increment_cache ( test_key , increment ) <EOL> expected = <NUM_LIT> <EOL> self . assertEqual ( float ( get_cache ( test_key ) [ '<STR_LIT>' ] ) , expected ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> increment_cache ( test_key , increment ) <EOL> expected = <NUM_LIT> <EOL> self . assertEqual ( float ( get_cache ( test_key ) [ '<STR_LIT>' ] ) , expected ) <EOL> def test_locking ( self ) : <EOL> """<STR_LIT>""" <EOL> key = decorators . _get_lock_key ( '<STR_LIT>' , self . pk ) <EOL> self . assertEqual ( int ( get_lock ( key ) ) , self . unlocked ) <EOL> @ decorators . lock_and_track <EOL> def fake_func ( import_file_pk ) : <EOL> self . assertEqual ( int ( get_lock ( key ) ) , self . locked ) <EOL> fake_func ( self . pk ) <EOL> self . assertEqual ( int ( get_lock ( key ) ) , self . unlocked ) <EOL> def test_locking_w_exception ( self ) : <EOL> """<STR_LIT>""" <EOL> key = decorators . _get_lock_key ( '<STR_LIT>' , self . pk ) <EOL> @ decorators . lock_and_track <EOL> def fake_func ( import_file_pk ) : <EOL> self . assertEqual ( int ( get_lock ( key ) ) , self . locked ) <EOL> raise TestException ( '<STR_LIT>' ) <EOL> self . assertRaises ( TestException , fake_func , self . pk ) <EOL> self . assertEqual ( int ( get_lock ( key ) ) , self . unlocked ) <EOL> def test_progress ( self ) : <EOL> """<STR_LIT>""" <EOL> increment = expected = <NUM_LIT> <EOL> key = decorators . get_prog_key ( '<STR_LIT>' , self . pk ) <EOL> self . assertEqual ( float ( get_cache ( key , <NUM_LIT:0.0> ) [ '<STR_LIT>' ] ) , <NUM_LIT:0.0> ) <EOL> @ decorators . lock_and_track <EOL> def fake_func ( import_file_pk ) : <EOL> increment_cache ( key , increment ) <EOL> fake_func ( self . pk ) <EOL> self . assertEqual ( float ( get_cache ( key , <NUM_LIT:0.0> ) [ '<STR_LIT>' ] ) , expected ) </s>
