LGTM

On Thu, Jun 9, 2016 at 11:33 PM, Iustin Pop <ius...@k1024.org> wrote:

> From: Iustin Pop <ius...@google.com>
>
> It seems the two alternatives for python-mock's way of patching objects
> are not
> enough; more recent versions have patch.object, so let's support that as
> well.
> I think this is post 1.0.1, but not entirely sure.
>
> Additionally, move the import and check for patcher at top level, so
> they're
> not executed each time patch_object is called.
>
> Side-note: it seems there are many ways we call patch object in the code,
> some
> cleanup would be in order but that's left for another time.
>
> Signed-off-by: Iustin Pop <ius...@google.com>
> ---
>  test/py/testutils/__init__.py | 33 +++++++++++++++++++--------------
>  1 file changed, 19 insertions(+), 14 deletions(-)
>
> diff --git a/test/py/testutils/__init__.py b/test/py/testutils/__init__.py
> index 27ca425..f2e63b5 100644
> --- a/test/py/testutils/__init__.py
> +++ b/test/py/testutils/__init__.py
> @@ -37,6 +37,23 @@ import tempfile
>  import unittest
>  import logging
>
> +# Unified patch_object for various versions of Python Mock.
> +#
> +# Different Python Mock versions provide incompatible versions of
> patching an
> +# object. More recent versions use _patch_object, older ones used
> patch_object.
> +# This unifies the different variations.
> +import mock
> +
> +try:
> +  # pylint: disable=W0212
> +  _patcher = mock._patch_object
> +except AttributeError:
> +  # pylint: disable=E1101
> +  try:
> +    _patcher = mock.patch_object
> +  except AttributeError:
> +    _patcher = mock.patch.object
> +
>  from ganeti import utils
>
>
> @@ -235,20 +252,8 @@ class GanetiTestCase(unittest.TestCase):
>
>
>  def patch_object(*args, **kwargs):
> -  """Unified patch_object for various versions of Python Mock.
> -
> -  Different Python Mock versions provide incompatible versions of
> patching an
> -  object. More recent versions use _patch_object, older ones used
> patch_object.
> -  This function unifies the different variations.
> -
> -  """
> -  import mock
> -  try:
> -    # pylint: disable=W0212
> -    return mock._patch_object(*args, **kwargs)
> -  except AttributeError:
> -    # pylint: disable=E1101
> -    return mock.patch_object(*args, **kwargs)
> +  """Unified patch_object for various versions of Python Mock."""
> +  return _patcher(*args, **kwargs)
>
>
>  def UnifyValueType(data):
> --
> 2.8.1
>
>

Reply via email to