<s> import imp <EOL> import unittest <EOL> from test import test_support <EOL> class LockTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def verify_lock_state ( self , expected ) : <EOL> self . assertEqual ( imp . lock_held ( ) , expected , <EOL> "<STR_LIT>" % expected ) <EOL> def testLock ( self ) : <EOL> LOOPS = <NUM_LIT:50> <EOL> lock_held_at_start = imp . lock_held ( ) <EOL> self . verify_lock_state ( lock_held_at_start ) <EOL> for i in range ( LOOPS ) : <EOL> imp . acquire_lock ( ) <EOL> self . verify_lock_state ( True ) <EOL> for i in range ( LOOPS ) : <EOL> imp . release_lock ( ) <EOL> self . verify_lock_state ( lock_held_at_start ) <EOL> if not lock_held_at_start : <EOL> try : <EOL> imp . release_lock ( ) <EOL> except RuntimeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> class ReloadTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_source ( self ) : <EOL> with test_support . EnvironmentVarGuard ( ) : <EOL> import os <EOL> imp . reload ( os ) <EOL> def test_extension ( self ) : <EOL> with test_support . CleanImport ( '<STR_LIT:time>' ) : <EOL> import time <EOL> imp . reload ( time ) <EOL> def test_builtin ( self ) : <EOL> with test_support . CleanImport ( '<STR_LIT>' ) : <EOL> import marshal <EOL> imp . reload ( marshal ) <EOL> def test_main ( ) : <EOL> tests = [ <EOL> ReloadTests , <EOL> ] <EOL> try : <EOL> import thread <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> tests . append ( LockTests ) <EOL> test_support . run_unittest ( * tests ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
