summaryrefslogtreecommitdiff
path: root/tests/unittests/test_handler
diff options
context:
space:
mode:
authorDaniel Watkins <oddbloke@ubuntu.com>2020-04-24 09:26:51 -0400
committerGitHub <noreply@github.com>2020-04-24 09:26:51 -0400
commit38a7e6e9756fdab31264c0d6e93d20432ed111ac (patch)
treec71a79b98c883cf3657eaac6e6b2267dfb50f277 /tests/unittests/test_handler
parent7276aa5240b8cb84671a56d795d811f15dfba8e2 (diff)
downloadvyos-cloud-init-38a7e6e9756fdab31264c0d6e93d20432ed111ac.tar.gz
vyos-cloud-init-38a7e6e9756fdab31264c0d6e93d20432ed111ac.zip
cloudinit: drop dependencies on unittest2 and contextlib2 (#322)
These libraries provide backports of Python 3's stdlib components to Python 2. As we only support Python 3, we can simply use the stdlib now. This pull request does the following: * removes some unneeded compatibility code for the old spelling of `assertRaisesRegex` * replaces invocations of the Python 2-only `assertItemsEqual` with its new name, `assertCountEqual` * replaces all usage of `unittest2` with `unittest` * replaces all usage of `contextlib2` with `contextlib` * drops `unittest2` and `contextlib2` from requirements files and tox.ini It also rewrites some `test_azure` helpers to use bare asserts. We were seeing a strange error in xenial builds of this branch which appear to be stemming from the AssertionError that pytest produces being _different_ from the standard AssertionError. This means that the modified helpers weren't behaving correctly, because they weren't catching AssertionErrors as one would expect. (I believe this is related, in some way, to https://github.com/pytest-dev/pytest/issues/645, but the only version of pytest where we're affected is so far in the past that it's not worth pursuing it any further as we have a workaround.)
Diffstat (limited to 'tests/unittests/test_handler')
-rw-r--r--tests/unittests/test_handler/test_handler_ca_certs.py6
-rw-r--r--tests/unittests/test_handler/test_handler_chef.py8
-rw-r--r--tests/unittests/test_handler/test_handler_growpart.py6
-rw-r--r--tests/unittests/test_handler/test_schema.py4
4 files changed, 8 insertions, 16 deletions
diff --git a/tests/unittests/test_handler/test_handler_ca_certs.py b/tests/unittests/test_handler/test_handler_ca_certs.py
index 5b4105dd..286ef771 100644
--- a/tests/unittests/test_handler/test_handler_ca_certs.py
+++ b/tests/unittests/test_handler/test_handler_ca_certs.py
@@ -11,13 +11,9 @@ import logging
import shutil
import tempfile
import unittest
+from contextlib import ExitStack
from unittest import mock
-try:
- from contextlib import ExitStack
-except ImportError:
- from contextlib2 import ExitStack
-
class TestNoConfig(unittest.TestCase):
def setUp(self):
diff --git a/tests/unittests/test_handler/test_handler_chef.py b/tests/unittests/test_handler/test_handler_chef.py
index 2dab3a54..513c18b5 100644
--- a/tests/unittests/test_handler/test_handler_chef.py
+++ b/tests/unittests/test_handler/test_handler_chef.py
@@ -65,18 +65,18 @@ class TestInstallChefOmnibus(HttprettyTestCase):
cc_chef.install_chef_from_omnibus()
expected_kwargs = {'retries': cc_chef.OMNIBUS_URL_RETRIES,
'url': cc_chef.OMNIBUS_URL}
- self.assertItemsEqual(expected_kwargs, m_rdurl.call_args_list[0][1])
+ self.assertCountEqual(expected_kwargs, m_rdurl.call_args_list[0][1])
cc_chef.install_chef_from_omnibus(retries=10)
expected_kwargs = {'retries': 10,
'url': cc_chef.OMNIBUS_URL}
- self.assertItemsEqual(expected_kwargs, m_rdurl.call_args_list[1][1])
+ self.assertCountEqual(expected_kwargs, m_rdurl.call_args_list[1][1])
expected_subp_kwargs = {
'args': ['-v', '2.0'],
'basename': 'chef-omnibus-install',
'blob': m_rdurl.return_value.contents,
'capture': False
}
- self.assertItemsEqual(
+ self.assertCountEqual(
expected_subp_kwargs,
m_subp_blob.call_args_list[0][1])
@@ -97,7 +97,7 @@ class TestInstallChefOmnibus(HttprettyTestCase):
'blob': response,
'capture': False
}
- self.assertItemsEqual(expected_kwargs, called_kwargs)
+ self.assertCountEqual(expected_kwargs, called_kwargs)
class TestChef(FilesystemMockingTestCase):
diff --git a/tests/unittests/test_handler/test_handler_growpart.py b/tests/unittests/test_handler/test_handler_growpart.py
index 43b53745..501bcca5 100644
--- a/tests/unittests/test_handler/test_handler_growpart.py
+++ b/tests/unittests/test_handler/test_handler_growpart.py
@@ -11,13 +11,9 @@ import logging
import os
import re
import unittest
+from contextlib import ExitStack
from unittest import mock
-try:
- from contextlib import ExitStack
-except ImportError:
- from contextlib2 import ExitStack
-
# growpart:
# mode: auto # off, on, auto, 'growpart'
# devices: ['root']
diff --git a/tests/unittests/test_handler/test_schema.py b/tests/unittests/test_handler/test_schema.py
index abde02d3..98628120 100644
--- a/tests/unittests/test_handler/test_schema.py
+++ b/tests/unittests/test_handler/test_schema.py
@@ -20,7 +20,7 @@ class GetSchemaTest(CiTestCase):
def test_get_schema_coalesces_known_schema(self):
"""Every cloudconfig module with schema is listed in allOf keyword."""
schema = get_schema()
- self.assertItemsEqual(
+ self.assertCountEqual(
[
'cc_bootcmd',
'cc_ntp',
@@ -38,7 +38,7 @@ class GetSchemaTest(CiTestCase):
schema['$schema'])
# FULL_SCHEMA is updated by the get_schema call
from cloudinit.config.schema import FULL_SCHEMA
- self.assertItemsEqual(['id', '$schema', 'allOf'], FULL_SCHEMA.keys())
+ self.assertCountEqual(['id', '$schema', 'allOf'], FULL_SCHEMA.keys())
def test_get_schema_returns_global_when_set(self):
"""When FULL_SCHEMA global is already set, get_schema returns it."""