summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-06-16 20:20:46 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-11-01 10:16:01 (GMT)
commit33b5dc9af0404eabeb0e60245ab1ca1dc3713a17 (patch)
treefda7b9996c7e90b96507988d54cc73161b309621 /tests
parenta8598ae89acd2963143b7a6b248fbecbc0e16025 (diff)
Added support for Yaml content.
Diffstat (limited to 'tests')
-rw-r--r--tests/plugins/yamlrdr.py94
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)