From b0da5b288b76a3c9a9fb19ebefbdba8de979e65a Mon Sep 17 00:00:00 2001 From: Jaromir Hradilek Date: Thu, 21 Nov 2024 02:22:02 +0100 Subject: [PATCH] Added more tests for the dita.convert.transform module. --- test/test_convert_transform.py | 75 ++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/test/test_convert_transform.py b/test/test_convert_transform.py index 05a6c7b..6ec01a2 100644 --- a/test/test_convert_transform.py +++ b/test/test_convert_transform.py @@ -96,6 +96,32 @@ def test_to_task_forbids_sections(self): self.assertEqual(str(cm.exception), 'ERROR: Section not allowed in a DITA task') + def test_to_task_transforms_topic(self): + xml = etree.parse(StringIO('''\ + + Topic title + +

Topic introduction

+
    +
  1. First step
  2. +
  3. Second step
  4. +
+

Topic summary

+ +
+ ''')) + + task = transform.to_task(xml) + + self.assertTrue(task.xpath('boolean(/task)')) + self.assertTrue(task.xpath('boolean(/task[@id="example-topic"])')) + self.assertTrue(task.xpath('boolean(/task/title[text()="Topic title"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody)')) + self.assertTrue(task.xpath('boolean(/task/taskbody/context/p[text()="Topic introduction"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody/steps/step[1]/cmd[text()="First step"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody/steps/step[2]/cmd[text()="Second step"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody/result/p[text()="Topic summary"])')) + def test_to_task_generated_requires_topic(self): xml = etree.parse(StringIO('''\ @@ -126,3 +152,52 @@ def test_to_task_generated_forbids_sections(self): transform.to_task_generated(xml) self.assertEqual(str(cm.exception), 'ERROR: Section not allowed in a DITA task') + + def test_to_task_generated_transforms_topic(self): + xml = etree.parse(StringIO('''\ + + Topic title + +

Topic introduction

+

Prerequisites

+
    +
  • First prerequisite
  • +
  • Second prerequisite
  • +
+

Procedure

+
    +
  1. First step
  2. +
  3. Second step
  4. +
+

Verification

+
    +
  • Verification step
  • +
+

Troubleshooting

+
    +
  1. First troubleshooting step
  2. +
  3. Second troubleshooting step
  4. +
+

Next steps

+
    +
  • Next step
  • +
+ +
+ ''')) + + task = transform.to_task_generated(xml) + + self.assertTrue(task.xpath('boolean(/task)')) + self.assertTrue(task.xpath('boolean(/task[@id="example-topic"])')) + self.assertTrue(task.xpath('boolean(/task/title[text()="Topic title"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody)')) + self.assertTrue(task.xpath('boolean(/task/taskbody/prereq/ul/li[1][text()="First prerequisite"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody/prereq/ul/li[2][text()="Second prerequisite"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody/context/p[text()="Topic introduction"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody/steps/step[1]/cmd[text()="First step"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody/steps/step[2]/cmd[text()="Second step"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody/result/ul/li[1][text()="Verification step"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody/tasktroubleshooting/ol/li[1][text()="First troubleshooting step"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody/tasktroubleshooting/ol/li[2][text()="Second troubleshooting step"])')) + self.assertTrue(task.xpath('boolean(/task/taskbody/postreq/ul/li[1][text()="Next step"])'))