def setup_lockfile_method_mocks(testcase, scenario, class_name):
 def mock_read_pid():
  return scenario['pidfile_pid']
 def mock_is_locked():
  return (scenario['locking_pid'] is not None)
 def mock_i_am_locking():
  return (scenario['locking_pid'] == scenario['pid'])
 def mock_acquire(timeout=None):
  if (scenario['locking_pid'] is not None):
   raise lockfile.AlreadyLocked()
  scenario['locking_pid'] = scenario['pid']
 def mock_release():
  if (scenario['locking_pid'] is None):
   raise lockfile.NotLocked()
  if (scenario['locking_pid'] != scenario['pid']):
   raise lockfile.NotMyLock()
  scenario['locking_pid'] = None
 def mock_break_lock():
  scenario['locking_pid'] = None
 for func_name in ['read_pid', 'is_locked', 'i_am_locking', 'acquire', 'release', 'break_lock']:
  mock_func = vars()[('mock_%(func_name)s' % vars())]
  lockfile_func_name = ('%(class_name)s.%(func_name)s' % vars())
  mock_lockfile_func = scaffold.Mock(lockfile_func_name, returns_func=mock_func, tracker=testcase.mock_tracker)
  try:
   scaffold.mock(lockfile_func_name, mock_obj=mock_lockfile_func, tracker=testcase.mock_tracker)
  except NameError:
   pass

def setup_lockfile_method_mocks ( testcase , scenario , class_name ) : def mock_read_pid ( ) : return scenario [ 'pidfile_pid' ] def mock_is_locked ( ) : return ( scenario [ 'locking_pid' ] is not None ) def mock_i_am_locking ( ) : return ( scenario [ 'locking_pid' ] == scenario [ 'pid' ] ) def mock_acquire ( timeout = None ) : if ( scenario [ 'locking_pid' ] is not None ) : raise lockfile . AlreadyLocked ( ) scenario [ 'locking_pid' ] = scenario [ 'pid' ] def mock_release ( ) : if ( scenario [ 'locking_pid' ] is None ) : raise lockfile . NotLocked ( ) if ( scenario [ 'locking_pid' ] != scenario [ 'pid' ] ) : raise lockfile . NotMyLock ( ) scenario [ 'locking_pid' ] = None def mock_break_lock ( ) : scenario [ 'locking_pid' ] = None for func_name in [ 'read_pid' , 'is_locked' , 'i_am_locking' , 'acquire' , 'release' , 'break_lock' ] : mock_func = vars ( ) [ ( 'mock_%(func_name)s' % vars ( ) ) ] lockfile_func_name = ( '%(class_name)s.%(func_name)s' % vars ( ) ) mock_lockfile_func = scaffold . Mock ( lockfile_func_name , returns_func = mock_func , tracker = testcase . mock_tracker ) try : scaffold . mock ( lockfile_func_name , mock_obj = mock_lockfile_func , tracker = testcase . mock_tracker ) except NameError : pass
set up common mock methods for lockfile class .