diff options
Diffstat (limited to 'tests/plugins')
-rw-r--r-- | tests/plugins/yamlrdr.py | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/plugins/yamlrdr.py b/tests/plugins/yamlrdr.py new file mode 100644 index 0000000..7f65624 --- /dev/null +++ b/tests/plugins/yamlrdr.py @@ -0,0 +1,94 @@ +#!/usr/bin/python3-dbg +# -*- coding: utf-8 -*- + + +from chrysacase import ChrysalideTestCase +from pychrysalide.plugins.yaml import YamlReader +import tempfile + + +class TestYamlReader(ChrysalideTestCase): + """TestCase for the Yaml reader.""" + + + @classmethod + def setUpClass(cls): + + super(TestYamlReader, cls).setUpClass() + + cls._simple = tempfile.NamedTemporaryFile() + + cls.simple_data = b''' +meta: + id: java_class + endian: be + file-extension: class + xref: + justsolve: Java + pronom: x-fmt/415 + 'wiki"data': Q2193155 + license: CC0-1.0 + +''' + + cls._simple.write(cls.simple_data) + + cls._simple.flush() + + cls.log('Using temporary file "%s"' % cls._simple.name) + + + @classmethod + def tearDownClass(cls): + + super(TestYamlReader, cls).tearDownClass() + + cls.log('Delete file "%s"' % cls._simple.name) + + cls._simple.close() + + + def testSimpleYamlContent(self): + """Validate simple Yaml content reader.""" + + reader = YamlReader.new_from_path(self._simple.name) + self.assertIsNotNone(reader) + + + def _build_node_desc(node, left): + + line = node.yaml_line + + desc = left + line.key + ':' + (' ' + line.value if line.value else '') + '\n' + + for child in node.children: + desc += _build_node_desc(child, left + ' ') + + return desc + + + fulldesc = '' + + for rn in reader.tree.root_nodes: + fulldesc += _build_node_desc(rn, '') + + self.assertEqual('\n' + fulldesc + '\n', self.simple_data.decode('ascii')) + + + def testSimpleYamlContentFinder(self): + """Validate simple Yaml content search.""" + + reader = YamlReader.new_from_path(self._simple.name) + self.assertIsNotNone(reader) + + found = reader.tree.find_node_by_path('/meta/xref') + + self.assertEqual(found.yaml_line.key, 'xref') + + found = reader.tree.find_node_by_path('/meta/xref/') + + self.assertEqual(found.yaml_line.key, 'xref') + + found = reader.tree.find_node_by_path('/meta/xref/aa') + + self.assertIsNone(found) |