Skip to content

Commit

Permalink
tests: add markup checks for figure captions
Browse files Browse the repository at this point in the history
Adding some unit tests to verify the processing non-simple text for
captions (i.e. additional markup for text). Previous implementations had
caption data malformed, and these checks should help prevent this from
happening again.

Signed-off-by: James Knight <[email protected]>
  • Loading branch information
jdknight committed Nov 18, 2023
1 parent 8608b26 commit 58bc3cb
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/unit-tests/datasets/rst/figure-caption/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.. https://docutils.sourceforge.io/docs/ref/rst/directives.html#figure
figure
------

.. figure with caption
.. figure:: ../../../assets/image03.png

**caption** with *markup*

legend
58 changes: 58 additions & 0 deletions tests/unit-tests/test_rst_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from tests.lib.parse import parse
from tests.lib.testcase import ConfluenceTestCase
from tests.lib.testcase import setup_builder
from tests.lib.testcase import setup_editor
import os


Expand Down Expand Up @@ -166,3 +167,60 @@ def test_storage_rst_figure_defaults(self):
self.assertIsNotNone(next_tag)
self.assertTrue(next_tag.has_attr('style'))
self.assertTrue('clear: both' in next_tag['style'])

@setup_builder('confluence')
def test_storage_rst_figure_caption_default(self):
dataset = os.path.join(self.datasets, 'rst', 'figure-caption')
out_dir = self.build(dataset)

with parse('index', out_dir) as data:
figures = data.find_all('p', recursive=False)
self.assertEqual(len(figures), 1)

# ##########################################################
# single figure with caption
# ##########################################################
figure = figures.pop(0)

image = figure.find('ac:image', recursive=False)
self.assertIsNotNone(image)

caption = figure.find('p', recursive=False)
self.assertIsNotNone(caption)

markup1 = caption.find('strong', recursive=False)
self.assertIsNotNone(markup1)
self.assertIsNotNone(markup1.text, 'caption')

markup2 = caption.find('em', recursive=False)
self.assertIsNotNone(markup2)
self.assertIsNotNone(markup2.text, 'markup')

@setup_builder('confluence')
@setup_editor('v2')
def test_storage_rst_figure_caption_v2(self):
dataset = os.path.join(self.datasets, 'rst', 'figure-caption')
out_dir = self.build(dataset)

with parse('index', out_dir) as data:
figures = data.find_all('p', recursive=False)
self.assertEqual(len(figures), 1)

# ##########################################################
# single figure with caption
# ##########################################################
figure = figures.pop(0)

image = figure.find('ac:image', recursive=False)
self.assertIsNotNone(image)

caption = image.find('ac:caption', recursive=False)
self.assertIsNotNone(caption)

markup1 = caption.find('strong', recursive=False)
self.assertIsNotNone(markup1)
self.assertIsNotNone(markup1.text, 'caption')

markup2 = caption.find('em', recursive=False)
self.assertIsNotNone(markup2)
self.assertIsNotNone(markup2.text, 'markup')

0 comments on commit 58bc3cb

Please sign in to comment.