<s> import os <EOL> import testtools <EOL> from neutron . common import utils <EOL> from neutron . tests import base <EOL> from neutron . tests . common . exclusive_resources import resource_allocator <EOL> def safe_remove_file ( file_path ) : <EOL> try : <EOL> os . remove ( file_path ) <EOL> except OSError : <EOL> pass <EOL> class TestResourceAllocator ( base . DietTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestResourceAllocator , self ) . setUp ( ) <EOL> self . ra = resource_allocator . ResourceAllocator ( <EOL> utils . get_random_string ( <NUM_LIT:6> ) , lambda : <NUM_LIT> ) <EOL> self . addCleanup ( safe_remove_file , self . ra . _state_file_path ) <EOL> def test_allocate_and_release ( self ) : <EOL> resource = self . ra . allocate ( ) <EOL> self . assertEqual ( '<STR_LIT>' , resource ) <EOL> with testtools . ExpectedException ( ValueError ) : <EOL> self . ra . allocate ( ) <EOL> self . ra . release ( resource ) <EOL> resource = self . ra . allocate ( ) <EOL> self . assertEqual ( '<STR_LIT>' , resource ) <EOL> def test_file_manipulation ( self ) : <EOL> self . assertFalse ( os . path . exists ( self . ra . _state_file_path ) ) <EOL> resource = self . ra . allocate ( ) <EOL> self . assertTrue ( os . path . exists ( self . ra . _state_file_path ) ) <EOL> self . ra . release ( resource ) <EOL> self . assertFalse ( os . path . exists ( self . ra . _state_file_path ) ) </s>
