diff options
author | Scott Moser <smoser@ubuntu.com> | 2018-03-16 13:41:40 -0600 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2018-03-16 13:41:40 -0600 |
commit | 95bb226921b8075ca9f65a9d2b672a3e342498b7 (patch) | |
tree | 89252056f297907d205f3caaaf302874279359de /cloudinit/tests | |
parent | b7b7331b9c308d8e1cb0b3dfd4398e6e7cb1b60f (diff) | |
download | vyos-cloud-init-95bb226921b8075ca9f65a9d2b672a3e342498b7.tar.gz vyos-cloud-init-95bb226921b8075ca9f65a9d2b672a3e342498b7.zip |
tests: Make pylint happy and fix python2.6 uses of assertRaisesRegex.
Older unittest2.TestCase (as seen in CentOS 6) do not have an
assertRaisesRegex method. They only have the now-deprecated
assertRaisesRegexp.
We need our unit tests to work there and on newer python (3.6).
Simply making assertRaisesRegex = assertRaisesRegexp makes pylint
complain as described in https://github.com/PyCQA/pylint/issues/1946 .
What was here before this commit was actually broken. This commit
makes assertRaisesRegex functional in CentOS 6 and works around
the invalid Deprecated warning from pylint.
To prove this, we use assertRaisesRegex in a unit test which will
be exectued in py27, py3 and py26.
Diffstat (limited to 'cloudinit/tests')
-rw-r--r-- | cloudinit/tests/helpers.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/cloudinit/tests/helpers.py b/cloudinit/tests/helpers.py index 14c0b0bf..a2e10536 100644 --- a/cloudinit/tests/helpers.py +++ b/cloudinit/tests/helpers.py @@ -433,12 +433,12 @@ if not hasattr(mock.Mock, 'assert_not_called'): mock.Mock.assert_not_called = __mock_assert_not_called -# older unittest2.TestCase (centos6) do not have assertRaisesRegex -# And setting assertRaisesRegex to assertRaisesRegexp causes -# https://github.com/PyCQA/pylint/issues/1653 . So the workaround. +# older unittest2.TestCase (centos6) have only the now-deprecated +# assertRaisesRegexp. Simple assignment makes pylint complain, about +# users of assertRaisesRegex so we use getattr to trick it. +# https://github.com/PyCQA/pylint/issues/1946 if not hasattr(unittest2.TestCase, 'assertRaisesRegex'): - def _tricky(*args, **kwargs): - return unittest2.TestCase.assertRaisesRegexp - unittest2.TestCase.assertRaisesRegex = _tricky + unittest2.TestCase.assertRaisesRegex = ( + getattr(unittest2.TestCase, 'assertRaisesRegexp')) # vi: ts=4 expandtab |