On Wed, Apr 24, 2013 at 5:00 PM, Thomas Thrainer <[email protected]>wrote:

> Based on the version of DRBD (as reported through /proc/drbd), the DRBD8
> class chooses helper objects which adapt for the differences between
> DRBD <= 8.3 and DRBD 8.4. This new test verifies that the proper objects
> are created.
>
> Signed-off-by: Thomas Thrainer <[email protected]>
> ---
>  test/py/ganeti.block.drbd_unittest.py | 42
> +++++++++++++++++++++++++++++++++++
>  test/py/testutils.py                  | 15 +++++++++++++
>  2 files changed, 57 insertions(+)
>
> diff --git a/test/py/ganeti.block.drbd_unittest.py b/test/py/
> ganeti.block.drbd_unittest.py
> index fc88ab6..284f131 100755
> --- a/test/py/ganeti.block.drbd_unittest.py
> +++ b/test/py/ganeti.block.drbd_unittest.py
> @@ -367,5 +367,47 @@ class TestDRBD8Status(testutils.GanetiTestCase):
>      self.assertAlmostEqual(stats.sync_percent, 68.5)
>
>
> +class TestDRBD8Construction(testutils.GanetiTestCase):
> +  def setUp(self):
> +    """Read in txt data"""
> +    testutils.GanetiTestCase.setUp(self)
> +    self.proc80_info = \
> +      drbd_info.DRBD8Info.CreateFromFile(
> +        filename=testutils.TestDataFilename("proc_drbd8.txt"))
> +    self.proc83_info = \
> +      drbd_info.DRBD8Info.CreateFromFile(
> +        filename=testutils.TestDataFilename("proc_drbd83.txt"))
> +    self.proc84_info = \
> +      drbd_info.DRBD8Info.CreateFromFile(
> +        filename=testutils.TestDataFilename("proc_drbd84.txt"))
> +
> +    self.test_unique_id = ("hosta.com", 123, "host2.com", 123, 0,
> "secret")
> +
> +  @testutils.patch_object(drbd_info.DRBD8Info, "CreateFromFile")
> +  def testConstructionWith80Data(self, mock_create_from_file):
> +    mock_create_from_file.return_value = self.proc80_info
> +
> +    inst = drbd.DRBD8(self.test_unique_id, [], 123, {})
> +    self.assertEqual(inst._show_info_cls, drbd_info.DRBD83ShowInfo)
> +    self.assertTrue(isinstance(inst._cmd_gen,
> drbd_cmdgen.DRBD83CmdGenerator))
> +
> +  @testutils.patch_object(drbd_info.DRBD8Info, "CreateFromFile")
> +  def testConstructionWith83Data(self, mock_create_from_file):
> +    mock_create_from_file.return_value = self.proc83_info
> +
> +    inst = drbd.DRBD8(self.test_unique_id, [], 123, {})
> +    self.assertEqual(inst._show_info_cls, drbd_info.DRBD83ShowInfo)
> +    self.assertTrue(isinstance(inst._cmd_gen,
> drbd_cmdgen.DRBD83CmdGenerator))
> +
> +  @testutils.patch_object(drbd_info.DRBD8Info, "CreateFromFile")
> +  def testConstructionWith84Data(self, mock_create_from_file):
> +    mock_create_from_file.return_value = self.proc84_info
> +
> +    inst = drbd.DRBD8(self.test_unique_id, [], 123, {})
> +    self.assertEqual(inst._show_info_cls, drbd_info.DRBD84ShowInfo)
> +    # FIXME: add assertion for right class here!
> +    self.assertEqual(inst._cmd_gen, None)
> +
> +
>  if __name__ == "__main__":
>    testutils.GanetiTestProgram()
> diff --git a/test/py/testutils.py b/test/py/testutils.py
> index 5459393..080efb5 100644
> --- a/test/py/testutils.py
> +++ b/test/py/testutils.py
> @@ -209,6 +209,21 @@ class GanetiTestCase(unittest.TestCase):
>      return fname
>
>
> +def patch_object(*args, **kwargs):
> +  """Unified patch_object for various versions of Python Mock.
> +
> +  Different Python Mock versions provide different versions of
> patch_object.
> +  More recent versions use patch.object, but all version have the
> _patch_object
> +  fallback.
> +
> +  """
> +  import mock
> +  try:
> +    return mock._patch_object(*args, **kwargs)
> +  except AttributeError:
> +    return mock.patch_object(*args, **kwargs)
>

The docstring and the code don't seem to be well aligned.
The docstring says that all the versions have _patch_object, but the code
uses patch_object as the fallback.
Please, fix one or the other.

Thanks,
Michele

Reply via email to