summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Watkins <oddbloke@ubuntu.com>2020-01-21 18:02:42 -0500
committerChad Smith <chad.smith@canonical.com>2020-01-21 16:02:42 -0700
commitbb71a9d08d25193836eda91c328760305285574e (patch)
tree50a1f2f4a61e04255c5a8129e7a2a26d9d4cecd4 /tests
parent8c4fd886931abcf2cc8627a47463907d655b35c3 (diff)
downloadvyos-cloud-init-bb71a9d08d25193836eda91c328760305285574e.tar.gz
vyos-cloud-init-bb71a9d08d25193836eda91c328760305285574e.zip
Drop most of the remaining use of six (#179)
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_cli.py16
-rw-r--r--tests/unittests/test_datasource/test_smartos.py4
-rw-r--r--tests/unittests/test_handler/test_handler_chef.py3
-rw-r--r--tests/unittests/test_handler/test_handler_write_files.py15
-rw-r--r--tests/unittests/test_log.py11
-rw-r--r--tests/unittests/test_merging.py6
-rw-r--r--tests/unittests/test_util.py17
7 files changed, 33 insertions, 39 deletions
diff --git a/tests/unittests/test_cli.py b/tests/unittests/test_cli.py
index d283f136..e57c15d1 100644
--- a/tests/unittests/test_cli.py
+++ b/tests/unittests/test_cli.py
@@ -1,8 +1,8 @@
# This file is part of cloud-init. See LICENSE file for license information.
-from collections import namedtuple
import os
-import six
+import io
+from collections import namedtuple
from cloudinit.cmd import main as cli
from cloudinit.tests import helpers as test_helpers
@@ -18,7 +18,7 @@ class TestCLI(test_helpers.FilesystemMockingTestCase):
def setUp(self):
super(TestCLI, self).setUp()
- self.stderr = six.StringIO()
+ self.stderr = io.StringIO()
self.patchStdoutAndStderr(stderr=self.stderr)
def _call_main(self, sysv_args=None):
@@ -147,7 +147,7 @@ class TestCLI(test_helpers.FilesystemMockingTestCase):
def test_conditional_subcommands_from_entry_point_sys_argv(self):
"""Subcommands from entry-point are properly parsed from sys.argv."""
- stdout = six.StringIO()
+ stdout = io.StringIO()
self.patchStdoutAndStderr(stdout=stdout)
expected_errors = [
@@ -178,7 +178,7 @@ class TestCLI(test_helpers.FilesystemMockingTestCase):
def test_collect_logs_subcommand_parser(self):
"""The subcommand cloud-init collect-logs calls the subparser."""
# Provide -h param to collect-logs to avoid having to mock behavior.
- stdout = six.StringIO()
+ stdout = io.StringIO()
self.patchStdoutAndStderr(stdout=stdout)
self._call_main(['cloud-init', 'collect-logs', '-h'])
self.assertIn('usage: cloud-init collect-log', stdout.getvalue())
@@ -186,7 +186,7 @@ class TestCLI(test_helpers.FilesystemMockingTestCase):
def test_clean_subcommand_parser(self):
"""The subcommand cloud-init clean calls the subparser."""
# Provide -h param to clean to avoid having to mock behavior.
- stdout = six.StringIO()
+ stdout = io.StringIO()
self.patchStdoutAndStderr(stdout=stdout)
self._call_main(['cloud-init', 'clean', '-h'])
self.assertIn('usage: cloud-init clean', stdout.getvalue())
@@ -194,7 +194,7 @@ class TestCLI(test_helpers.FilesystemMockingTestCase):
def test_status_subcommand_parser(self):
"""The subcommand cloud-init status calls the subparser."""
# Provide -h param to clean to avoid having to mock behavior.
- stdout = six.StringIO()
+ stdout = io.StringIO()
self.patchStdoutAndStderr(stdout=stdout)
self._call_main(['cloud-init', 'status', '-h'])
self.assertIn('usage: cloud-init status', stdout.getvalue())
@@ -219,7 +219,7 @@ class TestCLI(test_helpers.FilesystemMockingTestCase):
def test_wb_devel_schema_subcommand_doc_content(self):
"""Validate that doc content is sane from known examples."""
- stdout = six.StringIO()
+ stdout = io.StringIO()
self.patchStdoutAndStderr(stdout=stdout)
self._call_main(['cloud-init', 'devel', 'schema', '--doc'])
expected_doc_sections = [
diff --git a/tests/unittests/test_datasource/test_smartos.py b/tests/unittests/test_datasource/test_smartos.py
index d5b1c29c..62084de5 100644
--- a/tests/unittests/test_datasource/test_smartos.py
+++ b/tests/unittests/test_datasource/test_smartos.py
@@ -33,8 +33,6 @@ from cloudinit.sources.DataSourceSmartOS import (
identify_file)
from cloudinit.event import EventType
-import six
-
from cloudinit import helpers as c_helpers
from cloudinit.util import (
b64e, subp, ProcessExecutionError, which, write_file)
@@ -798,7 +796,7 @@ class TestJoyentMetadataClient(FilesystemMockingTestCase):
return self.serial.write.call_args[0][0]
def test_get_metadata_writes_bytes(self):
- self.assertIsInstance(self._get_written_line(), six.binary_type)
+ self.assertIsInstance(self._get_written_line(), bytes)
def test_get_metadata_line_starts_with_v2(self):
foo = self._get_written_line()
diff --git a/tests/unittests/test_handler/test_handler_chef.py b/tests/unittests/test_handler/test_handler_chef.py
index f4311268..2dab3a54 100644
--- a/tests/unittests/test_handler/test_handler_chef.py
+++ b/tests/unittests/test_handler/test_handler_chef.py
@@ -4,7 +4,6 @@ import httpretty
import json
import logging
import os
-import six
from cloudinit import cloud
from cloudinit.config import cc_chef
@@ -178,7 +177,7 @@ class TestChef(FilesystemMockingTestCase):
continue
# the value from the cfg overrides that in the default
val = cfg['chef'].get(k, v)
- if isinstance(val, six.string_types):
+ if isinstance(val, str):
self.assertIn(val, c)
c = util.load_file(cc_chef.CHEF_FB_PATH)
self.assertEqual({}, json.loads(c))
diff --git a/tests/unittests/test_handler/test_handler_write_files.py b/tests/unittests/test_handler/test_handler_write_files.py
index bc8756ca..ed0a4da2 100644
--- a/tests/unittests/test_handler/test_handler_write_files.py
+++ b/tests/unittests/test_handler/test_handler_write_files.py
@@ -1,17 +1,16 @@
# This file is part of cloud-init. See LICENSE file for license information.
-from cloudinit.config.cc_write_files import write_files, decode_perms
-from cloudinit import log as logging
-from cloudinit import util
-
-from cloudinit.tests.helpers import CiTestCase, FilesystemMockingTestCase
-
import base64
import gzip
+import io
import shutil
-import six
import tempfile
+from cloudinit import log as logging
+from cloudinit import util
+from cloudinit.config.cc_write_files import write_files, decode_perms
+from cloudinit.tests.helpers import CiTestCase, FilesystemMockingTestCase
+
LOG = logging.getLogger(__name__)
YAML_TEXT = """
@@ -138,7 +137,7 @@ class TestDecodePerms(CiTestCase):
def _gzip_bytes(data):
- buf = six.BytesIO()
+ buf = io.BytesIO()
fp = None
try:
fp = gzip.GzipFile(fileobj=buf, mode="wb")
diff --git a/tests/unittests/test_log.py b/tests/unittests/test_log.py
index cd6296d6..e069a487 100644
--- a/tests/unittests/test_log.py
+++ b/tests/unittests/test_log.py
@@ -2,14 +2,15 @@
"""Tests for cloudinit.log """
-from cloudinit.analyze.dump import CLOUD_INIT_ASCTIME_FMT
-from cloudinit import log as ci_logging
-from cloudinit.tests.helpers import CiTestCase
import datetime
+import io
import logging
-import six
import time
+from cloudinit import log as ci_logging
+from cloudinit.analyze.dump import CLOUD_INIT_ASCTIME_FMT
+from cloudinit.tests.helpers import CiTestCase
+
class TestCloudInitLogger(CiTestCase):
@@ -18,7 +19,7 @@ class TestCloudInitLogger(CiTestCase):
# of sys.stderr, we'll plug in a StringIO() object so we can see
# what gets logged
logging.Formatter.converter = time.gmtime
- self.ci_logs = six.StringIO()
+ self.ci_logs = io.StringIO()
self.ci_root = logging.getLogger()
console = logging.StreamHandler(self.ci_logs)
console.setFormatter(logging.Formatter(ci_logging.DEF_CON_FORMAT))
diff --git a/tests/unittests/test_merging.py b/tests/unittests/test_merging.py
index 3a5072c7..10871bcf 100644
--- a/tests/unittests/test_merging.py
+++ b/tests/unittests/test_merging.py
@@ -13,13 +13,11 @@ import glob
import os
import random
import re
-import six
import string
SOURCE_PAT = "source*.*yaml"
EXPECTED_PAT = "expected%s.yaml"
-TYPES = [dict, str, list, tuple, None]
-TYPES.extend(six.integer_types)
+TYPES = [dict, str, list, tuple, None, int]
def _old_mergedict(src, cand):
@@ -85,7 +83,7 @@ def _make_dict(current_depth, max_depth, rand):
pass
if t in [tuple]:
base = tuple(base)
- elif t in six.integer_types:
+ elif t in [int]:
base = rand.randint(0, 2 ** 8)
elif t in [str]:
base = _random_str(rand)
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 0e71db82..75a3f0b4 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -2,16 +2,15 @@
from __future__ import print_function
+import io
+import json
import logging
import os
import re
import shutil
import stat
-import tempfile
-
-import json
-import six
import sys
+import tempfile
import yaml
from cloudinit import importer, util
@@ -320,7 +319,7 @@ class TestLoadYaml(helpers.CiTestCase):
def test_python_unicode(self):
# complex type of python/unicode is explicitly allowed
- myobj = {'1': six.text_type("FOOBAR")}
+ myobj = {'1': "FOOBAR"}
safe_yaml = yaml.dump(myobj)
self.assertEqual(util.load_yaml(blob=safe_yaml,
default=self.mydefault),
@@ -663,8 +662,8 @@ class TestMultiLog(helpers.FilesystemMockingTestCase):
self.patchOS(self.root)
self.patchUtils(self.root)
self.patchOpen(self.root)
- self.stdout = six.StringIO()
- self.stderr = six.StringIO()
+ self.stdout = io.StringIO()
+ self.stderr = io.StringIO()
self.patchStdoutAndStderr(self.stdout, self.stderr)
def test_stderr_used_by_default(self):
@@ -879,8 +878,8 @@ class TestSubp(helpers.CiTestCase):
"""Raised exc should have stderr, stdout as string if no decode."""
with self.assertRaises(util.ProcessExecutionError) as cm:
util.subp([BOGUS_COMMAND], decode=True)
- self.assertTrue(isinstance(cm.exception.stdout, six.string_types))
- self.assertTrue(isinstance(cm.exception.stderr, six.string_types))
+ self.assertTrue(isinstance(cm.exception.stdout, str))
+ self.assertTrue(isinstance(cm.exception.stderr, str))
def test_bunch_of_slashes_in_path(self):
self.assertEqual("/target/my/path/",