From 8ba9abb45b800c912fe7856ba376b8dbf66e5f9f Mon Sep 17 00:00:00 2001 From: Ryan Beisner Date: Thu, 1 Nov 2018 21:46:59 -0500 Subject: [PATCH] Fix lint in unit tests re: py3-first and py2 compat Use local heler for now due to the transitional state of this charm from py2 to py3, where cmp does not exist. Change-Id: I86161b8886da69833c4cc074c0f7ede15f456c9d --- hooks/percona_utils.py | 7 ++++++- unit_tests/test_utils.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/hooks/percona_utils.py b/hooks/percona_utils.py index 2301655..8eecfe4 100644 --- a/hooks/percona_utils.py +++ b/hooks/percona_utils.py @@ -405,10 +405,15 @@ def assert_charm_supports_ipv6(): "versions less than Trusty 14.04") +def _cmp(x, y): + """Shim for py2 py3 compat.""" + return (x > y) - (x < y) + + def unit_sorted(units): """Return a sorted list of unit names.""" return sorted( - units, lambda a, b: cmp(int(a.split('/')[-1]), int(b.split('/')[-1]))) + units, lambda a, b: _cmp(int(a.split('/')[-1]), int(b.split('/')[-1]))) def install_mysql_ocf(): diff --git a/unit_tests/test_utils.py b/unit_tests/test_utils.py index 8ae9185..d8838ca 100644 --- a/unit_tests/test_utils.py +++ b/unit_tests/test_utils.py @@ -130,7 +130,7 @@ def patch_open(): Yields the mock for "open" and "file", respectively.''' mock_open = MagicMock(spec=open) - mock_file = MagicMock(spec=file) + mock_file = MagicMock(spec=__file__) @contextmanager def stub_open(*args, **kwargs):