Skip to content

Commit

Permalink
Added more tests for the dita.convert.transform module.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhradilek committed Nov 21, 2024
1 parent 67a7a5a commit b0da5b2
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/test_convert_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 id="example-topic">
<title>Topic title</title>
<body>
<p>Topic introduction</p>
<ol>
<li>First step</li>
<li>Second step</li>
</ol>
<p>Topic summary</p>
</body>
</topic>
'''))

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('''\
<task id="example-concept">
Expand Down Expand Up @@ -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 id="example-topic">
<title>Topic title</title>
<body>
<p>Topic introduction</p>
<p outputclass="title"><b>Prerequisites</b></p>
<ul>
<li>First prerequisite</li>
<li>Second prerequisite</li>
</ul>
<p outputclass="title"><b>Procedure</b></p>
<ol>
<li>First step</li>
<li>Second step</li>
</ol>
<p outputclass="title"><b>Verification</b></p>
<ul>
<li>Verification step</li>
</ul>
<p outputclass="title"><b>Troubleshooting</b></p>
<ol>
<li>First troubleshooting step</li>
<li>Second troubleshooting step</li>
</ol>
<p outputclass="title"><b>Next steps</b></p>
<ul>
<li>Next step</li>
</ul>
</body>
</topic>
'''))

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"])'))

0 comments on commit b0da5b2

Please sign in to comment.