summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-11-17 18:39:09 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-11-17 18:39:09 (GMT)
commitc02661b7a8151a49a77c39241b040aa9bdb30223 (patch)
tree0a183a31b8bf1a8f6ff67c79194aea679097e117 /tests
parentea2465431d9f50344f9c9b9e12535e69f10f7980 (diff)
Fixed the search of Yaml nodes.
Diffstat (limited to 'tests')
-rw-r--r--tests/plugins/yamlrdr.py63
1 files changed, 59 insertions, 4 deletions
diff --git a/tests/plugins/yamlrdr.py b/tests/plugins/yamlrdr.py
index 103d6e8..eeae032 100644
--- a/tests/plugins/yamlrdr.py
+++ b/tests/plugins/yamlrdr.py
@@ -52,10 +52,24 @@ root:
'''
+ cls._mixed = tempfile.NamedTemporaryFile()
+
+ cls._mixed_data = b'''
+root:
+ - a: av
+ aa: aav
+ ab: abv
+ - b: bv
+ ba: bav
+ bb: bbv
+
+'''
+
tmp = [
[ cls._simple_map, cls._simple_map_data ],
[ cls._simple_seq, cls._simple_seq_data ],
- [ cls._nested, cls._nested_data ]
+ [ cls._nested, cls._nested_data ],
+ [ cls._mixed, cls._mixed_data ],
]
for f, d in tmp:
@@ -75,6 +89,7 @@ root:
cls._simple_map,
cls._simple_seq,
cls._nested,
+ cls._mixed,
]
for f in tmp:
@@ -87,12 +102,12 @@ root:
def testSimpleYamlContent(self):
"""Validate Yaml content readers."""
- def _build_node_desc(node, left):
+ def _build_node_desc(node, left, extra = ''):
line = node.yaml_line
if line:
- prefix = '- ' if line.is_list_item else ''
+ prefix = '- ' if line.is_list_item else extra
desc = left + prefix + line.key + ':' + (' ' + line.value if line.value else '') + '\n'
indent = ' '
else:
@@ -100,8 +115,12 @@ root:
indent = ''
if node.collection:
+
+ if node.collection.is_sequence:
+ extra = ' '
+
for child in node.collection.nodes:
- desc += _build_node_desc(child, left + indent)
+ desc += _build_node_desc(child, left + indent, extra)
return desc
@@ -130,6 +149,14 @@ root:
self.assertEqual('\n' + fulldesc + '\n', self._nested_data.decode('ascii'))
+ reader = YamlReader.new_from_path(self._mixed.name)
+ self.assertIsNotNone(reader)
+ self.assertIsNotNone(reader.tree)
+
+ fulldesc = _build_node_desc(reader.tree.root, '')
+
+ self.assertEqual('\n' + fulldesc + '\n', self._mixed_data.decode('ascii'))
+
def testSimpleYamlContentFinder(self):
"""Validate Yaml nested content search."""
@@ -194,3 +221,31 @@ root:
self.assertEqual(found[0].yaml_line.key, 'i')
self.assertEqual(found[0].yaml_line.is_list_item, True)
+
+
+ def testMixedYamlContentFinder(self):
+ """Validate Yaml mixed content search."""
+
+ reader = YamlReader.new_from_path(self._mixed.name)
+ self.assertIsNotNone(reader)
+
+ found = reader.tree.find_by_path('/root')
+
+ self.assertEqual(len(found), 1)
+
+ if len(found) == 1:
+ self.assertEqual(found[0].yaml_line.key, 'root')
+
+ found = reader.tree.find_by_path('/root/')
+
+ self.assertEqual(len(found), 2)
+
+ if len(found) == 2:
+
+ sub = found[0].find_by_path('/a')
+ self.assertEqual(len(sub), 1)
+ self.assertEqual(sub[0].yaml_line.key, 'a')
+
+ sub = found[0].find_by_path('/aa')
+ self.assertEqual(len(sub), 1)
+ self.assertEqual(sub[0].yaml_line.key, 'aa')