summaryrefslogtreecommitdiff
path: root/tests/unittests/test_merging.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests/test_merging.py')
-rw-r--r--tests/unittests/test_merging.py123
1 files changed, 62 insertions, 61 deletions
diff --git a/tests/unittests/test_merging.py b/tests/unittests/test_merging.py
index 48ab6602..cf484dda 100644
--- a/tests/unittests/test_merging.py
+++ b/tests/unittests/test_merging.py
@@ -1,13 +1,5 @@
# This file is part of cloud-init. See LICENSE file for license information.
-from tests.unittests import helpers
-
-from cloudinit.handlers import cloud_config
-from cloudinit.handlers import (CONTENT_START, CONTENT_END)
-
-from cloudinit import helpers as c_helpers
-from cloudinit import util
-
import collections
import glob
import os
@@ -15,6 +7,11 @@ import random
import re
import string
+from cloudinit import helpers as c_helpers
+from cloudinit import util
+from cloudinit.handlers import CONTENT_END, CONTENT_START, cloud_config
+from tests.unittests import helpers
+
SOURCE_PAT = "source*.*yaml"
EXPECTED_PAT = "expected%s.yaml"
TYPES = [dict, str, list, tuple, None, int]
@@ -43,7 +40,7 @@ def _old_mergemanydict(*args):
def _random_str(rand):
- base = ''
+ base = ""
for _i in range(rand.randint(1, 2 ** 8)):
base += rand.choice(string.ascii_letters + string.digits)
return base
@@ -98,7 +95,7 @@ def make_dict(max_depth, seed=None):
class TestSimpleRun(helpers.ResourceUsingTestCase):
def _load_merge_files(self):
- merge_root = helpers.resourceLocation('merge_sources')
+ merge_root = helpers.resourceLocation("merge_sources")
tests = []
source_ids = collections.defaultdict(list)
expected_files = {}
@@ -106,8 +103,9 @@ class TestSimpleRun(helpers.ResourceUsingTestCase):
base_fn = os.path.basename(fn)
file_id = re.match(r"source(\d+)\-(\d+)[.]yaml", base_fn)
if not file_id:
- raise IOError("File %s does not have a numeric identifier"
- % (fn))
+ raise IOError(
+ "File %s does not have a numeric identifier" % (fn)
+ )
file_id = int(file_id.group(1))
source_ids[file_id].append(fn)
expected_fn = os.path.join(merge_root, EXPECTED_PAT % (file_id))
@@ -141,29 +139,31 @@ class TestSimpleRun(helpers.ResourceUsingTestCase):
cc_handler = cloud_config.CloudConfigPartHandler(paths)
cc_handler.cloud_fn = None
for (payloads, (expected_merge, expected_fn)) in tests:
- cc_handler.handle_part(None, CONTENT_START, None,
- None, None, None)
+ cc_handler.handle_part(None, CONTENT_START, None, None, None, None)
merging_fns = []
for (fn, contents) in payloads:
- cc_handler.handle_part(None, None, "%s.yaml" % (fn),
- contents, None, {})
+ cc_handler.handle_part(
+ None, None, "%s.yaml" % (fn), contents, None, {}
+ )
merging_fns.append(fn)
merged_buf = cc_handler.cloud_buf
- cc_handler.handle_part(None, CONTENT_END, None,
- None, None, None)
+ cc_handler.handle_part(None, CONTENT_END, None, None, None, None)
fail_msg = "Equality failure on checking %s with %s: %s != %s"
- fail_msg = fail_msg % (expected_fn,
- ",".join(merging_fns), merged_buf,
- expected_merge)
+ fail_msg = fail_msg % (
+ expected_fn,
+ ",".join(merging_fns),
+ merged_buf,
+ expected_merge,
+ )
self.assertEqual(expected_merge, merged_buf, msg=fail_msg)
def test_compat_merges_dict(self):
a = {
- '1': '2',
- 'b': 'c',
+ "1": "2",
+ "b": "c",
}
b = {
- 'b': 'e',
+ "b": "e",
}
c = _old_mergedict(a, b)
d = util.mergemanydict([a, b])
@@ -171,53 +171,53 @@ class TestSimpleRun(helpers.ResourceUsingTestCase):
def test_compat_merges_dict2(self):
a = {
- 'Blah': 1,
- 'Blah2': 2,
- 'Blah3': 3,
+ "Blah": 1,
+ "Blah2": 2,
+ "Blah3": 3,
}
b = {
- 'Blah': 1,
- 'Blah2': 2,
- 'Blah3': [1],
+ "Blah": 1,
+ "Blah2": 2,
+ "Blah3": [1],
}
c = _old_mergedict(a, b)
d = util.mergemanydict([a, b])
self.assertEqual(c, d)
def test_compat_merges_list(self):
- a = {'b': [1, 2, 3]}
- b = {'b': [4, 5]}
- c = {'b': [6, 7]}
+ a = {"b": [1, 2, 3]}
+ b = {"b": [4, 5]}
+ c = {"b": [6, 7]}
e = _old_mergemanydict(a, b, c)
f = util.mergemanydict([a, b, c])
self.assertEqual(e, f)
def test_compat_merges_str(self):
- a = {'b': "hi"}
- b = {'b': "howdy"}
- c = {'b': "hallo"}
+ a = {"b": "hi"}
+ b = {"b": "howdy"}
+ c = {"b": "hallo"}
e = _old_mergemanydict(a, b, c)
f = util.mergemanydict([a, b, c])
self.assertEqual(e, f)
def test_compat_merge_sub_dict(self):
a = {
- '1': '2',
- 'b': {
- 'f': 'g',
- 'e': 'c',
- 'h': 'd',
- 'hh': {
- '1': 2,
+ "1": "2",
+ "b": {
+ "f": "g",
+ "e": "c",
+ "h": "d",
+ "hh": {
+ "1": 2,
},
- }
+ },
}
b = {
- 'b': {
- 'e': 'c',
- 'hh': {
- '3': 4,
- }
+ "b": {
+ "e": "c",
+ "hh": {
+ "3": 4,
+ },
}
}
c = _old_mergedict(a, b)
@@ -226,14 +226,14 @@ class TestSimpleRun(helpers.ResourceUsingTestCase):
def test_compat_merge_sub_dict2(self):
a = {
- '1': '2',
- 'b': {
- 'f': 'g',
- }
+ "1": "2",
+ "b": {
+ "f": "g",
+ },
}
b = {
- 'b': {
- 'e': 'c',
+ "b": {
+ "e": "c",
}
}
c = _old_mergedict(a, b)
@@ -242,18 +242,19 @@ class TestSimpleRun(helpers.ResourceUsingTestCase):
def test_compat_merge_sub_list(self):
a = {
- '1': '2',
- 'b': {
- 'f': ['1'],
- }
+ "1": "2",
+ "b": {
+ "f": ["1"],
+ },
}
b = {
- 'b': {
- 'f': [],
+ "b": {
+ "f": [],
}
}
c = _old_mergedict(a, b)
d = util.mergemanydict([a, b])
self.assertEqual(c, d)
+
# vi: ts=4 expandtab