Revision e969a81f test/py/cmdlib/testsupport/iallocator_mock.py

b/test/py/cmdlib/testsupport/iallocator_mock.py
24 24

  
25 25
import mock
26 26

  
27
from ganeti.masterd import iallocator
28 27

  
28
# pylint: disable=C0103
29
def patchIAllocator(module_under_test):
30
  """Patches the L{ganeti.masterd.iallocator.IAllocator} class for tests.
29 31

  
30
def CreateIAllocatorMock():
31
  """Creates a new L{mock.MagicMock} tailored for L{iallocator.IAllocator}
32
  This function is meant to be used as a decorator for test methods.
33

  
34
  @type module_under_test: string
35
  @param module_under_test: the module within cmdlib which is tested. The
36
        "ganeti.cmdlib" prefix is optional.
32 37

  
33 38
  """
34
  ret = mock.MagicMock(spec=iallocator.IAllocator)
35
  return ret
39
  if not module_under_test.startswith("ganeti.cmdlib"):
40
    module_under_test = "ganeti.cmdlib." + module_under_test
41
  return mock.patch("%s.iallocator.IAllocator" % module_under_test)

Also available in: Unified diff