From abba115601d1f10e683218d6a01691f3f2d12571 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Mon, 5 Feb 2018 13:11:01 +1300 Subject: [PATCH 01/73] Update setuptools from 38.4.0 to 38.5.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 144f6b15..ff640e89 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ markdown==2.6.11 Jinja2==2.10 python-slugify==1.2.4 -setuptools==38.4.0 +setuptools==38.5.0 # Required dependencies for building documentation sphinx==1.6.6 From 0bc92975c646dee3a23816e940b12921bece4c9d Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 5 Feb 2018 20:43:09 +1300 Subject: [PATCH 02/73] Added missing line to interactive docs --- docs/source/processors/interactive.rst | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/source/processors/interactive.rst b/docs/source/processors/interactive.rst index 2b331b0a..ded1c7d3 100644 --- a/docs/source/processors/interactive.rst +++ b/docs/source/processors/interactive.rst @@ -24,7 +24,8 @@ You can include an interactive using the following text tag: Required Tag Parameters *************************************** -- ``name`` - The name to the interactive to include/link to. +- ``name`` - The name to the interactive to include/link to, given in slug format. + This name is added to the list of interactives in ``required_files``. - ``type`` - Sets the way the interactive is included in the page. Must be set to one of the following values: @@ -33,12 +34,14 @@ Required Tag Parameters page). - ``whole-page`` - Creates a link to the interactive displayed on a separate page (this is the preferred method for including an interactive - on a separate page). The link shows a thumbnail of the interactive with - text (the text is set using the ``text`` parameter). + on a separate page). + The link shows a thumbnail of the interactive with text (the text is set using the + ``text`` parameter). By default, the thumbnail should be a ``thumbnail.png`` file found within the interactive's img folder. - ``iframe`` - The interactive is included in the page by embedding using - an iframe. This is used if the interactive is included multiple times on + an iframe. + This is used if the interactive is included multiple times on the page to avoid conflicts in JavaScript/CSS. Optional Tag Parameters @@ -48,8 +51,9 @@ Optional Tag Parameters link. If no text is given, the link uses the text ``Click to load {{ name }}``. - ``parameters`` (used with ``whole-page`` and ``iframe`` values) - Adds the parameters - to interactive link. For example: ``digits=5&start=BBBBB``. Do not include - the ``?`` at the start, as this is already included in the output. + to interactive link. + For example: ``digits=5&start=BBBBB``. + Do not include the ``?`` at the start, as this is already included in the output. - ``thumbnail`` (optional - used with ``whole-page`` value) - Displays an alternative thumbnail for the interactive. When not provided, it defaults to ``interactives/interactive-name/img/thumbnail.png``, where ``interactive-name`` is the From cff5db34e100be5ea1af09fb4f06cdccbddfab7c Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Sat, 24 Feb 2018 15:12:06 +1300 Subject: [PATCH 03/73] Update sphinx from 1.6.6 to 1.7.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ff640e89..a0e98213 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ python-slugify==1.2.4 setuptools==38.5.0 # Required dependencies for building documentation -sphinx==1.6.6 +sphinx==1.7.1 sphinx_rtd_theme==0.2.4 From e088222a382d16191abdd41c58203a2e91a66e6a Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Mon, 19 Mar 2018 05:02:45 +1300 Subject: [PATCH 04/73] Update setuptools from 38.5.0 to 39.0.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ff640e89..f52f1820 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ markdown==2.6.11 Jinja2==2.10 python-slugify==1.2.4 -setuptools==38.5.0 +setuptools==39.0.1 # Required dependencies for building documentation sphinx==1.6.6 From ff57227297a12d6088dec4527ee756bd73a6e681 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 19 Mar 2018 11:48:38 +1300 Subject: [PATCH 05/73] Added style test to panel. Started rewriting style error. --- verto/errors/StyleError.py | 14 +++++++ verto/tests/PanelTest.py | 12 ++++++ .../panel/panel_block_missing_whitespace.md | 3 ++ verto/tests/start_tests.py | 42 +++++++++---------- 4 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 verto/tests/assets/panel/panel_block_missing_whitespace.md diff --git a/verto/errors/StyleError.py b/verto/errors/StyleError.py index 4953bb40..3c59efcf 100644 --- a/verto/errors/StyleError.py +++ b/verto/errors/StyleError.py @@ -1,5 +1,9 @@ from verto.errors.Error import Error +MESSAGE_TEMPLATE = """{} +Error happened on line {}. +""" + class StyleError(Error): '''Exception raised when a Style rule is broken. @@ -15,3 +19,13 @@ def __init__(self, line_nums, lines, message): self.line_nums = line_nums self.lines = lines self.message = message + + + def __str__(self): + """Overried default error string. + + Returns: + Error message for incorrect style, including offending lines. + + """ + return MESSAGE_TEMPLATE.format(self.message, self.lines) diff --git a/verto/tests/PanelTest.py b/verto/tests/PanelTest.py index 76c4344b..86fc2304 100644 --- a/verto/tests/PanelTest.py +++ b/verto/tests/PanelTest.py @@ -356,6 +356,18 @@ def test_panel_only_in_numbered_list(self): expected_string = self.read_test_file(self.processor_name, 'panel_only_in_numbered_list_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) + def test_panel_block_missing_whitespace(self): + '''Tests that panels and containers work within numbered lists. + ''' + test_string = self.read_test_file(self.processor_name, 'panel_block_missing_whitespace.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # self.assertRaises(PanelMissingTitleError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + #~ # Doc Tests #~ diff --git a/verto/tests/assets/panel/panel_block_missing_whitespace.md b/verto/tests/assets/panel/panel_block_missing_whitespace.md new file mode 100644 index 00000000..bc921fe2 --- /dev/null +++ b/verto/tests/assets/panel/panel_block_missing_whitespace.md @@ -0,0 +1,3 @@ +This is some text. +{panel} +Some more text. diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index eacb1c89..e7b9ed1f 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -69,28 +69,28 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - unittest.makeSuite(BoxedTextTest), - unittest.makeSuite(ButtonLinkTest), - unittest.makeSuite(CommentTest), - unittest.makeSuite(ConditionalTest), - unittest.makeSuite(FrameTest), - unittest.makeSuite(GlossaryLinkTest), - unittest.makeSuite(HeadingTest), - unittest.makeSuite(ImageInlineTest), - unittest.makeSuite(ImageTagTest), - unittest.makeSuite(ImageContainerTest), - unittest.makeSuite(InteractiveTest), - unittest.makeSuite(JinjaTest), + # unittest.makeSuite(BoxedTextTest), + # unittest.makeSuite(ButtonLinkTest), + # unittest.makeSuite(CommentTest), + # unittest.makeSuite(ConditionalTest), + # unittest.makeSuite(FrameTest), + # unittest.makeSuite(GlossaryLinkTest), + # unittest.makeSuite(HeadingTest), + # unittest.makeSuite(ImageInlineTest), + # unittest.makeSuite(ImageTagTest), + # unittest.makeSuite(ImageContainerTest), + # unittest.makeSuite(InteractiveTest), + # unittest.makeSuite(JinjaTest), unittest.makeSuite(PanelTest), - unittest.makeSuite(SaveTitleTest), - unittest.makeSuite(ScratchTest), - unittest.makeSuite(ScratchInlineTest), - unittest.makeSuite(StyleTest), - unittest.makeSuite(RelativeLinkTest), - unittest.makeSuite(RemoveTest), - unittest.makeSuite(RemoveTitleTest), - unittest.makeSuite(TableOfContentsTest), - unittest.makeSuite(VideoTest), + # unittest.makeSuite(SaveTitleTest), + # unittest.makeSuite(ScratchTest), + # unittest.makeSuite(ScratchInlineTest), + # unittest.makeSuite(StyleTest), + # unittest.makeSuite(RelativeLinkTest), + # unittest.makeSuite(RemoveTest), + # unittest.makeSuite(RemoveTitleTest), + # unittest.makeSuite(TableOfContentsTest), + # unittest.makeSuite(VideoTest), unittest.makeSuite(HtmlParserTest), unittest.makeSuite(MarkdownOverrideTest), From 016af11ccedd5e26ccc73976066d0cccc0c9e7f5 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Wed, 21 Mar 2018 09:45:20 +1300 Subject: [PATCH 06/73] Implemented new style error message. --- verto/errors/StyleError.py | 17 ++++---- verto/tests/PanelTest.py | 9 ++-- verto/tests/StyleTest.py | 28 ++++++------- .../doc_example_block_valid_expected.html | 5 +++ ..._example_block_valid_in_list_expected.html | 7 ++++ verto/tests/start_tests.py | 42 +++++++++---------- 6 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 verto/tests/assets/style/doc_example_block_valid_expected.html create mode 100644 verto/tests/assets/style/doc_example_block_valid_in_list_expected.html diff --git a/verto/errors/StyleError.py b/verto/errors/StyleError.py index 3c59efcf..0d16aa59 100644 --- a/verto/errors/StyleError.py +++ b/verto/errors/StyleError.py @@ -1,8 +1,9 @@ from verto.errors.Error import Error -MESSAGE_TEMPLATE = """{} -Error happened on line {}. -""" +MESSAGE_TEMPLATE = '''{} +The error occured in the following line(s): +{} +''' class StyleError(Error): @@ -20,12 +21,14 @@ def __init__(self, line_nums, lines, message): self.lines = lines self.message = message - def __str__(self): - """Overried default error string. + '''Overried default error string. Returns: Error message for incorrect style, including offending lines. - """ - return MESSAGE_TEMPLATE.format(self.message, self.lines) + ''' + error_lines = '' + for index, line in enumerate(self.lines): + error_lines += '{}: {}\n'.format(self.line_nums[index], line) + return MESSAGE_TEMPLATE.format(self.message, error_lines) diff --git a/verto/tests/PanelTest.py b/verto/tests/PanelTest.py index 86fc2304..74134496 100644 --- a/verto/tests/PanelTest.py +++ b/verto/tests/PanelTest.py @@ -7,6 +7,7 @@ from verto.errors.ArgumentValueError import ArgumentValueError from verto.errors.PanelMissingTitleError import PanelMissingTitleError from verto.errors.PanelMissingSubtitleError import PanelMissingSubtitleError +from verto.errors.StyleError import StyleError from verto.tests.ProcessorTest import ProcessorTest @@ -364,13 +365,11 @@ def test_panel_block_missing_whitespace(self): self.assertListEqual([True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # self.assertRaises(PanelMissingTitleError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - + self.assertRaises(StyleError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - #~ + # ~ # Doc Tests - #~ + # ~ def test_doc_example_basic(self): '''Example of the common usecase. diff --git a/verto/tests/StyleTest.py b/verto/tests/StyleTest.py index 7e862ac9..0ad4f9ce 100644 --- a/verto/tests/StyleTest.py +++ b/verto/tests/StyleTest.py @@ -1,11 +1,10 @@ import markdown from unittest.mock import Mock -from verto.VertoExtension import VertoExtension -from verto.processors.StylePreprocessor import StylePreprocessor from verto.errors.StyleError import StyleError from verto.tests.ProcessorTest import ProcessorTest + class StyleTest(ProcessorTest): '''Checks that failures are raised correctly. ''' @@ -22,62 +21,59 @@ def test_doc_example_block_whitespace(self): '''Test before an after a block. ''' test_string = self.read_test_file(self.processor_name, 'doc_example_block_whitespace.md') - with self.assertRaises(StyleError): - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + self.assertRaises(StyleError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) def test_doc_example_block_whitespace_1(self): '''Test no whitespace before an after content in a block container. ''' test_string = self.read_test_file(self.processor_name, 'doc_example_block_whitespace_1.md') - with self.assertRaises(StyleError): - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + self.assertRaises(StyleError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) def test_doc_example_block_whitespace_2(self): '''Test no whitespace before a block tag. ''' test_string = self.read_test_file(self.processor_name, 'doc_example_block_whitespace_2.md') - with self.assertRaises(StyleError): - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + self.assertRaises(StyleError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) def test_doc_example_block_whitespace_3(self): '''Test no whitespace after a block tag. ''' test_string = self.read_test_file(self.processor_name, 'doc_example_block_whitespace_3.md') - with self.assertRaises(StyleError): - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + self.assertRaises(StyleError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) def test_doc_example_block_solitary(self): '''Test extra text after a tag that should be solitary. ''' test_string = self.read_test_file(self.processor_name, 'doc_example_block_solitary.md') - with self.assertRaises(StyleError): - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + self.assertRaises(StyleError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) def test_doc_example_block_solitary_1(self): '''Test extra text before a tag that should be solitary. ''' test_string = self.read_test_file(self.processor_name, 'doc_example_block_solitary_1.md') - with self.assertRaises(StyleError): - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + self.assertRaises(StyleError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) def test_doc_example_block_valid(self): '''A valid example of using container tags. ''' test_string = self.read_test_file(self.processor_name, 'doc_example_block_valid.md') converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'doc_example_block_valid_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) def test_doc_example_block_valid_in_list(self): '''A valid example of using container tags. ''' test_string = self.read_test_file(self.processor_name, 'doc_example_block_valid_in_list.md') converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'doc_example_block_valid_in_list_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) def test_doc_example_block_error_in_list(self): '''A valid example of using container tags. ''' test_string = self.read_test_file(self.processor_name, 'doc_example_block_error_in_list.md') - with self.assertRaises(StyleError): - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + self.assertRaises(StyleError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) diff --git a/verto/tests/assets/style/doc_example_block_valid_expected.html b/verto/tests/assets/style/doc_example_block_valid_expected.html new file mode 100644 index 00000000..5e780afa --- /dev/null +++ b/verto/tests/assets/style/doc_example_block_valid_expected.html @@ -0,0 +1,5 @@ +

This is valid.

+

{panel}

+

This is valid.

+

{panel end}

+

This is valid.

diff --git a/verto/tests/assets/style/doc_example_block_valid_in_list_expected.html b/verto/tests/assets/style/doc_example_block_valid_in_list_expected.html new file mode 100644 index 00000000..070cfbfc --- /dev/null +++ b/verto/tests/assets/style/doc_example_block_valid_in_list_expected.html @@ -0,0 +1,7 @@ +

This is valid.

+
    +
  1. {panel} +This is valid. +{panel end}
  2. +
+

This is valid.

diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index e7b9ed1f..eacb1c89 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -69,28 +69,28 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - # unittest.makeSuite(BoxedTextTest), - # unittest.makeSuite(ButtonLinkTest), - # unittest.makeSuite(CommentTest), - # unittest.makeSuite(ConditionalTest), - # unittest.makeSuite(FrameTest), - # unittest.makeSuite(GlossaryLinkTest), - # unittest.makeSuite(HeadingTest), - # unittest.makeSuite(ImageInlineTest), - # unittest.makeSuite(ImageTagTest), - # unittest.makeSuite(ImageContainerTest), - # unittest.makeSuite(InteractiveTest), - # unittest.makeSuite(JinjaTest), + unittest.makeSuite(BoxedTextTest), + unittest.makeSuite(ButtonLinkTest), + unittest.makeSuite(CommentTest), + unittest.makeSuite(ConditionalTest), + unittest.makeSuite(FrameTest), + unittest.makeSuite(GlossaryLinkTest), + unittest.makeSuite(HeadingTest), + unittest.makeSuite(ImageInlineTest), + unittest.makeSuite(ImageTagTest), + unittest.makeSuite(ImageContainerTest), + unittest.makeSuite(InteractiveTest), + unittest.makeSuite(JinjaTest), unittest.makeSuite(PanelTest), - # unittest.makeSuite(SaveTitleTest), - # unittest.makeSuite(ScratchTest), - # unittest.makeSuite(ScratchInlineTest), - # unittest.makeSuite(StyleTest), - # unittest.makeSuite(RelativeLinkTest), - # unittest.makeSuite(RemoveTest), - # unittest.makeSuite(RemoveTitleTest), - # unittest.makeSuite(TableOfContentsTest), - # unittest.makeSuite(VideoTest), + unittest.makeSuite(SaveTitleTest), + unittest.makeSuite(ScratchTest), + unittest.makeSuite(ScratchInlineTest), + unittest.makeSuite(StyleTest), + unittest.makeSuite(RelativeLinkTest), + unittest.makeSuite(RemoveTest), + unittest.makeSuite(RemoveTitleTest), + unittest.makeSuite(TableOfContentsTest), + unittest.makeSuite(VideoTest), unittest.makeSuite(HtmlParserTest), unittest.makeSuite(MarkdownOverrideTest), From d626bde5fe58dea825d4b8be2844eaba925ba38c Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Wed, 21 Mar 2018 10:16:31 +1300 Subject: [PATCH 07/73] WIP started changing interactive parameter 'name' to 'slug' --- verto/html-templates/interactive.html | 8 ++++---- verto/processor-info.json | 6 +++--- verto/processors/InteractiveBlockProcessor.py | 10 +++++----- verto/tests/assets/configuration/all_processors.md | 2 +- .../all_processors_custom_html_expected.html | 2 +- .../configuration/all_processors_expected.html | 2 +- .../custom_processors_custom_templates_expected.html | 2 +- .../configuration/custom_processors_expected.html | 2 +- .../configuration/multiline_templates_expected.html | 2 +- .../assets/interactive/doc_example_iframe_usage.md | 2 +- .../doc_example_iframe_usage_expected.html | 2 +- .../assets/interactive/doc_example_in_page_usage.md | 2 +- .../assets/interactive/doc_example_override_html.md | 2 +- .../doc_example_override_html_expected.html | 2 +- .../doc_example_override_html_template.html | 8 ++++---- .../doc_example_override_thumbnail_html.md | 2 +- ...doc_example_override_thumbnail_html_expected.html | 2 +- .../doc_example_thumbnail_path_html_template.html | 2 +- .../interactive/doc_example_whole_page_usage.md | 2 +- .../doc_example_whole_page_usage_expected.html | 2 +- verto/tests/assets/interactive/iframe_parameters.md | 2 +- .../interactive/iframe_parameters_expected.html | 2 +- verto/tests/assets/interactive/invalid_type.md | 2 +- verto/tests/assets/interactive/missing_type.md | 2 +- .../assets/interactive/multiple_interactives.md | 6 +++--- .../interactive/multiple_interactives_expected.html | 4 ++-- .../interactive/whole_page_external_thumbnail.md | 2 +- .../whole_page_external_thumbnail_expected.html | 2 +- .../assets/interactive/whole_page_parameters.md | 2 +- .../interactive/whole_page_parameters_expected.html | 2 +- verto/tests/assets/interactive/whole_page_text.md | 2 +- .../assets/interactive/whole_page_text_expected.html | 2 +- .../tests/assets/interactive/whole_page_thumbnail.md | 2 +- .../interactive/whole_page_thumbnail_expected.html | 2 +- .../interactive/whole_page_thumbnail_parameters.md | 2 +- .../whole_page_thumbnail_parameters_expected.html | 2 +- verto/tests/assets/smoke/algorithms.md | 12 ++++++------ verto/tests/assets/smoke/introduction.md | 2 +- 38 files changed, 58 insertions(+), 58 deletions(-) diff --git a/verto/html-templates/interactive.html b/verto/html-templates/interactive.html index dd1f00fa..627a1eea 100644 --- a/verto/html-templates/interactive.html +++ b/verto/html-templates/interactive.html @@ -1,14 +1,14 @@ {%- if type == 'in-page' -%} -{{ "{% include 'interactive/" }}{{ name }}{{ "/index.html' %}" }} +{{ "{% include 'interactive/" }}{{ slug }}{{ "/index.html' %}" }} {% elif type == 'iframe' -%} - {% elif type == 'whole-page' -%} diff --git a/verto/processor-info.json b/verto/processor-info.json index 3a14f5bc..b47faaee 100644 --- a/verto/processor-info.json +++ b/verto/processor-info.json @@ -305,7 +305,7 @@ "interactive": { "class": "custom", "arguments": { - "name": { + "slug": { "required": true, "dependencies": [] }, @@ -331,8 +331,8 @@ "type": { "argument": "type" }, - "name": { - "argument": "name" + "slug": { + "argument": "slug" }, "text": { "argument": "text" diff --git a/verto/processors/InteractiveBlockProcessor.py b/verto/processors/InteractiveBlockProcessor.py index 2055ab22..793b4783 100644 --- a/verto/processors/InteractiveBlockProcessor.py +++ b/verto/processors/InteractiveBlockProcessor.py @@ -4,7 +4,7 @@ class InteractiveBlockProcessor(GenericTagBlockProcessor): '''Searches a Document for interactive tags: - e.g. {interactive name='example' type='in-page'} + e.g. {interactive slug='example' type='in-page'} These are then replaced with the html template. ''' @@ -29,13 +29,13 @@ def custom_parsing(self, argument_values): ''' extra_args = {} interactive_type = argument_values['type'] - name = argument_values['name'] + slug = argument_values['slug'] # add to list of interactives - self.required_interactives.add(name) + self.required_interactives.add(slug) if interactive_type == 'in-page': - self.scripts.add('interactive/{}/scripts.html'.format(name)) + self.scripts.add('interactive/{}/scripts.html'.format(slug)) elif interactive_type == 'whole-page': argument = 'thumbnail' thumbnail_file_path = argument_values.get(argument, None) @@ -43,7 +43,7 @@ def custom_parsing(self, argument_values): if thumbnail_file_path is not None: del argument_values[argument] else: - thumbnail_file_path = 'interactives/{}/img/thumbnail.png'.format(name) + thumbnail_file_path = 'interactives/{}/img/thumbnail.png'.format(slug) external_path_match = re.search(r'^http', thumbnail_file_path) if external_path_match is None: # internal image diff --git a/verto/tests/assets/configuration/all_processors.md b/verto/tests/assets/configuration/all_processors.md index f73584be..da73b7b5 100644 --- a/verto/tests/assets/configuration/all_processors.md +++ b/verto/tests/assets/configuration/all_processors.md @@ -46,7 +46,7 @@ It's worth considering which {glossary-link term="algorithm"}algorithms{glossary {iframe link="https://github.com/"} -{interactive name="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"} +{interactive slug="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"} scratch when flag clicked diff --git a/verto/tests/assets/configuration/all_processors_custom_html_expected.html b/verto/tests/assets/configuration/all_processors_custom_html_expected.html index 36e2992d..4bf36292 100644 --- a/verto/tests/assets/configuration/all_processors_custom_html_expected.html +++ b/verto/tests/assets/configuration/all_processors_custom_html_expected.html @@ -31,7 +31,7 @@

-
diff --git a/verto/tests/assets/configuration/all_processors_expected.html b/verto/tests/assets/configuration/all_processors_expected.html index 40f8370c..c41d5f63 100644 --- a/verto/tests/assets/configuration/all_processors_expected.html +++ b/verto/tests/assets/configuration/all_processors_expected.html @@ -40,7 +40,7 @@

-
diff --git a/verto/tests/assets/configuration/custom_processors_custom_templates_expected.html b/verto/tests/assets/configuration/custom_processors_custom_templates_expected.html index 4274fac0..e9650c64 100644 --- a/verto/tests/assets/configuration/custom_processors_custom_templates_expected.html +++ b/verto/tests/assets/configuration/custom_processors_custom_templates_expected.html @@ -21,7 +21,7 @@

Guides for Algorithms

{conditional end}

It's worth considering which {glossary-link term="algorithm"}algorithms{glossary-link end} should be used.

{iframe link="https://github.com/"}

-

{interactive name="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"}

+

{interactive slug="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"}

scratch
 when flag clicked
 clear
diff --git a/verto/tests/assets/configuration/custom_processors_expected.html b/verto/tests/assets/configuration/custom_processors_expected.html
index 981fad7c..db6dc430 100644
--- a/verto/tests/assets/configuration/custom_processors_expected.html
+++ b/verto/tests/assets/configuration/custom_processors_expected.html
@@ -27,7 +27,7 @@ 

Example Title 2

{conditional end}

It's worth considering which {glossary-link term="algorithm"}algorithms{glossary-link end} should be used.

{iframe link="https://github.com/"}

-

{interactive name="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"}

+

{interactive slug="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"}

scratch
 when flag clicked
 clear
diff --git a/verto/tests/assets/configuration/multiline_templates_expected.html b/verto/tests/assets/configuration/multiline_templates_expected.html
index f9034627..e0ef1e24 100644
--- a/verto/tests/assets/configuration/multiline_templates_expected.html
+++ b/verto/tests/assets/configuration/multiline_templates_expected.html
@@ -39,7 +39,7 @@ 

-
diff --git a/verto/tests/assets/interactive/doc_example_iframe_usage.md b/verto/tests/assets/interactive/doc_example_iframe_usage.md index 44ec3458..e06b0837 100644 --- a/verto/tests/assets/interactive/doc_example_iframe_usage.md +++ b/verto/tests/assets/interactive/doc_example_iframe_usage.md @@ -1 +1 @@ -{interactive name="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"} +{interactive slug="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"} diff --git a/verto/tests/assets/interactive/doc_example_iframe_usage_expected.html b/verto/tests/assets/interactive/doc_example_iframe_usage_expected.html index 8e04ad3a..25f235b0 100644 --- a/verto/tests/assets/interactive/doc_example_iframe_usage_expected.html +++ b/verto/tests/assets/interactive/doc_example_iframe_usage_expected.html @@ -1,3 +1,3 @@ - diff --git a/verto/tests/assets/interactive/doc_example_in_page_usage.md b/verto/tests/assets/interactive/doc_example_in_page_usage.md index f796c9a9..bc4f421a 100644 --- a/verto/tests/assets/interactive/doc_example_in_page_usage.md +++ b/verto/tests/assets/interactive/doc_example_in_page_usage.md @@ -1 +1 @@ -{interactive name="binary-cards" type="in-page"} +{interactive slug="binary-cards" type="in-page"} diff --git a/verto/tests/assets/interactive/doc_example_override_html.md b/verto/tests/assets/interactive/doc_example_override_html.md index 4179a11b..352b06ab 100644 --- a/verto/tests/assets/interactive/doc_example_override_html.md +++ b/verto/tests/assets/interactive/doc_example_override_html.md @@ -1 +1 @@ -{interactive name="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="Binary Cards Interactive"} +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive/doc_example_override_html_expected.html b/verto/tests/assets/interactive/doc_example_override_html_expected.html index 579c2fb4..fb071360 100644 --- a/verto/tests/assets/interactive/doc_example_override_html_expected.html +++ b/verto/tests/assets/interactive/doc_example_override_html_expected.html @@ -1,4 +1,4 @@ - +
Binary Cards Interactive
diff --git a/verto/tests/assets/interactive/doc_example_override_html_template.html b/verto/tests/assets/interactive/doc_example_override_html_template.html index 868a4a3f..701edf7e 100644 --- a/verto/tests/assets/interactive/doc_example_override_html_template.html +++ b/verto/tests/assets/interactive/doc_example_override_html_template.html @@ -1,20 +1,20 @@ {% if type == 'in-page' -%}
-{{ "{{% include 'interactive/" }}{{ name }}{{ "/index.html' %}}" }} +{{ "{{% include 'interactive/" }}{{ slug }}{{ "/index.html' %}}" }}
{% elif type == 'iframe' -%} - {% elif type == 'whole-page' -%}
{% if text -%} {{ text }} {% else -%} -Click to load {{ name }} +Click to load {{ slug }} {% endif -%}
diff --git a/verto/tests/assets/interactive/doc_example_override_thumbnail_html.md b/verto/tests/assets/interactive/doc_example_override_thumbnail_html.md index 4179a11b..352b06ab 100644 --- a/verto/tests/assets/interactive/doc_example_override_thumbnail_html.md +++ b/verto/tests/assets/interactive/doc_example_override_thumbnail_html.md @@ -1 +1 @@ -{interactive name="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="Binary Cards Interactive"} +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive/doc_example_override_thumbnail_html_expected.html b/verto/tests/assets/interactive/doc_example_override_thumbnail_html_expected.html index b0fbc0aa..3fe204ff 100644 --- a/verto/tests/assets/interactive/doc_example_override_thumbnail_html_expected.html +++ b/verto/tests/assets/interactive/doc_example_override_thumbnail_html_expected.html @@ -1,4 +1,4 @@ - +
Binary Cards Interactive diff --git a/verto/tests/assets/interactive/doc_example_thumbnail_path_html_template.html b/verto/tests/assets/interactive/doc_example_thumbnail_path_html_template.html index 5d399d19..56d4c58a 100644 --- a/verto/tests/assets/interactive/doc_example_thumbnail_path_html_template.html +++ b/verto/tests/assets/interactive/doc_example_thumbnail_path_html_template.html @@ -1,3 +1,3 @@ {% autoescape false -%} -{{ "{% static '" }}interactives/{{ name }}/img/{{ file_path }}{{ "' %}" }} +{{ "{% static '" }}interactives/{{ slug }}/img/{{ file_path }}{{ "' %}" }} {%- endautoescape %} diff --git a/verto/tests/assets/interactive/doc_example_whole_page_usage.md b/verto/tests/assets/interactive/doc_example_whole_page_usage.md index 7d26cc23..aa820f2d 100644 --- a/verto/tests/assets/interactive/doc_example_whole_page_usage.md +++ b/verto/tests/assets/interactive/doc_example_whole_page_usage.md @@ -1 +1 @@ -{interactive name="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive/doc_example_whole_page_usage_expected.html b/verto/tests/assets/interactive/doc_example_whole_page_usage_expected.html index 95f3ccb5..fea9ee9c 100644 --- a/verto/tests/assets/interactive/doc_example_whole_page_usage_expected.html +++ b/verto/tests/assets/interactive/doc_example_whole_page_usage_expected.html @@ -1,4 +1,4 @@ - +
Binary Cards Interactive diff --git a/verto/tests/assets/interactive/iframe_parameters.md b/verto/tests/assets/interactive/iframe_parameters.md index 44ec3458..e06b0837 100644 --- a/verto/tests/assets/interactive/iframe_parameters.md +++ b/verto/tests/assets/interactive/iframe_parameters.md @@ -1 +1 @@ -{interactive name="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"} +{interactive slug="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"} diff --git a/verto/tests/assets/interactive/iframe_parameters_expected.html b/verto/tests/assets/interactive/iframe_parameters_expected.html index 8e04ad3a..25f235b0 100644 --- a/verto/tests/assets/interactive/iframe_parameters_expected.html +++ b/verto/tests/assets/interactive/iframe_parameters_expected.html @@ -1,3 +1,3 @@ - diff --git a/verto/tests/assets/interactive/invalid_type.md b/verto/tests/assets/interactive/invalid_type.md index 2d4abe99..62b2d6d2 100644 --- a/verto/tests/assets/interactive/invalid_type.md +++ b/verto/tests/assets/interactive/invalid_type.md @@ -1 +1 @@ -{interactive name="binary-cards" type="not-a-real-type" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} +{interactive slug="binary-cards" type="not-a-real-type" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive/missing_type.md b/verto/tests/assets/interactive/missing_type.md index 3d561427..7efd0ef9 100644 --- a/verto/tests/assets/interactive/missing_type.md +++ b/verto/tests/assets/interactive/missing_type.md @@ -1 +1 @@ -{interactive name="binary-cards" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} +{interactive slug="binary-cards" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive/multiple_interactives.md b/verto/tests/assets/interactive/multiple_interactives.md index 955b5bb0..45d248a1 100644 --- a/verto/tests/assets/interactive/multiple_interactives.md +++ b/verto/tests/assets/interactive/multiple_interactives.md @@ -1,13 +1,13 @@ This is some text. -{interactive name="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png"} +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png"} This is some more text. -{interactive name="arrows" type="iframe" parameters="digits=5&start=BBBBB"} +{interactive slug="arrows" type="iframe" parameters="digits=5&start=BBBBB"} And some more text again. -{interactive name="flying-boxes" type="in-page"} +{interactive slug="flying-boxes" type="in-page"} Aaaaaaaaaaaaaaaannnnnd here's some more. diff --git a/verto/tests/assets/interactive/multiple_interactives_expected.html b/verto/tests/assets/interactive/multiple_interactives_expected.html index e3982ef8..fe8c70a2 100644 --- a/verto/tests/assets/interactive/multiple_interactives_expected.html +++ b/verto/tests/assets/interactive/multiple_interactives_expected.html @@ -1,11 +1,11 @@

This is some text.

-
+
Click to load binary-cards

This is some more text.

-

And some more text again.

diff --git a/verto/tests/assets/interactive/whole_page_external_thumbnail.md b/verto/tests/assets/interactive/whole_page_external_thumbnail.md index 5a801328..0dff9ad3 100644 --- a/verto/tests/assets/interactive/whole_page_external_thumbnail.md +++ b/verto/tests/assets/interactive/whole_page_external_thumbnail.md @@ -1 +1 @@ -{interactive name="binary-cards" type="whole-page" thumbnail="http://totallylegit/filepath/foran/image.png"} +{interactive slug="binary-cards" type="whole-page" thumbnail="http://totallylegit/filepath/foran/image.png"} diff --git a/verto/tests/assets/interactive/whole_page_external_thumbnail_expected.html b/verto/tests/assets/interactive/whole_page_external_thumbnail_expected.html index 1807afee..cb1677dc 100644 --- a/verto/tests/assets/interactive/whole_page_external_thumbnail_expected.html +++ b/verto/tests/assets/interactive/whole_page_external_thumbnail_expected.html @@ -1,4 +1,4 @@ - +
Click to load binary-cards diff --git a/verto/tests/assets/interactive/whole_page_parameters.md b/verto/tests/assets/interactive/whole_page_parameters.md index 7d26cc23..aa820f2d 100644 --- a/verto/tests/assets/interactive/whole_page_parameters.md +++ b/verto/tests/assets/interactive/whole_page_parameters.md @@ -1 +1 @@ -{interactive name="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive/whole_page_parameters_expected.html b/verto/tests/assets/interactive/whole_page_parameters_expected.html index 95f3ccb5..fea9ee9c 100644 --- a/verto/tests/assets/interactive/whole_page_parameters_expected.html +++ b/verto/tests/assets/interactive/whole_page_parameters_expected.html @@ -1,4 +1,4 @@ - +
Binary Cards Interactive diff --git a/verto/tests/assets/interactive/whole_page_text.md b/verto/tests/assets/interactive/whole_page_text.md index 5b65e430..396f316e 100644 --- a/verto/tests/assets/interactive/whole_page_text.md +++ b/verto/tests/assets/interactive/whole_page_text.md @@ -1 +1 @@ -{interactive name="binary-cards" type="whole-page" text="Binary Cards Interactive"} +{interactive slug="binary-cards" type="whole-page" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive/whole_page_text_expected.html b/verto/tests/assets/interactive/whole_page_text_expected.html index 0b462722..a259a370 100644 --- a/verto/tests/assets/interactive/whole_page_text_expected.html +++ b/verto/tests/assets/interactive/whole_page_text_expected.html @@ -1,4 +1,4 @@ - +
Binary Cards Interactive diff --git a/verto/tests/assets/interactive/whole_page_thumbnail.md b/verto/tests/assets/interactive/whole_page_thumbnail.md index 23d3459f..4625c3a2 100644 --- a/verto/tests/assets/interactive/whole_page_thumbnail.md +++ b/verto/tests/assets/interactive/whole_page_thumbnail.md @@ -1 +1 @@ -{interactive name="binary-cards" type="whole-page" thumbnail="interactives/binary-cards/img/binarycards.png"} +{interactive slug="binary-cards" type="whole-page" thumbnail="interactives/binary-cards/img/binarycards.png"} diff --git a/verto/tests/assets/interactive/whole_page_thumbnail_expected.html b/verto/tests/assets/interactive/whole_page_thumbnail_expected.html index f2629137..9ec659d6 100644 --- a/verto/tests/assets/interactive/whole_page_thumbnail_expected.html +++ b/verto/tests/assets/interactive/whole_page_thumbnail_expected.html @@ -1,4 +1,4 @@ - +
Click to load binary-cards diff --git a/verto/tests/assets/interactive/whole_page_thumbnail_parameters.md b/verto/tests/assets/interactive/whole_page_thumbnail_parameters.md index c1bd9f8c..33681e40 100644 --- a/verto/tests/assets/interactive/whole_page_thumbnail_parameters.md +++ b/verto/tests/assets/interactive/whole_page_thumbnail_parameters.md @@ -1 +1 @@ -{interactive name="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png"} +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png"} diff --git a/verto/tests/assets/interactive/whole_page_thumbnail_parameters_expected.html b/verto/tests/assets/interactive/whole_page_thumbnail_parameters_expected.html index e5020999..f1b49c5e 100644 --- a/verto/tests/assets/interactive/whole_page_thumbnail_parameters_expected.html +++ b/verto/tests/assets/interactive/whole_page_thumbnail_parameters_expected.html @@ -1,4 +1,4 @@ - +
Click to load binary-cards diff --git a/verto/tests/assets/smoke/algorithms.md b/verto/tests/assets/smoke/algorithms.md index a7fd564e..5abe1123 100644 --- a/verto/tests/assets/smoke/algorithms.md +++ b/verto/tests/assets/smoke/algorithms.md @@ -8,7 +8,7 @@ Every computer device you have ever used, from your school computers to your calculator, has been using algorithms to tell it how to do whatever it was doing. Algorithms are a very important topic in Computer Science because they help software developers create efficient and error free programs. The most important thing to remember about algorithms is that there can be many different algorithms for the same problem, but some are much better than others! -{interactive name="sorting-algorithm-comparison" type="in-page"} +{interactive slug="sorting-algorithm-comparison" type="in-page"} Computers are incredibly fast at manipulating, moving and looking through data. However the amount of data computers use is often so large that it doesn't matter how fast the computer is, it will take it far too long to examine every single piece of data (companies like Google, Facebook and Twitter routinely process billions of things per day, and in some cases, per minute!) This is where algorithms come in. If a computer is given a better algorithm to process the data then it doesn't matter how much information it has to look through, it will still be able to do it in a reasonable amount of time. @@ -24,7 +24,7 @@ Often you can get away with describing a process just using some sort of informa "please get me a glass of water". A human can understand what this means and can figure out how to accomplish this task by thinking, but a computer would have no idea how to do this! -{interactive name="high-score-boxes" type="whole-page" text="High Score Boxes"} +{interactive slug="high-score-boxes" type="whole-page" text="High Score Boxes"} An example in a computational context might be if you wanted to find a high score in a table of scores: go through each score keeping track of the largest so far. @@ -157,13 +157,13 @@ Searching through collections of data is something computers have to do all the Lets investigate searching with a game... -{interactive name="searching-algorithms" type="whole-page" text="Searching Boxes - Part 1" parameters="max=2"} +{interactive slug="searching-algorithms" type="whole-page" text="Searching Boxes - Part 1" parameters="max=2"} You may have noticed that the numbers on the monsters and pets in the game were in a random order, which meant that finding the pet was basically luck! You might have found it on your first try, or if you were less lucky you might have had to look inside almost all the presents before you found it. This might not seem like such a bad thing since you had enough lives to look under all the boxes, but imagine if there had been 1,000 boxes, or worse 1,000,000! It would have taken far too long to look through all the boxes and the pet might have never been found. Now this next game is slightly different. You have less lives, which makes things a bit more challenging, but this time the numbers inside the boxes will be in order. The monsters, or maybe the pet, with the smallest number is in the present on the far left, and the one with the largest number is in the present on the far right. Let's see if you can collect all the pets without running out of lives... -{interactive name="searching-algorithms" type="whole-page" text="Searching Boxes - Part 2" parameters="level=3" thumbnail="thumbnail2.png"} +{interactive slug="searching-algorithms" type="whole-page" text="Searching Boxes - Part 2" parameters="level=3" thumbnail="thumbnail2.png"} Now that you have played through the whole game (and hopefully found all of the lost pets!) you may have noticed that even though you had less lives in the second part of the game, and lots of presents to search through, you were still able to find the pet. Why was this possible? @@ -261,7 +261,7 @@ Use the scales to compare the boxes (you can only compare two boxes at a time) a If the interactive does not run properly on your computer you can use a set of physical balance scales instead; just make sure you can only tell if one box is heavier than the other, not their exact weight (so not digital scales that show the exact weight). -{interactive name="sorting-algorithms" type="whole-page" text="Scales interactive"} +{interactive slug="sorting-algorithms" type="whole-page" text="Scales interactive"} {comment} @@ -350,7 +350,7 @@ Insertion and Selection Sort may seem like logical ways to sort things into orde A much better sorting algorithm is {glossary-link term="quicksort"}Quicksort!{glossary-link end} (the name is a bit of a giveaway) -{interactive name="sorting-algorithms" type="whole-page" text="Quicksort interactive" parameters="method=quick" thumbnail="thumbnail-quick.png"} +{interactive slug="sorting-algorithms" type="whole-page" text="Quicksort interactive" parameters="method=quick" thumbnail="thumbnail-quick.png"} This algorithm is a little more complicated, but is very powerful. To do this algorithm with the sorting interactive, start by randomly choosing a box and placing it on the scales. Now compare every other box to the one you selected; heavier boxes should be put on the right of the second row and lighter boxes are put on the left. When you are done, place the box you were comparing everything else to between these two groups, but to help you keep track of things, put it in the row below. The following example shows how it might look after this step. Note that the selected block is in the right place for the final sorted order, and everything on either side will remain on the side that it is on. diff --git a/verto/tests/assets/smoke/introduction.md b/verto/tests/assets/smoke/introduction.md index c2678def..bf2f29b8 100644 --- a/verto/tests/assets/smoke/introduction.md +++ b/verto/tests/assets/smoke/introduction.md @@ -45,7 +45,7 @@ They both have the same functionality (they can do the same calculations), but w (This book has many interactives like this. If the calculators don't work properly, you may need to use a more recent browser. The interactive material in this book works in most recent browsers; Google Chrome is a particularly safe bet.) -{interactive name="awful-calculator" type="in-page"} +{interactive slug="awful-calculator" type="in-page"} The second calculator above is slower, and that can be frustrating. But it has a fancier interface --- buttons expand when you point to them to highlight what you're doing. From ed9cbf1db0b019b8c21b8e01a03381949883729c Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Thu, 22 Mar 2018 13:04:51 +1300 Subject: [PATCH 08/73] Update sphinx from 1.7.1 to 1.7.2 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9029dd04..a06dcfba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ python-slugify==1.2.4 setuptools==39.0.1 # Required dependencies for building documentation -sphinx==1.7.1 +sphinx==1.7.2 sphinx_rtd_theme==0.2.4 From 06d15682fa01a0c6076b5306d0bc5d4c6bbe0798 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Thu, 22 Mar 2018 15:40:09 +1300 Subject: [PATCH 09/73] Fixed last reference to name rather than slug in ineractive test Fixed style errors in start_tests --- ...ll_processors_except_comment_expected.html | 2 +- verto/tests/start_tests.py | 40 +++++++++++++------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/verto/tests/assets/configuration/all_processors_except_comment_expected.html b/verto/tests/assets/configuration/all_processors_except_comment_expected.html index 1bb2e934..e8d4396a 100644 --- a/verto/tests/assets/configuration/all_processors_except_comment_expected.html +++ b/verto/tests/assets/configuration/all_processors_except_comment_expected.html @@ -41,7 +41,7 @@

-
diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index eacb1c89..5cfc39b3 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -1,7 +1,8 @@ -import sys, unittest, optparse +import sys +import unittest +import optparse from verto.tests.ConfigurationTest import ConfigurationTest from verto.tests.SmokeTests import SmokeFileTest, SmokeDocsTest - from verto.tests.BoxedTextTest import BoxedTextTest from verto.tests.ButtonLinkTest import ButtonLinkTest from verto.tests.CommentTest import CommentTest @@ -24,7 +25,6 @@ from verto.tests.StyleTest import StyleTest from verto.tests.TableOfContentsTest import TableOfContentsTest from verto.tests.VideoTest import VideoTest - from verto.tests.HtmlParserTest import HtmlParserTest from verto.tests.MarkdownOverrideTest import MarkdownOverrideTest @@ -34,15 +34,31 @@ def parse_args(): useful for developing when parts of verto are known to fail. ''' opts = optparse.OptionParser( - usage='Run the command `python -m verto.tests.start_tests` from the level above the verto directory.', description='Verifies that Verto is functional compared to the testing suite.') - opts.add_option('--travis', - action='store_true', help='Enables skipping suites on failure. To be used by continuous integration system.', default=False) - opts.add_option('--no_smoke', - action='store_true', help='Skips smoke tests, should be used for local development only.', default=False) - opts.add_option('--no_system', - action='store_true', help='Skips system tests, should be used for local development only.', default=False) - opts.add_option('--no_unit', - action='store_true', help='Skips unit tests, should be used for local development only.', default=False) + usage='Run the command `python -m verto.tests.start_tests` from the level above the verto directory.', + description='Verifies that Verto is functional compared to the testing suite.') + opts.add_option( + '--travis', + action='store_true', + help='Enables skipping suites on failure. To be used by continuous integration system.', + default=False + ) + opts.add_option( + '--no_smoke', + action='store_true', + help='Skips smoke tests, should be used for local development only.', + default=False + ) + opts.add_option( + '--no_system', + action='store_true', help='Skips system tests, should be used for local development only.', + default=False + ) + opts.add_option( + '--no_unit', + action='store_true', + help='Skips unit tests, should be used for local development only.', + default=False + ) options, arguments = opts.parse_args() return options, arguments From be30cb450a4592aadd1f6e446fdc54e8582d73a7 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Thu, 22 Mar 2018 15:47:46 +1300 Subject: [PATCH 10/73] Updated docs to reflect refactoring --- docs/source/processors/interactive.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/source/processors/interactive.rst b/docs/source/processors/interactive.rst index ded1c7d3..b6234ed2 100644 --- a/docs/source/processors/interactive.rst +++ b/docs/source/processors/interactive.rst @@ -24,8 +24,8 @@ You can include an interactive using the following text tag: Required Tag Parameters *************************************** -- ``name`` - The name to the interactive to include/link to, given in slug format. - This name is added to the list of interactives in ``required_files``. +- ``slug`` - The slug to the interactive to include/link to. + This slug is added to the list of interactives in ``required_files``. - ``type`` - Sets the way the interactive is included in the page. Must be set to one of the following values: @@ -49,15 +49,15 @@ Optional Tag Parameters - ``text`` (used with ``whole-page`` value) - Sets the text for the interactive link. If no text is given, the link uses the text ``Click to load - {{ name }}``. + {{ slug }}``. - ``parameters`` (used with ``whole-page`` and ``iframe`` values) - Adds the parameters to interactive link. For example: ``digits=5&start=BBBBB``. Do not include the ``?`` at the start, as this is already included in the output. - ``thumbnail`` (optional - used with ``whole-page`` value) - Displays an alternative thumbnail for the interactive. When not provided, it defaults to - ``interactives/interactive-name/img/thumbnail.png``, where ``interactive-name`` is the - value given for the ``name`` tag parameter (see above). + ``interactives/interactive-slug/img/thumbnail.png``, where ``interactive-slug`` is the + value given for the ``slug`` tag parameter (see above). - If the ``thumbnail`` value provided is a relative link (a link that doesn't start with ``http:``), the link will be rendered with a Django @@ -128,7 +128,7 @@ Overriding HTML for Interactives When overriding the HTML for interactives, the following Jinja2 placeholders are available: - ``{{ type }}`` - The type of the interactive. -- ``{{ name }}`` - The slug name of the interactive to include/link to. +- ``{{ slug }}`` - The slug of the interactive to include/link to. - ``{{ text }}`` - The text to to display to a link to a ``whole-page`` interactive. - ``{{ parameters }}`` - GET parameters to append to the interactive link. From 3b61eb2a952d010ac236032149a876603a6413bd Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Thu, 22 Mar 2018 16:07:23 +1300 Subject: [PATCH 11/73] Updated readme to correct panel syntax --- README.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 0fcacbae..15d0f2e0 100644 --- a/README.rst +++ b/README.rst @@ -19,7 +19,9 @@ markdown: Example Paragraph - {panel type="example" title="Example Panel"} + {panel type="example"} + + # Example Panel {image file-path="http://placehold.it/350x150" caption="Example Image"} From fa61cc56cd2b32162b829700e6b212730b5153b2 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Thu, 22 Mar 2018 17:03:26 +1300 Subject: [PATCH 12/73] Changed template for youtube video to not include ?rel=0 by default --- verto/html-templates/video-youtube.html | 2 +- verto/processors/VideoBlockProcessor.py | 2 +- verto/tests/ConfigurationTest.py | 312 +++++++++--------- verto/tests/VideoTest.py | 15 +- ...ll_processors_except_comment_expected.html | 2 +- .../all_processors_expected.html | 2 +- .../multiline_templates_expected.html | 2 +- .../contains_multiple_videos_expected.html | 6 +- .../doc_example_basic_usage_expected.html | 2 +- .../doc_example_override_html_expected.html | 2 +- .../multiple_youtube_links_expected.html | 10 +- .../youtube_and_vimeo_links_expected.html | 10 +- .../video/youtube_be_link_expected.html | 2 +- .../tests/assets/video/youtube_embed_link.md | 2 +- .../video/youtube_embed_link_expected.html | 2 +- .../video/youtube_watch_link_expected.html | 2 +- 16 files changed, 188 insertions(+), 187 deletions(-) diff --git a/verto/html-templates/video-youtube.html b/verto/html-templates/video-youtube.html index 805ebfbc..aee17c27 100644 --- a/verto/html-templates/video-youtube.html +++ b/verto/html-templates/video-youtube.html @@ -1 +1 @@ -https://www.youtube.com/embed/{{ identifier }}?rel=0 +https://www.youtube.com/embed/{{ identifier }} diff --git a/verto/processors/VideoBlockProcessor.py b/verto/processors/VideoBlockProcessor.py index 7706388c..573a7893 100644 --- a/verto/processors/VideoBlockProcessor.py +++ b/verto/processors/VideoBlockProcessor.py @@ -88,7 +88,7 @@ def extract_video_identifier(self, video_url): ''' if re.match('.*?youtu\.{0,1}be(.com){0,1}', video_url) is not None: # is a youtube url - video_url = re.sub(r'(.*?)(\?rel=0)', r'\g<1>', video_url) + video_url = re.sub(r'(.*?)(\?rel=0 )', r'\g<1>', video_url) if 'youtu.be' in video_url or 'youtube.com/embed' in video_url: video_query = video_url.split('/')[-1] elif 'youtube.com' in video_url: diff --git a/verto/tests/ConfigurationTest.py b/verto/tests/ConfigurationTest.py index 10bf8e72..ceed0c44 100644 --- a/verto/tests/ConfigurationTest.py +++ b/verto/tests/ConfigurationTest.py @@ -1,10 +1,8 @@ -import unittest from verto.Verto import Verto, VertoResult from verto.processors.ScratchTreeprocessor import ScratchImageMetaData from verto.utils.HeadingNode import HeadingNode -import jinja2 from verto.tests.BaseTest import BaseTest -from collections import defaultdict + class ConfigurationTest(BaseTest): '''Test configuration methods of Verto @@ -26,107 +24,108 @@ def __init__(self, *args, **kwargs): self.maxDiff = None self.custom_templates = { 'image': '', - 'boxed-text': '
{% autoescape false %}{{ text }}{% endautoescape %}
' + 'boxed-text': '
{% autoescape false %}{{ text }}{% endautoescape %}
', + 'video-youtube': 'https://www.youtube.com/embed/{{ identifier }}?rel=0' } def test_multiple_calls(self): '''Checks all fields of VertoResult are correct for multiple Verto calls. ''' - test_cases = [ - ('all_processors.md', - VertoResult( - html_string=self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True), - title='Example Title', - required_files={ - 'interactives': { - 'binary-cards' - }, - 'images': set(), - 'page_scripts': set(), - 'scratch_images': { - ScratchImageMetaData( - hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', - text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' - ), - } + test_cases = [( + 'all_processors.md', + VertoResult( + html_string=self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True), + title='Example Title', + required_files={ + 'interactives': { + 'binary-cards' }, - heading_tree=(HeadingNode( - title='Example Title', - title_slug='example-title', - level=1, - children=(), + 'images': set(), + 'page_scripts': set(), + 'scratch_images': { + ScratchImageMetaData( + hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', + text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' ), - HeadingNode( - title='Example Title 2', - title_slug='example-title-2', - level=1, - children=() - ), - ), - required_glossary_terms={ - 'algorithm': [] } - ) - ), - ('some_processors.md', - VertoResult( - html_string=self.read_test_file(self.test_name, 'some_processors_expected.html', strip=True), - title='Another Example Title', - required_files={ - 'interactives': set(), - 'images': {'totally-legit-image.png'}, - 'page_scripts': set(), - 'scratch_images': set() - }, - heading_tree=(HeadingNode( - title='Another Example Title', - title_slug='another-example-title', - level=1, - children=(HeadingNode( - title='This is an H2', - title_slug='this-is-an-h2', - level=2, - children=() - ),), - ),), - required_glossary_terms={ - 'chomsky-hierarchy': - [('Formal languages', 'glossary-chomsky-hierarchy')] - } - ) - ), - ('some_processors_2.md', - VertoResult( - html_string=self.read_test_file(self.test_name, 'some_processors_2_expected.html', strip=True), - title='Another Example Title', - required_files={ - 'interactives': set(), - 'images': { - 'totally-legit-image.png', - 'finite-state-automata-no-trap-example.png', - 'finite-state-automata-trap-added-example.png', - 'finite-state-automata-trap-added-extreme-example.png', - }, - 'page_scripts': set(), - 'scratch_images': set() - }, - heading_tree=(HeadingNode( - title='Another Example Title', - title_slug='another-example-title', + }, + heading_tree=( + HeadingNode( + title='Example Title', + title_slug='example-title', level=1, children=(), + ), + HeadingNode( + title='Example Title 2', + title_slug='example-title-2', + level=1, + children=() + ), + ), + required_glossary_terms={ + 'algorithm': [] + } + ) + ), ( + 'some_processors.md', + VertoResult( + html_string=self.read_test_file(self.test_name, 'some_processors_expected.html', strip=True), + title='Another Example Title', + required_files={ + 'interactives': set(), + 'images': {'totally-legit-image.png'}, + 'page_scripts': set(), + 'scratch_images': set() + }, + heading_tree=(HeadingNode( + title='Another Example Title', + title_slug='another-example-title', + level=1, + children=(HeadingNode( + title='This is an H2', + title_slug='this-is-an-h2', + level=2, + children=() ),), - required_glossary_terms={ - 'hello': [], - 'algorithm': - [('computer program', 'glossary-algorithm'), - ('algorithm cost', 'glossary-algorithm-2'), - ('searching algorithms', 'glossary-algorithm-3'), - ('sorting algorithms', 'glossary-algorithm-4')] - } - ) + ),), + required_glossary_terms={ + 'chomsky-hierarchy': + [('Formal languages', 'glossary-chomsky-hierarchy')] + } + ) + ), ( + 'some_processors_2.md', + VertoResult( + html_string=self.read_test_file(self.test_name, 'some_processors_2_expected.html', strip=True), + title='Another Example Title', + required_files={ + 'interactives': set(), + 'images': { + 'totally-legit-image.png', + 'finite-state-automata-no-trap-example.png', + 'finite-state-automata-trap-added-example.png', + 'finite-state-automata-trap-added-extreme-example.png', + }, + 'page_scripts': set(), + 'scratch_images': set() + }, + heading_tree=(HeadingNode( + title='Another Example Title', + title_slug='another-example-title', + level=1, + children=(), + ),), + required_glossary_terms={ + 'hello': [], + 'algorithm': + [('computer program', 'glossary-algorithm'), + ('algorithm cost', 'glossary-algorithm-2'), + ('searching algorithms', 'glossary-algorithm-3'), + ('sorting algorithms', 'glossary-algorithm-4')] + } ) - ] + )] verto = Verto() for filename, expected_result in test_cases: @@ -145,71 +144,72 @@ def test_multiple_calls_without_clearing(self): filename = 'all_processors.md' other_filename = 'otherfile.md' expected_result = VertoResult( - html_string=self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True), - title='Example Title', - required_files={ - 'interactives': { - 'binary-cards' - }, - 'images': set(), - 'page_scripts': set(), - 'scratch_images': { - ScratchImageMetaData( - hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', - text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' - ), - } - }, - heading_tree=(HeadingNode( - title='Example Title', - title_slug='example-title', - level=1, - children=(), - ), - HeadingNode( - title='Example Title 2', - title_slug='example-title-2', - level=1, - children=() - ), - ), - required_glossary_terms={ - 'algorithm': [] - } - ) + html_string=self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True), + title='Example Title', + required_files={ + 'interactives': { + 'binary-cards' + }, + 'images': set(), + 'page_scripts': set(), + 'scratch_images': { + ScratchImageMetaData( + hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', + text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' + ), + } + }, + heading_tree=( + HeadingNode( + title='Example Title', + title_slug='example-title', + level=1, + children=(), + ), + HeadingNode( + title='Example Title 2', + title_slug='example-title-2', + level=1, + children=() + ), + ), + required_glossary_terms={ + 'algorithm': [] + } + ) expected_otherfile_result = VertoResult( - html_string=self.read_test_file(self.test_name, 'otherfile_expected.html', strip=True), - title='Example Title', - required_files={ - 'interactives': { - 'binary-cards' - }, - 'images': { - 'pixel-diamond.png' - }, - 'page_scripts': set(), - 'scratch_images': { - ScratchImageMetaData( - hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', - text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' - ), - ScratchImageMetaData( - hash='b78bff524e54a18116e1e898a93e360827f874a8b0b508e1edc47d21516495ad', - text='never\ngoing\nto\ngive\nyou\nup' - ), - } - }, - heading_tree=(HeadingNode( - title='Example Title', - title_slug='example-title-3', - level=1, - children=(), - ), - ), - required_glossary_terms={ - 'algorithm': [] - } - ) + html_string=self.read_test_file(self.test_name, 'otherfile_expected.html', strip=True), + title='Example Title', + required_files={ + 'interactives': { + 'binary-cards' + }, + 'images': { + 'pixel-diamond.png' + }, + 'page_scripts': set(), + 'scratch_images': { + ScratchImageMetaData( + hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', + text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' + ), + ScratchImageMetaData( + hash='b78bff524e54a18116e1e898a93e360827f874a8b0b508e1edc47d21516495ad', + text='never\ngoing\nto\ngive\nyou\nup' + ), + } + }, + heading_tree=(HeadingNode( + title='Example Title', + title_slug='example-title-3', + level=1, + children=(), + ), + ), + required_glossary_terms={ + 'algorithm': [] + } + ) verto = Verto() # First file diff --git a/verto/tests/VideoTest.py b/verto/tests/VideoTest.py index 61d88c66..19ccffb2 100644 --- a/verto/tests/VideoTest.py +++ b/verto/tests/VideoTest.py @@ -3,7 +3,6 @@ from verto.VertoExtension import VertoExtension from verto.processors.VideoBlockProcessor import VideoBlockProcessor -from verto.errors.NoSourceLinkError import NoSourceLinkError from verto.errors.NoVideoIdentifierError import NoVideoIdentifierError from verto.errors.UnsupportedVideoPlayerError import UnsupportedVideoPlayerError from verto.tests.ProcessorTest import ProcessorTest @@ -23,10 +22,10 @@ def __init__(self, *args, **kwargs): self.processor_name = 'video' self.ext = Mock() self.ext.jinja_templates = { - self.processor_name: ProcessorTest.loadJinjaTemplate(self, self.processor_name), - 'video-youtube': ProcessorTest.loadJinjaTemplate(self, 'video-youtube'), - 'video-vimeo': ProcessorTest.loadJinjaTemplate(self, 'video-vimeo') - } + self.processor_name: ProcessorTest.loadJinjaTemplate(self, self.processor_name), + 'video-youtube': ProcessorTest.loadJinjaTemplate(self, 'video-youtube'), + 'video-vimeo': ProcessorTest.loadJinjaTemplate(self, 'video-vimeo') + } self.ext.processor_info = ProcessorTest.loadProcessorInfo(self) def test_contains_no_video(self): @@ -173,9 +172,11 @@ def test_contains_multiple_videos(self): converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_file_string = self.read_test_file(self.processor_name, 'contains_multiple_videos_expected.html', strip=True) self.assertEqual(converted_test_string, expected_file_string) - #~ + + # ~ # Doc Tests - #~ + # ~ + def test_doc_example_basic(self): '''A generic example of common usage. ''' diff --git a/verto/tests/assets/configuration/all_processors_except_comment_expected.html b/verto/tests/assets/configuration/all_processors_except_comment_expected.html index e8d4396a..dc7e7c61 100644 --- a/verto/tests/assets/configuration/all_processors_except_comment_expected.html +++ b/verto/tests/assets/configuration/all_processors_except_comment_expected.html @@ -49,5 +49,5 @@

{{ table_of_contents }}
- +
diff --git a/verto/tests/assets/configuration/all_processors_expected.html b/verto/tests/assets/configuration/all_processors_expected.html index c41d5f63..69e12543 100644 --- a/verto/tests/assets/configuration/all_processors_expected.html +++ b/verto/tests/assets/configuration/all_processors_expected.html @@ -48,5 +48,5 @@

{{ table_of_contents }}
- +
diff --git a/verto/tests/assets/configuration/multiline_templates_expected.html b/verto/tests/assets/configuration/multiline_templates_expected.html index e0ef1e24..5aa68efa 100644 --- a/verto/tests/assets/configuration/multiline_templates_expected.html +++ b/verto/tests/assets/configuration/multiline_templates_expected.html @@ -47,5 +47,5 @@

{{ table_of_contents }}
- +
diff --git a/verto/tests/assets/video/contains_multiple_videos_expected.html b/verto/tests/assets/video/contains_multiple_videos_expected.html index dbf02d94..9882716d 100644 --- a/verto/tests/assets/video/contains_multiple_videos_expected.html +++ b/verto/tests/assets/video/contains_multiple_videos_expected.html @@ -1,13 +1,13 @@

Videos

There and back again: a packet's tale

- +

How does the internet work?

- +

How the internet works in 5 minutes

- +
diff --git a/verto/tests/assets/video/doc_example_basic_usage_expected.html b/verto/tests/assets/video/doc_example_basic_usage_expected.html index 0db0aa21..68ae17cb 100644 --- a/verto/tests/assets/video/doc_example_basic_usage_expected.html +++ b/verto/tests/assets/video/doc_example_basic_usage_expected.html @@ -1,3 +1,3 @@
- +
diff --git a/verto/tests/assets/video/doc_example_override_html_expected.html b/verto/tests/assets/video/doc_example_override_html_expected.html index 32c0429b..69f91d54 100644 --- a/verto/tests/assets/video/doc_example_override_html_expected.html +++ b/verto/tests/assets/video/doc_example_override_html_expected.html @@ -1,3 +1,3 @@
- +
diff --git a/verto/tests/assets/video/multiple_youtube_links_expected.html b/verto/tests/assets/video/multiple_youtube_links_expected.html index 2d452568..4e40316d 100644 --- a/verto/tests/assets/video/multiple_youtube_links_expected.html +++ b/verto/tests/assets/video/multiple_youtube_links_expected.html @@ -1,21 +1,21 @@

Videos

There and back again: a packet's tale

- +

How does the internet work?

- +

Totally real video

- +

How the internet works in 5 minutes

- +

It has English captions, but the most interesting part is what is happening in the action.

- +
diff --git a/verto/tests/assets/video/youtube_and_vimeo_links_expected.html b/verto/tests/assets/video/youtube_and_vimeo_links_expected.html index 708705db..5cfd9024 100644 --- a/verto/tests/assets/video/youtube_and_vimeo_links_expected.html +++ b/verto/tests/assets/video/youtube_and_vimeo_links_expected.html @@ -1,29 +1,29 @@

Videos

There and back again: a packet's tale

- +

How does the internet work?

- +

Totally real video

- +

How the internet works in 5 minutes

- +

It has English captions, but the most interesting part is what is happening in the action.

- +
diff --git a/verto/tests/assets/video/youtube_be_link_expected.html b/verto/tests/assets/video/youtube_be_link_expected.html index 48a1c01b..3c712c3e 100644 --- a/verto/tests/assets/video/youtube_be_link_expected.html +++ b/verto/tests/assets/video/youtube_be_link_expected.html @@ -1,5 +1,5 @@

Engineering Disasters 13: Software Flaws

- +

is an excerpt from Engineering Disaster Episode 13 explaining software flaws in Ariane 5 and Patriot Missiles

diff --git a/verto/tests/assets/video/youtube_embed_link.md b/verto/tests/assets/video/youtube_embed_link.md index b7605f64..ce5c0d33 100644 --- a/verto/tests/assets/video/youtube_embed_link.md +++ b/verto/tests/assets/video/youtube_embed_link.md @@ -1,6 +1,6 @@ ## Run Length Encoding -{video url="https://www.youtube.com/embed/uaV2RuAJTjQ?rel=0"} +{video url="https://www.youtube.com/embed/uaV2RuAJTjQ"} Run length encoding (RLE) is a technique that isn't so widely used these days, but it's a great way to get a feel for some of the issues around using compression. diff --git a/verto/tests/assets/video/youtube_embed_link_expected.html b/verto/tests/assets/video/youtube_embed_link_expected.html index 151447a8..d846cf76 100644 --- a/verto/tests/assets/video/youtube_embed_link_expected.html +++ b/verto/tests/assets/video/youtube_embed_link_expected.html @@ -1,6 +1,6 @@

Run Length Encoding

- +

Run length encoding (RLE) is a technique that isn't so widely used these days, but it's a great way to get a feel for some of the issues around using compression.

{panel type="teacher-note" summary="Who uses run length encoding?"}

diff --git a/verto/tests/assets/video/youtube_watch_link_expected.html b/verto/tests/assets/video/youtube_watch_link_expected.html index 77b23ec3..4c6dde17 100644 --- a/verto/tests/assets/video/youtube_watch_link_expected.html +++ b/verto/tests/assets/video/youtube_watch_link_expected.html @@ -4,6 +4,6 @@

The Turing Test

{panel type="teacher-note" summary="TED video introducing the Turing Test"}

There is a TED video that gives an overview of the Turing Test on YouTube

- +

{panel end}

From 5ad383d2426776863592a287741ea9854cd15ad1 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Thu, 22 Mar 2018 17:10:39 +1300 Subject: [PATCH 13/73] Fixed extra space mysteriously added to regex --- verto/processors/VideoBlockProcessor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/verto/processors/VideoBlockProcessor.py b/verto/processors/VideoBlockProcessor.py index 573a7893..7706388c 100644 --- a/verto/processors/VideoBlockProcessor.py +++ b/verto/processors/VideoBlockProcessor.py @@ -88,7 +88,7 @@ def extract_video_identifier(self, video_url): ''' if re.match('.*?youtu\.{0,1}be(.com){0,1}', video_url) is not None: # is a youtube url - video_url = re.sub(r'(.*?)(\?rel=0 )', r'\g<1>', video_url) + video_url = re.sub(r'(.*?)(\?rel=0)', r'\g<1>', video_url) if 'youtu.be' in video_url or 'youtube.com/embed' in video_url: video_query = video_url.split('/')[-1] elif 'youtube.com' in video_url: From 6ed0d06ce54da462cae2305fb33d66465f7dd940 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Fri, 23 Mar 2018 19:06:55 +1300 Subject: [PATCH 14/73] WIP fixing tests for required alt tag in images --- verto/processor-info.json | 2 +- verto/tests/ImageTagTest.py | 16 ++----- verto/tests/assets/image-tag/contains_alt.md | 3 -- .../image-tag/contains_alt_expected.html | 4 -- .../file_width_value_external_image.md | 2 +- ...e_width_value_external_image_expected.html | 2 +- .../image-tag/file_width_value_no_units.md | 2 +- .../file_width_value_no_units_expected.html | 2 +- .../assets/image-tag/missing_alt_parameter.md | 3 ++ .../multiple_images_captions_false.md | 2 +- ...ltiple_images_captions_false_expected.html | 2 +- ...ultiple_images_captions_true_expected.html | 2 +- verto/tests/start_tests.py | 42 +++++++++---------- 13 files changed, 36 insertions(+), 48 deletions(-) delete mode 100644 verto/tests/assets/image-tag/contains_alt.md delete mode 100644 verto/tests/assets/image-tag/contains_alt_expected.html create mode 100644 verto/tests/assets/image-tag/missing_alt_parameter.md diff --git a/verto/processor-info.json b/verto/processor-info.json index b47faaee..25216562 100644 --- a/verto/processor-info.json +++ b/verto/processor-info.json @@ -131,7 +131,7 @@ "dependencies": [] }, "alt": { - "required": false, + "required": true, "dependencies": [] }, "caption": { diff --git a/verto/tests/ImageTagTest.py b/verto/tests/ImageTagTest.py index 9c885cfb..9532ccdb 100644 --- a/verto/tests/ImageTagTest.py +++ b/verto/tests/ImageTagTest.py @@ -177,23 +177,15 @@ def test_contains_hover_text(self): } self.assertSetEqual(expected_images, images) - def test_contains_alt(self): - '''Tests that argument for alt produces expected output and expected images are updated. + def test_missing_alt_parameter(self): + '''Tests that missing alt argument produces correct error. ''' - test_string = self.read_test_file(self.processor_name, 'contains_alt.md') + test_string = self.read_test_file(self.processor_name, 'missing_alt_parameter.md') blocks = self.to_blocks(test_string) self.assertListEqual([True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'contains_alt_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' - } - self.assertSetEqual(expected_images, images) + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) def test_contains_source(self): '''Tests that argument for source produces expected output and expected images are updated. diff --git a/verto/tests/assets/image-tag/contains_alt.md b/verto/tests/assets/image-tag/contains_alt.md deleted file mode 100644 index ee2fd7ee..00000000 --- a/verto/tests/assets/image-tag/contains_alt.md +++ /dev/null @@ -1,3 +0,0 @@ -{image file-path="computer-studying-turing-test.png" alt="Lipsum"} - -Some text after. diff --git a/verto/tests/assets/image-tag/contains_alt_expected.html b/verto/tests/assets/image-tag/contains_alt_expected.html deleted file mode 100644 index 52ddc6b3..00000000 --- a/verto/tests/assets/image-tag/contains_alt_expected.html +++ /dev/null @@ -1,4 +0,0 @@ -
-Lipsum -
-

Some text after.

diff --git a/verto/tests/assets/image-tag/file_width_value_external_image.md b/verto/tests/assets/image-tag/file_width_value_external_image.md index a4e7e4c6..4a2ac5b2 100644 --- a/verto/tests/assets/image-tag/file_width_value_external_image.md +++ b/verto/tests/assets/image-tag/file_width_value_external_image.md @@ -1 +1 @@ -{image file-path="https://www.verto.io/images/image@200px.png"} +{image alt="text" file-path="https://www.verto.io/images/image@200px.png"} diff --git a/verto/tests/assets/image-tag/file_width_value_external_image_expected.html b/verto/tests/assets/image-tag/file_width_value_external_image_expected.html index bf1003ff..b6bfa196 100644 --- a/verto/tests/assets/image-tag/file_width_value_external_image_expected.html +++ b/verto/tests/assets/image-tag/file_width_value_external_image_expected.html @@ -1 +1 @@ - +text diff --git a/verto/tests/assets/image-tag/file_width_value_no_units.md b/verto/tests/assets/image-tag/file_width_value_no_units.md index a8287260..e999d072 100644 --- a/verto/tests/assets/image-tag/file_width_value_no_units.md +++ b/verto/tests/assets/image-tag/file_width_value_no_units.md @@ -1 +1 @@ -{image file-path="path/to/image@900.png"} +{image file-path="path/to/image@900.png" alt="alt text"} diff --git a/verto/tests/assets/image-tag/file_width_value_no_units_expected.html b/verto/tests/assets/image-tag/file_width_value_no_units_expected.html index df31a586..42871606 100644 --- a/verto/tests/assets/image-tag/file_width_value_no_units_expected.html +++ b/verto/tests/assets/image-tag/file_width_value_no_units_expected.html @@ -1 +1 @@ - +text diff --git a/verto/tests/assets/image-tag/missing_alt_parameter.md b/verto/tests/assets/image-tag/missing_alt_parameter.md new file mode 100644 index 00000000..2be8e999 --- /dev/null +++ b/verto/tests/assets/image-tag/missing_alt_parameter.md @@ -0,0 +1,3 @@ +{image file-path="computer-studying-turing-test.png"} + +Some text after. diff --git a/verto/tests/assets/image-tag/multiple_images_captions_false.md b/verto/tests/assets/image-tag/multiple_images_captions_false.md index 3f90c160..4397a812 100644 --- a/verto/tests/assets/image-tag/multiple_images_captions_false.md +++ b/verto/tests/assets/image-tag/multiple_images_captions_false.md @@ -1,6 +1,6 @@ Imagine we have the following simple black and white image. -{image file-path="the-first-image.png" caption="false"} +{image file-path="the-first-image.png" caption="false" alt="alt text"} {image file-path="Lipsum.png" caption="false" alt="A diamond shape made out of pixels"} diff --git a/verto/tests/assets/image-tag/multiple_images_captions_false_expected.html b/verto/tests/assets/image-tag/multiple_images_captions_false_expected.html index 31c9eeab..7e7a46b4 100644 --- a/verto/tests/assets/image-tag/multiple_images_captions_false_expected.html +++ b/verto/tests/assets/image-tag/multiple_images_captions_false_expected.html @@ -1,6 +1,6 @@

Imagine we have the following simple black and white image.

- +alt text
A diamond shape made out of pixels diff --git a/verto/tests/assets/image-tag/multiple_images_captions_true_expected.html b/verto/tests/assets/image-tag/multiple_images_captions_true_expected.html index 671e74c9..8fa494d3 100644 --- a/verto/tests/assets/image-tag/multiple_images_captions_true_expected.html +++ b/verto/tests/assets/image-tag/multiple_images_captions_true_expected.html @@ -1,6 +1,6 @@

Imagine we have the following simple black and white image.

- +the alt text
A diamond shape made out of pixels diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 5cfc39b3..92cf82f9 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -85,31 +85,31 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - unittest.makeSuite(BoxedTextTest), - unittest.makeSuite(ButtonLinkTest), - unittest.makeSuite(CommentTest), + # unittest.makeSuite(BoxedTextTest), + # unittest.makeSuite(ButtonLinkTest), + # unittest.makeSuite(CommentTest), unittest.makeSuite(ConditionalTest), - unittest.makeSuite(FrameTest), - unittest.makeSuite(GlossaryLinkTest), - unittest.makeSuite(HeadingTest), + # unittest.makeSuite(FrameTest), + # unittest.makeSuite(GlossaryLinkTest), + # unittest.makeSuite(HeadingTest), unittest.makeSuite(ImageInlineTest), unittest.makeSuite(ImageTagTest), unittest.makeSuite(ImageContainerTest), - unittest.makeSuite(InteractiveTest), - unittest.makeSuite(JinjaTest), - unittest.makeSuite(PanelTest), - unittest.makeSuite(SaveTitleTest), - unittest.makeSuite(ScratchTest), - unittest.makeSuite(ScratchInlineTest), - unittest.makeSuite(StyleTest), - unittest.makeSuite(RelativeLinkTest), - unittest.makeSuite(RemoveTest), - unittest.makeSuite(RemoveTitleTest), - unittest.makeSuite(TableOfContentsTest), - unittest.makeSuite(VideoTest), - - unittest.makeSuite(HtmlParserTest), - unittest.makeSuite(MarkdownOverrideTest), + # unittest.makeSuite(InteractiveTest), + # unittest.makeSuite(JinjaTest), + # unittest.makeSuite(PanelTest), + # unittest.makeSuite(SaveTitleTest), + # unittest.makeSuite(ScratchTest), + # unittest.makeSuite(ScratchInlineTest), + # unittest.makeSuite(StyleTest), + # unittest.makeSuite(RelativeLinkTest), + # unittest.makeSuite(RemoveTest), + # unittest.makeSuite(RemoveTitleTest), + # unittest.makeSuite(TableOfContentsTest), + # unittest.makeSuite(VideoTest), + + # unittest.makeSuite(HtmlParserTest), + # unittest.makeSuite(MarkdownOverrideTest), )) From c1d5bd92d12576e64543e2fa4b6b46bebebb790d Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Mon, 26 Mar 2018 04:23:06 +1300 Subject: [PATCH 15/73] Update python-slugify from 1.2.4 to 1.2.5 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a06dcfba..aaadd7a6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ # Required dependencies for Verto (installed automatically in setup.py) markdown==2.6.11 Jinja2==2.10 -python-slugify==1.2.4 +python-slugify==1.2.5 setuptools==39.0.1 # Required dependencies for building documentation From fc278614bc6c0c2340758d88c5ca93078edd3fc7 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Wed, 11 Apr 2018 09:55:48 +1200 Subject: [PATCH 16/73] Update sphinx_rtd_theme from 0.2.4 to 0.3.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a06dcfba..046a025e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,4 @@ setuptools==39.0.1 # Required dependencies for building documentation sphinx==1.7.2 -sphinx_rtd_theme==0.2.4 +sphinx_rtd_theme==0.3.0 From 02618c16c79370e0d1c75d8b3ef2151b3fd365ce Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Thu, 26 Apr 2018 17:08:48 +1200 Subject: [PATCH 17/73] Update sphinx from 1.7.2 to 1.7.4 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a06dcfba..6c1a9f46 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ python-slugify==1.2.4 setuptools==39.0.1 # Required dependencies for building documentation -sphinx==1.7.2 +sphinx==1.7.4 sphinx_rtd_theme==0.2.4 From 33c7f9fcc6d13078a92b5a321facfdf4657c67e5 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Sun, 29 Apr 2018 00:53:53 +1200 Subject: [PATCH 18/73] Update setuptools from 39.0.1 to 39.1.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a06dcfba..6dfd52df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ markdown==2.6.11 Jinja2==2.10 python-slugify==1.2.4 -setuptools==39.0.1 +setuptools==39.1.0 # Required dependencies for building documentation sphinx==1.7.2 From ae9bb515f7b423a89a343903ebdfac859f36feca Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 1 May 2018 17:51:45 +1200 Subject: [PATCH 19/73] Fixed image test - alt tag now required --- verto/Verto.py | 8 ++++ verto/tests/ImageTagTest.py | 19 +++++++++ verto/tests/assets/image-tag/align_center.md | 2 +- .../image-tag/align_center_expected.html | 2 +- verto/tests/assets/image-tag/align_left.md | 2 +- .../assets/image-tag/align_left_expected.html | 2 +- verto/tests/assets/image-tag/align_right.md | 2 +- .../image-tag/align_right_expected.html | 2 +- .../assets/image-tag/align_undefined_error.md | 2 +- .../assets/image-tag/contains_hover_text.md | 2 +- .../contains_hover_text_expected.html | 2 +- .../tests/assets/image-tag/contains_source.md | 2 +- .../image-tag/contains_source_expected.html | 2 +- .../image-tag/doc_example_2_override_html.md | 2 +- .../doc_example_2_override_html_expected.html | 2 +- .../doc_example_2_override_html_template.html | 2 +- .../image-tag/doc_example_basic_usage.md | 2 +- .../doc_example_basic_usage_expected.html | 2 +- .../image-tag/doc_example_override_html.md | 2 +- .../doc_example_override_html_expected.html | 2 +- .../doc_example_override_html_template.html | 2 +- .../image-tag/file_invalid_width_value_1.md | 2 +- .../file_invalid_width_value_1_expected.html | 2 +- ...e_invalid_width_value_1_html_template.html | 2 +- .../image-tag/file_invalid_width_value_2.md | 2 +- .../file_invalid_width_value_2_expected.html | 2 +- ...e_invalid_width_value_2_html_template.html | 2 +- .../assets/image-tag/file_width_value.md | 2 +- .../image-tag/file_width_value_expected.html | 2 +- ...th_value_external_image_html_template.html | 2 +- .../file_width_value_html_template.html | 2 +- .../file_width_value_no_units_expected.html | 2 +- ...le_width_value_no_units_html_template.html | 2 +- .../image-tag/image_in_numbered_list.md | 2 +- .../image_in_numbered_list_expected.html | 2 +- verto/tests/start_tests.py | 42 +++++++++---------- 36 files changed, 81 insertions(+), 54 deletions(-) diff --git a/verto/Verto.py b/verto/Verto.py index 1f572dec..bd8dc370 100644 --- a/verto/Verto.py +++ b/verto/Verto.py @@ -47,6 +47,14 @@ def __init__(self, processors=DEFAULT_PROCESSORS, html_templates={}, extensions= self.processors = set(processors) self.html_templates = dict(html_templates) self.extensions = list(extensions) + ### WIP + # Overwrite processor-info file with any rules given here + self.custom_rules = { + 'image': { + 'alt': False + } + } + ### self.create_converter() def create_converter(self): diff --git a/verto/tests/ImageTagTest.py b/verto/tests/ImageTagTest.py index 9532ccdb..e1f2b38e 100644 --- a/verto/tests/ImageTagTest.py +++ b/verto/tests/ImageTagTest.py @@ -300,12 +300,16 @@ def test_image_width_value(self): ''' test_string = self.read_test_file(self.processor_name, 'file_width_value.md') blocks = self.to_blocks(test_string) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + html_template = self.read_test_file(self.processor_name, 'file_width_value_html_template.html', strip=True) verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) expected_string = self.read_test_file(self.processor_name, 'file_width_value_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) + images = self.verto_extension.required_files['images'] expected_images = set() self.assertSetEqual(expected_images, images) @@ -315,12 +319,16 @@ def test_image_width_value_no_units(self): ''' test_string = self.read_test_file(self.processor_name, 'file_width_value_no_units.md') blocks = self.to_blocks(test_string) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + html_template = self.read_test_file(self.processor_name, 'file_width_value_no_units_html_template.html', strip=True) verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) expected_string = self.read_test_file(self.processor_name, 'file_width_value_no_units_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) + images = self.verto_extension.required_files['images'] expected_images = set() self.assertSetEqual(expected_images, images) @@ -330,12 +338,15 @@ def test_image_invalid_width_value_1(self): ''' test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1.md') blocks = self.to_blocks(test_string) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_html_template.html', strip=True) verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) + images = self.verto_extension.required_files['images'] expected_images = set() self.assertSetEqual(expected_images, images) @@ -345,12 +356,16 @@ def test_image_invalid_width_value_2(self): ''' test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2.md') blocks = self.to_blocks(test_string) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_html_template.html', strip=True) verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) + images = self.verto_extension.required_files['images'] expected_images = set() self.assertSetEqual(expected_images, images) @@ -360,12 +375,16 @@ def test_image_width_value_external_image(self): ''' test_string = self.read_test_file(self.processor_name, 'file_width_value_external_image.md') blocks = self.to_blocks(test_string) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + html_template = self.read_test_file(self.processor_name, 'file_width_value_external_image_html_template.html', strip=True) verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) expected_string = self.read_test_file(self.processor_name, 'file_width_value_external_image_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) + images = self.verto_extension.required_files['images'] expected_images = set() self.assertSetEqual(expected_images, images) diff --git a/verto/tests/assets/image-tag/align_center.md b/verto/tests/assets/image-tag/align_center.md index d4e15401..131181af 100644 --- a/verto/tests/assets/image-tag/align_center.md +++ b/verto/tests/assets/image-tag/align_center.md @@ -1,5 +1,5 @@ Some text before. -{image file-path="computer-studying-turing-test.png" caption="false" alignment="center"} +{image file-path="computer-studying-turing-test.png" alt="placeholder image" caption="false" alignment="center"} Some text after. diff --git a/verto/tests/assets/image-tag/align_center_expected.html b/verto/tests/assets/image-tag/align_center_expected.html index d25639fb..083104d0 100644 --- a/verto/tests/assets/image-tag/align_center_expected.html +++ b/verto/tests/assets/image-tag/align_center_expected.html @@ -1,5 +1,5 @@

Some text before.

- +placeholder image

Some text after.

diff --git a/verto/tests/assets/image-tag/align_left.md b/verto/tests/assets/image-tag/align_left.md index c0d65c2f..738364cf 100644 --- a/verto/tests/assets/image-tag/align_left.md +++ b/verto/tests/assets/image-tag/align_left.md @@ -1 +1 @@ -{image file-path="computer-studying-turing-test.png" alignment="left"} +{image alt="placeholder image" file-path="computer-studying-turing-test.png" alignment="left"} diff --git a/verto/tests/assets/image-tag/align_left_expected.html b/verto/tests/assets/image-tag/align_left_expected.html index 3b7d79f1..d75c15e4 100644 --- a/verto/tests/assets/image-tag/align_left_expected.html +++ b/verto/tests/assets/image-tag/align_left_expected.html @@ -1,3 +1,3 @@
- +placeholder image
diff --git a/verto/tests/assets/image-tag/align_right.md b/verto/tests/assets/image-tag/align_right.md index 6fc50a4a..eb18da69 100644 --- a/verto/tests/assets/image-tag/align_right.md +++ b/verto/tests/assets/image-tag/align_right.md @@ -1 +1 @@ -{image file-path="computer-studying-turing-test.png" alignment="right"} +{image file-path="computer-studying-turing-test.png" alt="placeholder image" alignment="right"} diff --git a/verto/tests/assets/image-tag/align_right_expected.html b/verto/tests/assets/image-tag/align_right_expected.html index 6f88c4ca..8ef59fba 100644 --- a/verto/tests/assets/image-tag/align_right_expected.html +++ b/verto/tests/assets/image-tag/align_right_expected.html @@ -1,3 +1,3 @@
- +placeholder image
diff --git a/verto/tests/assets/image-tag/align_undefined_error.md b/verto/tests/assets/image-tag/align_undefined_error.md index d8d24505..7be59d44 100644 --- a/verto/tests/assets/image-tag/align_undefined_error.md +++ b/verto/tests/assets/image-tag/align_undefined_error.md @@ -1 +1 @@ -{image file-path="computer-studying-turing-test.png" alignment="around-about-here"} +{image file-path="computer-studying-turing-test.png" alignment="around-about-here" alt="placeholder image"} diff --git a/verto/tests/assets/image-tag/contains_hover_text.md b/verto/tests/assets/image-tag/contains_hover_text.md index b5c9bc76..59eb1acb 100644 --- a/verto/tests/assets/image-tag/contains_hover_text.md +++ b/verto/tests/assets/image-tag/contains_hover_text.md @@ -1,3 +1,3 @@ Some text before. -{image file-path="computer-studying-turing-test.png" hover-text="Lipsum"} +{image file-path="computer-studying-turing-test.png" hover-text="Lipsum" alt="placeholder image"} diff --git a/verto/tests/assets/image-tag/contains_hover_text_expected.html b/verto/tests/assets/image-tag/contains_hover_text_expected.html index 7b64b2c0..3287e46d 100644 --- a/verto/tests/assets/image-tag/contains_hover_text_expected.html +++ b/verto/tests/assets/image-tag/contains_hover_text_expected.html @@ -1,4 +1,4 @@

Some text before.

- +placeholder image
diff --git a/verto/tests/assets/image-tag/contains_source.md b/verto/tests/assets/image-tag/contains_source.md index a87b3c4d..2a84bd32 100644 --- a/verto/tests/assets/image-tag/contains_source.md +++ b/verto/tests/assets/image-tag/contains_source.md @@ -1,3 +1,3 @@ So it goes... -{image caption="false" file-path="computer-studying-turing-test.png" source="example.com"} +{image caption="false" file-path="computer-studying-turing-test.png" alt="placeholder image" source="example.com"} diff --git a/verto/tests/assets/image-tag/contains_source_expected.html b/verto/tests/assets/image-tag/contains_source_expected.html index e12ecea6..a0a19d9c 100644 --- a/verto/tests/assets/image-tag/contains_source_expected.html +++ b/verto/tests/assets/image-tag/contains_source_expected.html @@ -1,5 +1,5 @@

So it goes...

diff --git a/verto/tests/assets/image-tag/doc_example_2_override_html.md b/verto/tests/assets/image-tag/doc_example_2_override_html.md index d6818613..4428e4ff 100644 --- a/verto/tests/assets/image-tag/doc_example_2_override_html.md +++ b/verto/tests/assets/image-tag/doc_example_2_override_html.md @@ -1 +1 @@ -{image file-path="path/to/image@500px.png"} +{image alt="placeholder image" file-path="path/to/image@500px.png"} diff --git a/verto/tests/assets/image-tag/doc_example_2_override_html_expected.html b/verto/tests/assets/image-tag/doc_example_2_override_html_expected.html index 9e55150c..be5d1659 100644 --- a/verto/tests/assets/image-tag/doc_example_2_override_html_expected.html +++ b/verto/tests/assets/image-tag/doc_example_2_override_html_expected.html @@ -1 +1 @@ - +placeholder image diff --git a/verto/tests/assets/image-tag/doc_example_2_override_html_template.html b/verto/tests/assets/image-tag/doc_example_2_override_html_template.html index a1343960..07a4fbc8 100644 --- a/verto/tests/assets/image-tag/doc_example_2_override_html_template.html +++ b/verto/tests/assets/image-tag/doc_example_2_override_html_template.html @@ -1,4 +1,4 @@ -placeholder image - +placeholder image

Source

diff --git a/verto/tests/assets/image-tag/doc_example_override_html.md b/verto/tests/assets/image-tag/doc_example_override_html.md index 17eb6ef7..205d12ba 100644 --- a/verto/tests/assets/image-tag/doc_example_override_html.md +++ b/verto/tests/assets/image-tag/doc_example_override_html.md @@ -1 +1 @@ -{image file-path="http://placehold.it/350x150" source="https://placehold.it/"} +{image file-path="http://placehold.it/350x150" alt="placeholder image" source="https://placehold.it/"} diff --git a/verto/tests/assets/image-tag/doc_example_override_html_expected.html b/verto/tests/assets/image-tag/doc_example_override_html_expected.html index 11846fa6..a2a18547 100644 --- a/verto/tests/assets/image-tag/doc_example_override_html_expected.html +++ b/verto/tests/assets/image-tag/doc_example_override_html_expected.html @@ -1,3 +1,3 @@
- +placeholder image
diff --git a/verto/tests/assets/image-tag/doc_example_override_html_template.html b/verto/tests/assets/image-tag/doc_example_override_html_template.html index 28028df8..98bf2b3b 100644 --- a/verto/tests/assets/image-tag/doc_example_override_html_template.html +++ b/verto/tests/assets/image-tag/doc_example_override_html_template.html @@ -1,3 +1,3 @@
- +placeholder image
diff --git a/verto/tests/assets/image-tag/file_invalid_width_value_1.md b/verto/tests/assets/image-tag/file_invalid_width_value_1.md index a3dbce88..08eedb77 100644 --- a/verto/tests/assets/image-tag/file_invalid_width_value_1.md +++ b/verto/tests/assets/image-tag/file_invalid_width_value_1.md @@ -1 +1 @@ -{image file-path="path/to/image@.png"} +{image alt="image alt text" file-path="path/to/image@.png"} diff --git a/verto/tests/assets/image-tag/file_invalid_width_value_1_expected.html b/verto/tests/assets/image-tag/file_invalid_width_value_1_expected.html index e66fe9be..0024f343 100644 --- a/verto/tests/assets/image-tag/file_invalid_width_value_1_expected.html +++ b/verto/tests/assets/image-tag/file_invalid_width_value_1_expected.html @@ -1 +1 @@ - +image alt text diff --git a/verto/tests/assets/image-tag/file_invalid_width_value_1_html_template.html b/verto/tests/assets/image-tag/file_invalid_width_value_1_html_template.html index a1343960..ebec4dcb 100644 --- a/verto/tests/assets/image-tag/file_invalid_width_value_1_html_template.html +++ b/verto/tests/assets/image-tag/file_invalid_width_value_1_html_template.html @@ -1,4 +1,4 @@ -image alt text +image alt text diff --git a/verto/tests/assets/image-tag/file_invalid_width_value_2_html_template.html b/verto/tests/assets/image-tag/file_invalid_width_value_2_html_template.html index a1343960..ebec4dcb 100644 --- a/verto/tests/assets/image-tag/file_invalid_width_value_2_html_template.html +++ b/verto/tests/assets/image-tag/file_invalid_width_value_2_html_template.html @@ -1,4 +1,4 @@ -image alt text +image alt text diff --git a/verto/tests/assets/image-tag/file_width_value_external_image_html_template.html b/verto/tests/assets/image-tag/file_width_value_external_image_html_template.html index a1343960..41e5c544 100644 --- a/verto/tests/assets/image-tag/file_width_value_external_image_html_template.html +++ b/verto/tests/assets/image-tag/file_width_value_external_image_html_template.html @@ -1,4 +1,4 @@ -text +alt text diff --git a/verto/tests/assets/image-tag/file_width_value_no_units_html_template.html b/verto/tests/assets/image-tag/file_width_value_no_units_html_template.html index a1343960..6af6c930 100644 --- a/verto/tests/assets/image-tag/file_width_value_no_units_html_template.html +++ b/verto/tests/assets/image-tag/file_width_value_no_units_html_template.html @@ -1,4 +1,4 @@ -alt text

Lorem

- +numbered list

Source

diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 92cf82f9..5cfc39b3 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -85,31 +85,31 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - # unittest.makeSuite(BoxedTextTest), - # unittest.makeSuite(ButtonLinkTest), - # unittest.makeSuite(CommentTest), + unittest.makeSuite(BoxedTextTest), + unittest.makeSuite(ButtonLinkTest), + unittest.makeSuite(CommentTest), unittest.makeSuite(ConditionalTest), - # unittest.makeSuite(FrameTest), - # unittest.makeSuite(GlossaryLinkTest), - # unittest.makeSuite(HeadingTest), + unittest.makeSuite(FrameTest), + unittest.makeSuite(GlossaryLinkTest), + unittest.makeSuite(HeadingTest), unittest.makeSuite(ImageInlineTest), unittest.makeSuite(ImageTagTest), unittest.makeSuite(ImageContainerTest), - # unittest.makeSuite(InteractiveTest), - # unittest.makeSuite(JinjaTest), - # unittest.makeSuite(PanelTest), - # unittest.makeSuite(SaveTitleTest), - # unittest.makeSuite(ScratchTest), - # unittest.makeSuite(ScratchInlineTest), - # unittest.makeSuite(StyleTest), - # unittest.makeSuite(RelativeLinkTest), - # unittest.makeSuite(RemoveTest), - # unittest.makeSuite(RemoveTitleTest), - # unittest.makeSuite(TableOfContentsTest), - # unittest.makeSuite(VideoTest), - - # unittest.makeSuite(HtmlParserTest), - # unittest.makeSuite(MarkdownOverrideTest), + unittest.makeSuite(InteractiveTest), + unittest.makeSuite(JinjaTest), + unittest.makeSuite(PanelTest), + unittest.makeSuite(SaveTitleTest), + unittest.makeSuite(ScratchTest), + unittest.makeSuite(ScratchInlineTest), + unittest.makeSuite(StyleTest), + unittest.makeSuite(RelativeLinkTest), + unittest.makeSuite(RemoveTest), + unittest.makeSuite(RemoveTitleTest), + unittest.makeSuite(TableOfContentsTest), + unittest.makeSuite(VideoTest), + + unittest.makeSuite(HtmlParserTest), + unittest.makeSuite(MarkdownOverrideTest), )) From a6f748a429e3af81758c3602e7231802b732b541 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 7 May 2018 18:52:56 +1200 Subject: [PATCH 20/73] Getting deeper and deeper into the black hole... --- verto/processor-info.json | 4 +- verto/processors/GenericTagBlockProcessor.py | 3 + verto/processors/ImageTagBlockProcessor.py | 1 + verto/processors/utils.py | 13 + verto/tests/ConfigurationTest.py | 629 ++++++++-------- verto/tests/ImageTagTest.py | 710 +++++++++--------- .../assets/configuration/all_processors.md | 4 +- .../all_processors_expected.html | 4 +- verto/tests/assets/configuration/test.md | 7 + .../assets/configuration/test_expected.html | 9 + verto/tests/start_tests.py | 46 +- 11 files changed, 739 insertions(+), 691 deletions(-) create mode 100644 verto/tests/assets/configuration/test.md create mode 100644 verto/tests/assets/configuration/test_expected.html diff --git a/verto/processor-info.json b/verto/processor-info.json index 25216562..a592e1aa 100644 --- a/verto/processor-info.json +++ b/verto/processor-info.json @@ -207,7 +207,7 @@ "dependencies": [] }, "alt": { - "required": false, + "required": true, "dependencies": [] }, "caption": { @@ -281,7 +281,7 @@ "dependencies": [] }, "alt": { - "required": false, + "required": true, "dependencies": [] }, "caption": { diff --git a/verto/processors/GenericTagBlockProcessor.py b/verto/processors/GenericTagBlockProcessor.py index ff8587d6..342d3de2 100644 --- a/verto/processors/GenericTagBlockProcessor.py +++ b/verto/processors/GenericTagBlockProcessor.py @@ -57,7 +57,10 @@ def run(self, parent, blocks): if after.strip() != '': blocks.insert(0, after) + # print(match.group('args')) + print('here') argument_values = parse_arguments(self.processor, match.group('args'), self.arguments) + print(argument_values) extra_args = self.custom_parsing(argument_values) argument_values.update(extra_args) diff --git a/verto/processors/ImageTagBlockProcessor.py b/verto/processors/ImageTagBlockProcessor.py index bee194d8..c19db29d 100644 --- a/verto/processors/ImageTagBlockProcessor.py +++ b/verto/processors/ImageTagBlockProcessor.py @@ -42,6 +42,7 @@ def custom_parsing(self, argument_values): Returns: extra_args (dict): dictionary to update the agument_values dict. ''' + print('cats') extra_args = {} argument = 'caption' diff --git a/verto/processors/utils.py b/verto/processors/utils.py index dc948999..689f5b91 100644 --- a/verto/processors/utils.py +++ b/verto/processors/utils.py @@ -44,9 +44,14 @@ def parse_flag(argument_key, arguments, default=False): Returns: True if argument is found, otherwise None. ''' + print() + print(argument_key) + # print(arguments) result = re.search(r'(^|\s+){}($|\s)'.format(argument_key), arguments) + print(result) if result: argument_value = True + # print(argument_value) else: argument_value = default return argument_value @@ -68,6 +73,7 @@ def parse_arguments(processor, inputs, arguments): ''' argument_values = defaultdict(None) for argument, argument_info in arguments.items(): + # print(argument) is_required = argument_info['required'] is_arg = parse_argument(argument, inputs, None) is not None is_flag = parse_flag(argument, inputs) @@ -106,12 +112,19 @@ def process_parameters(ext, processor, parameters, argument_values): Returns: A dictionary of parameter to converted values. ''' + # for i in parameters: + # print(i) + # print() + # for i in argument_values: + # print(i) + # print() context = dict() transformations = OrderedDict() for parameter, parameter_info in parameters.items(): argument_name = parameter_info['argument'] parameter_default = parameter_info.get('default', None) argument_value = argument_values.get(argument_name, parameter_default) + # print(argument_name, argument_value) parameter_value = argument_value if parameter_info.get('transform', None): diff --git a/verto/tests/ConfigurationTest.py b/verto/tests/ConfigurationTest.py index ceed0c44..befbea1d 100644 --- a/verto/tests/ConfigurationTest.py +++ b/verto/tests/ConfigurationTest.py @@ -23,340 +23,355 @@ def __init__(self, *args, **kwargs): self.test_name = 'configuration' self.maxDiff = None self.custom_templates = { - 'image': '', + 'image': '\'test\'', 'boxed-text': '
{% autoescape false %}{{ text }}{% endautoescape %}
', 'video-youtube': 'https://www.youtube.com/embed/{{ identifier }}?rel=0' } - def test_multiple_calls(self): - '''Checks all fields of VertoResult are correct for multiple Verto calls. - ''' - test_cases = [( - 'all_processors.md', - VertoResult( - html_string=self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True), - title='Example Title', - required_files={ - 'interactives': { - 'binary-cards' - }, - 'images': set(), - 'page_scripts': set(), - 'scratch_images': { - ScratchImageMetaData( - hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', - text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' - ), - } - }, - heading_tree=( - HeadingNode( - title='Example Title', - title_slug='example-title', - level=1, - children=(), - ), - HeadingNode( - title='Example Title 2', - title_slug='example-title-2', - level=1, - children=() - ), - ), - required_glossary_terms={ - 'algorithm': [] - } - ) - ), ( - 'some_processors.md', - VertoResult( - html_string=self.read_test_file(self.test_name, 'some_processors_expected.html', strip=True), - title='Another Example Title', - required_files={ - 'interactives': set(), - 'images': {'totally-legit-image.png'}, - 'page_scripts': set(), - 'scratch_images': set() - }, - heading_tree=(HeadingNode( - title='Another Example Title', - title_slug='another-example-title', - level=1, - children=(HeadingNode( - title='This is an H2', - title_slug='this-is-an-h2', - level=2, - children=() - ),), - ),), - required_glossary_terms={ - 'chomsky-hierarchy': - [('Formal languages', 'glossary-chomsky-hierarchy')] - } - ) - ), ( - 'some_processors_2.md', - VertoResult( - html_string=self.read_test_file(self.test_name, 'some_processors_2_expected.html', strip=True), - title='Another Example Title', - required_files={ - 'interactives': set(), - 'images': { - 'totally-legit-image.png', - 'finite-state-automata-no-trap-example.png', - 'finite-state-automata-trap-added-example.png', - 'finite-state-automata-trap-added-extreme-example.png', - }, - 'page_scripts': set(), - 'scratch_images': set() - }, - heading_tree=(HeadingNode( - title='Another Example Title', - title_slug='another-example-title', - level=1, - children=(), - ),), - required_glossary_terms={ - 'hello': [], - 'algorithm': - [('computer program', 'glossary-algorithm'), - ('algorithm cost', 'glossary-algorithm-2'), - ('searching algorithms', 'glossary-algorithm-3'), - ('sorting algorithms', 'glossary-algorithm-4')] - } - ) - )] + # def test_multiple_calls(self): + # '''Checks all fields of VertoResult are correct for multiple Verto calls. + # ''' + # test_cases = [( + # 'all_processors.md', + # VertoResult( + # html_string=self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True), + # title='Example Title', + # required_files={ + # 'interactives': { + # 'binary-cards' + # }, + # 'images': set(), + # 'page_scripts': set(), + # 'scratch_images': { + # ScratchImageMetaData( + # hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', + # text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' + # ), + # } + # }, + # heading_tree=( + # HeadingNode( + # title='Example Title', + # title_slug='example-title', + # level=1, + # children=(), + # ), + # HeadingNode( + # title='Example Title 2', + # title_slug='example-title-2', + # level=1, + # children=() + # ), + # ), + # required_glossary_terms={ + # 'algorithm': [] + # } + # ) + # ), ( + # 'some_processors.md', + # VertoResult( + # html_string=self.read_test_file(self.test_name, 'some_processors_expected.html', strip=True), + # title='Another Example Title', + # required_files={ + # 'interactives': set(), + # 'images': {'totally-legit-image.png'}, + # 'page_scripts': set(), + # 'scratch_images': set() + # }, + # heading_tree=(HeadingNode( + # title='Another Example Title', + # title_slug='another-example-title', + # level=1, + # children=(HeadingNode( + # title='This is an H2', + # title_slug='this-is-an-h2', + # level=2, + # children=() + # ),), + # ),), + # required_glossary_terms={ + # 'chomsky-hierarchy': + # [('Formal languages', 'glossary-chomsky-hierarchy')] + # } + # ) + # ), ( + # 'some_processors_2.md', + # VertoResult( + # html_string=self.read_test_file(self.test_name, 'some_processors_2_expected.html', strip=True), + # title='Another Example Title', + # required_files={ + # 'interactives': set(), + # 'images': { + # 'totally-legit-image.png', + # 'finite-state-automata-no-trap-example.png', + # 'finite-state-automata-trap-added-example.png', + # 'finite-state-automata-trap-added-extreme-example.png', + # }, + # 'page_scripts': set(), + # 'scratch_images': set() + # }, + # heading_tree=(HeadingNode( + # title='Another Example Title', + # title_slug='another-example-title', + # level=1, + # children=(), + # ),), + # required_glossary_terms={ + # 'hello': [], + # 'algorithm': + # [('computer program', 'glossary-algorithm'), + # ('algorithm cost', 'glossary-algorithm-2'), + # ('searching algorithms', 'glossary-algorithm-3'), + # ('sorting algorithms', 'glossary-algorithm-4')] + # } + # ) + # )] - verto = Verto() - for filename, expected_result in test_cases: - test_string = self.read_test_file(self.test_name, filename) - verto_result = verto.convert(test_string) + # verto = Verto() + # for filename, expected_result in test_cases: + # test_string = self.read_test_file(self.test_name, filename) + # verto_result = verto.convert(test_string) - self.assertEqual(verto_result.title, expected_result.title) - self.assertEqual(verto_result.required_files, expected_result.required_files) - self.assertTupleEqual(verto_result.heading_tree, expected_result.heading_tree) - self.assertDictEqual(verto_result.required_glossary_terms, expected_result.required_glossary_terms) - verto.clear_saved_data() + # self.assertEqual(verto_result.title, expected_result.title) + # self.assertEqual(verto_result.required_files, expected_result.required_files) + # self.assertTupleEqual(verto_result.heading_tree, expected_result.heading_tree) + # self.assertDictEqual(verto_result.required_glossary_terms, expected_result.required_glossary_terms) + # verto.clear_saved_data() - def test_multiple_calls_without_clearing(self): - '''Tests that if the verto extension is not cleared that information such as required_files and slugs are persistent. - ''' - filename = 'all_processors.md' - other_filename = 'otherfile.md' - expected_result = VertoResult( - html_string=self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True), - title='Example Title', - required_files={ - 'interactives': { - 'binary-cards' - }, - 'images': set(), - 'page_scripts': set(), - 'scratch_images': { - ScratchImageMetaData( - hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', - text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' - ), - } - }, - heading_tree=( - HeadingNode( - title='Example Title', - title_slug='example-title', - level=1, - children=(), - ), - HeadingNode( - title='Example Title 2', - title_slug='example-title-2', - level=1, - children=() - ), - ), - required_glossary_terms={ - 'algorithm': [] - } - ) - expected_otherfile_result = VertoResult( - html_string=self.read_test_file(self.test_name, 'otherfile_expected.html', strip=True), - title='Example Title', - required_files={ - 'interactives': { - 'binary-cards' - }, - 'images': { - 'pixel-diamond.png' - }, - 'page_scripts': set(), - 'scratch_images': { - ScratchImageMetaData( - hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', - text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' - ), - ScratchImageMetaData( - hash='b78bff524e54a18116e1e898a93e360827f874a8b0b508e1edc47d21516495ad', - text='never\ngoing\nto\ngive\nyou\nup' - ), - } - }, - heading_tree=(HeadingNode( - title='Example Title', - title_slug='example-title-3', - level=1, - children=(), - ), - ), - required_glossary_terms={ - 'algorithm': [] - } - ) + # def test_multiple_calls_without_clearing(self): + # '''Tests that if the verto extension is not cleared that information such as required_files and slugs are persistent. + # ''' + # filename = 'all_processors.md' + # other_filename = 'otherfile.md' + # expected_result = VertoResult( + # html_string=self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True), + # title='Example Title', + # required_files={ + # 'interactives': { + # 'binary-cards' + # }, + # 'images': set(), + # 'page_scripts': set(), + # 'scratch_images': { + # ScratchImageMetaData( + # hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', + # text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' + # ), + # } + # }, + # heading_tree=( + # HeadingNode( + # title='Example Title', + # title_slug='example-title', + # level=1, + # children=(), + # ), + # HeadingNode( + # title='Example Title 2', + # title_slug='example-title-2', + # level=1, + # children=() + # ), + # ), + # required_glossary_terms={ + # 'algorithm': [] + # } + # ) + # expected_otherfile_result = VertoResult( + # html_string=self.read_test_file(self.test_name, 'otherfile_expected.html', strip=True), + # title='Example Title', + # required_files={ + # 'interactives': { + # 'binary-cards' + # }, + # 'images': { + # 'pixel-diamond.png' + # }, + # 'page_scripts': set(), + # 'scratch_images': { + # ScratchImageMetaData( + # hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', + # text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' + # ), + # ScratchImageMetaData( + # hash='b78bff524e54a18116e1e898a93e360827f874a8b0b508e1edc47d21516495ad', + # text='never\ngoing\nto\ngive\nyou\nup' + # ), + # } + # }, + # heading_tree=(HeadingNode( + # title='Example Title', + # title_slug='example-title-3', + # level=1, + # children=(), + # ), + # ), + # required_glossary_terms={ + # 'algorithm': [] + # } + # ) - verto = Verto() - # First file - test_string = self.read_test_file(self.test_name, filename) - verto_result = verto.convert(test_string) + # verto = Verto() + # # First file + # test_string = self.read_test_file(self.test_name, filename) + # verto_result = verto.convert(test_string) - self.assertEqual(verto_result.title, expected_result.title) - self.assertEqual(verto_result.required_files, expected_result.required_files) - self.assertTupleEqual(verto_result.heading_tree, expected_result.heading_tree) - self.assertDictEqual(verto_result.required_glossary_terms, expected_result.required_glossary_terms) + # self.assertEqual(verto_result.title, expected_result.title) + # self.assertEqual(verto_result.required_files, expected_result.required_files) + # self.assertTupleEqual(verto_result.heading_tree, expected_result.heading_tree) + # self.assertDictEqual(verto_result.required_glossary_terms, expected_result.required_glossary_terms) - # Another file - test_string = self.read_test_file(self.test_name, other_filename) - verto_result = verto.convert(test_string) + # # Another file + # test_string = self.read_test_file(self.test_name, other_filename) + # verto_result = verto.convert(test_string) - self.assertEqual(verto_result.title, expected_otherfile_result.title) - self.assertEqual(verto_result.required_files, expected_otherfile_result.required_files) - self.assertTupleEqual(verto_result.heading_tree, expected_otherfile_result.heading_tree) - self.assertDictEqual(verto_result.required_glossary_terms, expected_otherfile_result.required_glossary_terms) + # self.assertEqual(verto_result.title, expected_otherfile_result.title) + # self.assertEqual(verto_result.required_files, expected_otherfile_result.required_files) + # self.assertTupleEqual(verto_result.heading_tree, expected_otherfile_result.heading_tree) + # self.assertDictEqual(verto_result.required_glossary_terms, expected_otherfile_result.required_glossary_terms) - def test_custom_processors_and_custom_templates_on_creation(self): - '''Checks if custom processors and custom templates work together on creation of verto. - ''' - processors = {'image-tag', 'boxed-text'} - verto = Verto(processors=processors, html_templates=self.custom_templates) - test_string = self.read_test_file(self.test_name, 'all_processors.md') - converted_test_string = verto.convert(test_string).html_string - expected_string = self.read_test_file(self.test_name, 'custom_processors_custom_templates_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # def test_custom_processors_and_custom_templates_on_creation(self): + # '''Checks if custom processors and custom templates work together on creation of verto. + # ''' + # processors = {'image-tag', 'boxed-text'} + # verto = Verto(processors=processors, html_templates=self.custom_templates) + # test_string = self.read_test_file(self.test_name, 'all_processors.md') + # converted_test_string = verto.convert(test_string).html_string + # expected_string = self.read_test_file(self.test_name, 'custom_processors_custom_templates_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - def test_custom_processors_and_custom_templates_after_creation(self): - '''Checks if custom processors and custom templates work together after creation of verto. - ''' - processors = {'image-tag', 'boxed-text'} - verto = Verto() - verto.update_processors(processors) - verto.update_templates(self.custom_templates) - test_string = self.read_test_file(self.test_name, 'all_processors.md') - converted_test_string = verto.convert(test_string).html_string - expected_string = self.read_test_file(self.test_name, 'custom_processors_custom_templates_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # def test_custom_processors_and_custom_templates_after_creation(self): + # '''Checks if custom processors and custom templates work together after creation of verto. + # ''' + # processors = {'image-tag', 'boxed-text'} + # verto = Verto() + # verto.update_processors(processors) + # verto.update_templates(self.custom_templates) + # test_string = self.read_test_file(self.test_name, 'all_processors.md') + # converted_test_string = verto.convert(test_string).html_string + # expected_string = self.read_test_file(self.test_name, 'custom_processors_custom_templates_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - def test_default_processors_on_creation(self): - '''Checks if all expected default processors work on default creation. - ''' - verto = Verto() - test_string = self.read_test_file(self.test_name, 'all_processors.md') - converted_test_string = verto.convert(test_string).html_string - expected_string = self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # def test_default_processors_on_creation(self): + # '''Checks if all expected default processors work on default creation. + # ''' + # verto = Verto() + # test_string = self.read_test_file(self.test_name, 'all_processors.md') + # converted_test_string = verto.convert(test_string).html_string + # expected_string = self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - def test_custom_processors_on_creation(self): - '''Checks if system only uses specified processors. - ''' - processors = {'panel', 'image-container'} - verto = Verto(processors=processors) - test_string = self.read_test_file(self.test_name, 'all_processors.md') - converted_test_string = verto.convert(test_string).html_string - expected_string = self.read_test_file(self.test_name, 'custom_processors_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # def test_custom_processors_on_creation(self): + # '''Checks if system only uses specified processors. + # ''' + # processors = {'panel', 'image-container'} + # verto = Verto(processors=processors) + # test_string = self.read_test_file(self.test_name, 'all_processors.md') + # converted_test_string = verto.convert(test_string).html_string + # expected_string = self.read_test_file(self.test_name, 'custom_processors_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - def test_custom_processors_after_creation(self): - '''Checks if extension correct changes processors. - ''' - verto = Verto() - processors = Verto.processor_defaults() - processors.add('example_processor') - processors.remove('comment') - verto.update_processors(processors) - # Check example_processor is now stored in extension processors - self.assertEqual(verto.verto_extension.processors, processors) - # Check comments are now skipped - test_string = self.read_test_file(self.test_name, 'all_processors.md') - converted_test_string = verto.convert(test_string).html_string - expected_string = self.read_test_file(self.test_name, 'all_processors_except_comment_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # def test_custom_processors_after_creation(self): + # '''Checks if extension correct changes processors. + # ''' + # verto = Verto() + # processors = Verto.processor_defaults() + # processors.add('example_processor') + # processors.remove('comment') + # verto.update_processors(processors) + # # Check example_processor is now stored in extension processors + # self.assertEqual(verto.verto_extension.processors, processors) + # # Check comments are now skipped + # test_string = self.read_test_file(self.test_name, 'all_processors.md') + # converted_test_string = verto.convert(test_string).html_string + # expected_string = self.read_test_file(self.test_name, 'all_processors_except_comment_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - def test_unique_custom_processors(self): - '''Checks if unique processors are stored when duplicates provided. - ''' - processors = ['comment', 'comment', 'comment'] - verto = Verto(processors=processors) - self.assertEqual(verto.verto_extension.processors, set(processors)) - processors = list(Verto.processor_defaults()) - processors.append('example_processor') - processors.append('example_processor') - processors.append('example_processor') - verto.update_processors(processors) - self.assertTrue(verto.verto_extension.processors, processors) + # def test_unique_custom_processors(self): + # '''Checks if unique processors are stored when duplicates provided. + # ''' + # processors = ['comment', 'comment', 'comment'] + # verto = Verto(processors=processors) + # self.assertEqual(verto.verto_extension.processors, set(processors)) + # processors = list(Verto.processor_defaults()) + # processors.append('example_processor') + # processors.append('example_processor') + # processors.append('example_processor') + # verto.update_processors(processors) + # self.assertTrue(verto.verto_extension.processors, processors) - def test_custom_templates_on_creation(self): - '''Checks custom templates are used when given on creation. - ''' - verto = Verto(html_templates=self.custom_templates) - test_string = self.read_test_file(self.test_name, 'all_processors.md') - converted_test_string = verto.convert(test_string).html_string - expected_string = self.read_test_file(self.test_name, 'all_processors_custom_html_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # def test_custom_templates_on_creation(self): + # '''Checks custom templates are used when given on creation. + # ''' + # verto = Verto(html_templates=self.custom_templates) + # test_string = self.read_test_file(self.test_name, 'all_processors.md') + # converted_test_string = verto.convert(test_string).html_string + # expected_string = self.read_test_file(self.test_name, 'all_processors_custom_html_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - def test_custom_templates_after_creation(self): - '''Checks custom templates are used when given after creation. - ''' - verto = Verto() - verto.update_templates(self.custom_templates) - test_string = self.read_test_file(self.test_name, 'all_processors.md') - converted_test_string = verto.convert(test_string).html_string - expected_string = self.read_test_file(self.test_name, 'all_processors_custom_html_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # def test_custom_templates_after_creation(self): + # '''Checks custom templates are used when given after creation. + # ''' + # verto = Verto() + # verto.update_templates(self.custom_templates) + # test_string = self.read_test_file(self.test_name, 'all_processors.md') + # converted_test_string = verto.convert(test_string).html_string + # expected_string = self.read_test_file(self.test_name, 'all_processors_custom_html_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - def test_reset_templates_after_custom(self): + # def test_reset_templates_after_custom(self): + # '''Checks custom templates are reset when given at creation. + # ''' + # verto = Verto(html_templates=self.custom_templates) + # verto.clear_templates() + # test_string = self.read_test_file(self.test_name, 'all_processors.md') + # converted_test_string = verto.convert(test_string).html_string + # expected_string = self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + def test_alt(self): '''Checks custom templates are reset when given at creation. ''' - verto = Verto(html_templates=self.custom_templates) + verto = Verto() verto.clear_templates() - test_string = self.read_test_file(self.test_name, 'all_processors.md') + test_string = self.read_test_file(self.test_name, 'test.md') converted_test_string = verto.convert(test_string).html_string - expected_string = self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True) + expected_string = self.read_test_file(self.test_name, 'test_expected.html', strip=True) + print() + print(converted_test_string) + print() + print(expected_string) + print() self.assertEqual(expected_string, converted_test_string) - def test_multiline_custom_templates(self): - '''Checks that multiple multiline custom templates are loaded and used correctly. - ''' - custom_templates = { - 'image': \ -'''
- -
''', + # def test_multiline_custom_templates(self): + # '''Checks that multiple multiline custom templates are loaded and used correctly. + # ''' + # custom_templates = { + # 'image': \ +# '''
+# +#
''', - 'boxed-text': \ -'''
-
-{{ text }} -
-
''', + # 'boxed-text': \ +# '''
+#
+# {{ text }} +#
+#
''', - 'heading': \ -'''<{{ heading_type }} id="{{ title_slug }}"> - -{{ level_1 }}.{{ level_2 }}.{{ level_3 }}.{{ level_4 }}.{{ level_5 }}.{{ level_6 }}. - -{{ title }} -''' + # 'heading': \ +# '''<{{ heading_type }} id="{{ title_slug }}"> +# +# {{ level_1 }}.{{ level_2 }}.{{ level_3 }}.{{ level_4 }}.{{ level_5 }}.{{ level_6 }}. +# +# {{ title }} +# ''' - } + # } - verto = Verto(html_templates=custom_templates) - test_string = self.read_test_file(self.test_name, 'all_processors.md') - converted_test_string = verto.convert(test_string).html_string - expected_string = self.read_test_file(self.test_name, 'multiline_templates_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # verto = Verto(html_templates=custom_templates) + # test_string = self.read_test_file(self.test_name, 'all_processors.md') + # converted_test_string = verto.convert(test_string).html_string + # expected_string = self.read_test_file(self.test_name, 'multiline_templates_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) diff --git a/verto/tests/ImageTagTest.py b/verto/tests/ImageTagTest.py index e1f2b38e..c07f3664 100644 --- a/verto/tests/ImageTagTest.py +++ b/verto/tests/ImageTagTest.py @@ -43,406 +43,406 @@ def test_caption(self): # should not be matched expected_string = self.read_test_file(self.processor_name, 'caption_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - def test_no_caption(self): - '''Tests to ensure that an image with no caption is rendered correctly and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'no_caption.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'no_caption_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'pixel-diamond.png' - } - self.assertSetEqual(expected_images, images) - - def test_caption_false(self): - '''Tests caption argument is ignored when set to false and that expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'caption_false.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'caption_false_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'cats.png' - } - self.assertSetEqual(expected_images, images) - - def test_invalid_caption_parameter(self): - '''Tests that ArgumentValueError is raised when aaption-link argument is give but a caption is not provided. - ''' - test_string = self.read_test_file(self.processor_name, 'invalid_caption_error.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - def test_source_hover_no_caption(self): - '''Tests that multiple arguments are rendered correctly when no caption argument is included and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'source_hover_no_caption.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'source_hover_no_caption_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'finite-state-automata-no-trap-example.png', - 'finite-state-automata-trap-added-example.png' - } - self.assertSetEqual(expected_images, images) - - def test_alt_hover_caption_false(self): - '''Tests that multiple arguments are rendered correctly when caption argument is false and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'alt_hover_caption_false.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'alt_hover_caption_false_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'finite-state-automata-no-trap-example.png', - 'finite-state-automata-trap-added-example.png' - } - self.assertSetEqual(expected_images, images) - - def test_multiple_images_captions_false(self): - '''Tests to ensure that multiple internally reference images produce the desired output and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'multiple_images_captions_false.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'multiple_images_captions_false_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'the-first-image.png', - 'Lipsum.png', - 'pixel-diamond.png' - } - self.assertSetEqual(expected_images, images) - - def test_external_image(self): - '''Tests that external images are processed and that the expected images are unchanged. - ''' - test_string = self.read_test_file(self.processor_name, 'external_image.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'external_image_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - def test_contains_hover_text(self): - '''Tests that argument for hover-text produces expected output and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'contains_hover_text.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'contains_hover_text_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' - } - self.assertSetEqual(expected_images, images) - - def test_missing_alt_parameter(self): - '''Tests that missing alt argument produces correct error. - ''' - test_string = self.read_test_file(self.processor_name, 'missing_alt_parameter.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + # def test_no_caption(self): + # '''Tests to ensure that an image with no caption is rendered correctly and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'no_caption.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'no_caption_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'pixel-diamond.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_caption_false(self): + # '''Tests caption argument is ignored when set to false and that expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'caption_false.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'caption_false_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'cats.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_invalid_caption_parameter(self): + # '''Tests that ArgumentValueError is raised when aaption-link argument is give but a caption is not provided. + # ''' + # test_string = self.read_test_file(self.processor_name, 'invalid_caption_error.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + # def test_source_hover_no_caption(self): + # '''Tests that multiple arguments are rendered correctly when no caption argument is included and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'source_hover_no_caption.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'source_hover_no_caption_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'finite-state-automata-no-trap-example.png', + # 'finite-state-automata-trap-added-example.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_alt_hover_caption_false(self): + # '''Tests that multiple arguments are rendered correctly when caption argument is false and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'alt_hover_caption_false.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'alt_hover_caption_false_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'finite-state-automata-no-trap-example.png', + # 'finite-state-automata-trap-added-example.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_multiple_images_captions_false(self): + # '''Tests to ensure that multiple internally reference images produce the desired output and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'multiple_images_captions_false.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, True, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'multiple_images_captions_false_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'the-first-image.png', + # 'Lipsum.png', + # 'pixel-diamond.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_external_image(self): + # '''Tests that external images are processed and that the expected images are unchanged. + # ''' + # test_string = self.read_test_file(self.processor_name, 'external_image.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'external_image_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # def test_contains_hover_text(self): + # '''Tests that argument for hover-text produces expected output and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'contains_hover_text.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'contains_hover_text_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'computer-studying-turing-test.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_missing_alt_parameter(self): + # '''Tests that missing alt argument produces correct error. + # ''' + # test_string = self.read_test_file(self.processor_name, 'missing_alt_parameter.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + # def test_contains_source(self): + # '''Tests that argument for source produces expected output and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'contains_source.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'contains_source_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'computer-studying-turing-test.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_align_left(self): + # '''Tests that argument for align produces expected output when set to left and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'align_left.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'align_left_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'computer-studying-turing-test.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_align_right(self): + # '''Tests that argument for align produces expected output when set to right and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'align_right.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'align_right_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'computer-studying-turing-test.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_align_center(self): + # '''Tests that argument for align produces expected output when set to center and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'align_center.md') + # blocks = self.to_blocks(test_string) - def test_contains_source(self): - '''Tests that argument for source produces expected output and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'contains_source.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'contains_source_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' - } - self.assertSetEqual(expected_images, images) - - def test_align_left(self): - '''Tests that argument for align produces expected output when set to left and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'align_left.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'align_left_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' - } - self.assertSetEqual(expected_images, images) - - def test_align_right(self): - '''Tests that argument for align produces expected output when set to right and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'align_right.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'align_right_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' - } - self.assertSetEqual(expected_images, images) - - def test_align_center(self): - '''Tests that argument for align produces expected output when set to center and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'align_center.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'align_center_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' - } - self.assertSetEqual(expected_images, images) + # self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'align_center_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - def test_caption_link_error(self): - '''Tests that ArgumentMissingError is raised when caption-link argument is give but a caption is not provided. - ''' - test_string = self.read_test_file(self.processor_name, 'caption_link_error.md') - blocks = self.to_blocks(test_string) + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'computer-studying-turing-test.png' + # } + # self.assertSetEqual(expected_images, images) - self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # def test_caption_link_error(self): + # '''Tests that ArgumentMissingError is raised when caption-link argument is give but a caption is not provided. + # ''' + # test_string = self.read_test_file(self.processor_name, 'caption_link_error.md') + # blocks = self.to_blocks(test_string) - self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - def test_align_undefined_error(self): - '''Tests that ArgumentValueError is raised when undefined align value is given. - ''' - test_string = self.read_test_file(self.processor_name, 'align_undefined_error.md') - blocks = self.to_blocks(test_string) + # self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + # def test_align_undefined_error(self): + # '''Tests that ArgumentValueError is raised when undefined align value is given. + # ''' + # test_string = self.read_test_file(self.processor_name, 'align_undefined_error.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + # def test_image_in_numbered_list(self): + # '''Test image rendered correctly in numbered list. + # ''' + # test_string = self.read_test_file(self.processor_name, 'image_in_numbered_list.md') + # blocks = self.to_blocks(test_string) - def test_image_in_numbered_list(self): - '''Test image rendered correctly in numbered list. - ''' - test_string = self.read_test_file(self.processor_name, 'image_in_numbered_list.md') - blocks = self.to_blocks(test_string) + # self.assertListEqual([False, False, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - self.assertListEqual([False, False, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'image_in_numbered_list_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'image_in_numbered_list_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # def test_image_width_value(self): + # '''Test image rendered correctly with width value. + # ''' + # test_string = self.read_test_file(self.processor_name, 'file_width_value.md') + # blocks = self.to_blocks(test_string) - def test_image_width_value(self): - '''Test image rendered correctly with width value. - ''' - test_string = self.read_test_file(self.processor_name, 'file_width_value.md') - blocks = self.to_blocks(test_string) + # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # html_template = self.read_test_file(self.processor_name, 'file_width_value_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - html_template = self.read_test_file(self.processor_name, 'file_width_value_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'file_width_value_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'file_width_value_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) + + # def test_image_width_value_no_units(self): + # '''Test image rendered correctly with width value with no units. + # ''' + # test_string = self.read_test_file(self.processor_name, 'file_width_value_no_units.md') + # blocks = self.to_blocks(test_string) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - def test_image_width_value_no_units(self): - '''Test image rendered correctly with width value with no units. - ''' - test_string = self.read_test_file(self.processor_name, 'file_width_value_no_units.md') - blocks = self.to_blocks(test_string) + # html_template = self.read_test_file(self.processor_name, 'file_width_value_no_units_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'file_width_value_no_units_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - html_template = self.read_test_file(self.processor_name, 'file_width_value_no_units_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'file_width_value_no_units_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # def test_image_invalid_width_value_1(self): + # '''Test image rendered correctly with width value. + # ''' + # test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1.md') + # blocks = self.to_blocks(test_string) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - def test_image_invalid_width_value_1(self): - '''Test image rendered correctly with width value. - ''' - test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1.md') - blocks = self.to_blocks(test_string) + # html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) - html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # def test_image_invalid_width_value_2(self): + # '''Test image rendered correctly with width value. + # ''' + # test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2.md') + # blocks = self.to_blocks(test_string) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - def test_image_invalid_width_value_2(self): - '''Test image rendered correctly with width value. - ''' - test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2.md') - blocks = self.to_blocks(test_string) + # html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # def test_image_width_value_external_image(self): + # '''Test image rendered correctly with width value. + # ''' + # test_string = self.read_test_file(self.processor_name, 'file_width_value_external_image.md') + # blocks = self.to_blocks(test_string) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - def test_image_width_value_external_image(self): - '''Test image rendered correctly with width value. - ''' - test_string = self.read_test_file(self.processor_name, 'file_width_value_external_image.md') - blocks = self.to_blocks(test_string) + # html_template = self.read_test_file(self.processor_name, 'file_width_value_external_image_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'file_width_value_external_image_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - html_template = self.read_test_file(self.processor_name, 'file_width_value_external_image_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'file_width_value_external_image_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # #~ + # # Doc Tests + # #~ - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # def test_doc_example_basic(self): + # '''Basic example of common usage. + # ''' + # test_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage.md') + # blocks = self.to_blocks(test_string) - #~ - # Doc Tests - #~ + # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - def test_doc_example_basic(self): - '''Basic example of common usage. - ''' - test_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage.md') - blocks = self.to_blocks(test_string) + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # def test_doc_example_override_html(self): + # '''Basic example showing how to override the html-template. + # ''' + # test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') + # blocks = self.to_blocks(test_string) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - def test_doc_example_override_html(self): - '''Basic example showing how to override the html-template. - ''' - test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) - def test_doc_example_2_override_html(self): - '''Basic example showing how to override the html-template for relative files in a specific file only. - ''' - test_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html.md') - blocks = self.to_blocks(test_string) + # def test_doc_example_2_override_html(self): + # '''Basic example showing how to override the html-template for relative files in a specific file only. + # ''' + # test_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html.md') + # blocks = self.to_blocks(test_string) - self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - html_template = self.read_test_file(self.processor_name, 'doc_example_2_override_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # html_template = self.read_test_file(self.processor_name, 'doc_example_2_override_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) diff --git a/verto/tests/assets/configuration/all_processors.md b/verto/tests/assets/configuration/all_processors.md index da73b7b5..9165b86e 100644 --- a/verto/tests/assets/configuration/all_processors.md +++ b/verto/tests/assets/configuration/all_processors.md @@ -18,13 +18,13 @@ This text is the panel's contents. {panel end} -{image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left"} +{image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left" alt="This is alt text"} Dancing with our hands tied. {image end} -{image file-path="http://placehold.it/250x50" caption="false" source="https://placehold.it/" hover-text="This is hover text" alignment="left"} +{image file-path="http://placehold.it/250x50" caption="false" source="https://placehold.it/" hover-text="This is hover text" alignment="left" alt="This is alt text"} {boxed-text} diff --git a/verto/tests/assets/configuration/all_processors_expected.html b/verto/tests/assets/configuration/all_processors_expected.html index 69e12543..df3a7494 100644 --- a/verto/tests/assets/configuration/all_processors_expected.html +++ b/verto/tests/assets/configuration/all_processors_expected.html @@ -21,12 +21,12 @@

- +This is alt text

Dancing with our hands tied.

Source

- +This is alt text

Source

diff --git a/verto/tests/assets/configuration/test.md b/verto/tests/assets/configuration/test.md new file mode 100644 index 00000000..ab8d2178 --- /dev/null +++ b/verto/tests/assets/configuration/test.md @@ -0,0 +1,7 @@ +{image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left" alt="This is alt text"} + +Dancing with our hands tied. + +{image end} + +{image file-path="http://placehold.it/250x50" caption="false" source="https://placehold.it/" hover-text="This is hover text" alignment="left" alt="This is alt text"} diff --git a/verto/tests/assets/configuration/test_expected.html b/verto/tests/assets/configuration/test_expected.html new file mode 100644 index 00000000..4f34df4e --- /dev/null +++ b/verto/tests/assets/configuration/test_expected.html @@ -0,0 +1,9 @@ +
+This is alt text +

Dancing with our hands tied.

+

Source

+
+
+This is alt text +

Source

+
diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 5cfc39b3..42483421 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -85,31 +85,31 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - unittest.makeSuite(BoxedTextTest), - unittest.makeSuite(ButtonLinkTest), + # unittest.makeSuite(BoxedTextTest), + # unittest.makeSuite(ButtonLinkTest), unittest.makeSuite(CommentTest), - unittest.makeSuite(ConditionalTest), - unittest.makeSuite(FrameTest), - unittest.makeSuite(GlossaryLinkTest), - unittest.makeSuite(HeadingTest), - unittest.makeSuite(ImageInlineTest), + # unittest.makeSuite(ConditionalTest), + # unittest.makeSuite(FrameTest), + # unittest.makeSuite(GlossaryLinkTest), + # unittest.makeSuite(HeadingTest), + # unittest.makeSuite(ImageInlineTest), unittest.makeSuite(ImageTagTest), - unittest.makeSuite(ImageContainerTest), - unittest.makeSuite(InteractiveTest), - unittest.makeSuite(JinjaTest), - unittest.makeSuite(PanelTest), - unittest.makeSuite(SaveTitleTest), - unittest.makeSuite(ScratchTest), - unittest.makeSuite(ScratchInlineTest), - unittest.makeSuite(StyleTest), - unittest.makeSuite(RelativeLinkTest), - unittest.makeSuite(RemoveTest), - unittest.makeSuite(RemoveTitleTest), - unittest.makeSuite(TableOfContentsTest), - unittest.makeSuite(VideoTest), - - unittest.makeSuite(HtmlParserTest), - unittest.makeSuite(MarkdownOverrideTest), + # unittest.makeSuite(ImageContainerTest), + # unittest.makeSuite(InteractiveTest), + # unittest.makeSuite(JinjaTest), + # unittest.makeSuite(PanelTest), + # unittest.makeSuite(SaveTitleTest), + # unittest.makeSuite(ScratchTest), + # unittest.makeSuite(ScratchInlineTest), + # unittest.makeSuite(StyleTest), + # unittest.makeSuite(RelativeLinkTest), + # unittest.makeSuite(RemoveTest), + # unittest.makeSuite(RemoveTitleTest), + # unittest.makeSuite(TableOfContentsTest), + # unittest.makeSuite(VideoTest), + + # unittest.makeSuite(HtmlParserTest), + # unittest.makeSuite(MarkdownOverrideTest), )) From 3c0398459fc4d2bd176bd1eddd0b2681f8a32b50 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 8 May 2018 11:47:16 +1200 Subject: [PATCH 21/73] Added optional type parameter to boxed text Complete with tests --- verto/html-templates/boxed-text.html | 2 +- verto/processor-info.json | 8 ++++++ verto/tests/BoxedTextTest.py | 27 +++++++++++++++++++ .../assets/boxed-text/boxed_text_type.md | 7 +++++ .../boxed-text/boxed_text_type_expected.html | 4 +++ .../boxed-text/indented_type_boxed_text.md | 5 ++++ .../indented_type_boxed_text_expected.html | 3 +++ .../assets/boxed-text/multiple_boxed_text.md | 2 +- .../multiple_boxed_text_expected.html | 2 +- 9 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 verto/tests/assets/boxed-text/boxed_text_type.md create mode 100644 verto/tests/assets/boxed-text/boxed_text_type_expected.html create mode 100644 verto/tests/assets/boxed-text/indented_type_boxed_text.md create mode 100644 verto/tests/assets/boxed-text/indented_type_boxed_text_expected.html diff --git a/verto/html-templates/boxed-text.html b/verto/html-templates/boxed-text.html index 12e4bb64..2d3d5699 100644 --- a/verto/html-templates/boxed-text.html +++ b/verto/html-templates/boxed-text.html @@ -1,4 +1,4 @@ -
+
{% autoescape false -%} {{ text }} {% endautoescape -%} diff --git a/verto/processor-info.json b/verto/processor-info.json index b47faaee..0ae8f160 100644 --- a/verto/processor-info.json +++ b/verto/processor-info.json @@ -6,6 +6,10 @@ "required": false, "dependencies": [], "values": ["yes", "no"] + }, + "type": { + "required": false, + "dependencies": [] } }, "template_name": "boxed-text", @@ -17,6 +21,10 @@ "text": { "argument": "content", "transform": null + }, + "type": { + "argument": "type", + "transform": "str.lower" } } }, diff --git a/verto/tests/BoxedTextTest.py b/verto/tests/BoxedTextTest.py index b59a16ca..40345e96 100644 --- a/verto/tests/BoxedTextTest.py +++ b/verto/tests/BoxedTextTest.py @@ -49,6 +49,19 @@ def test_single_boxed_text(self): expected_string = self.read_test_file(self.processor_name, 'single_boxed_text_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) + def test_boxed_text_type(self): + '''Tests that, when specified, type is added to class + ''' + test_string = self.read_test_file(self.processor_name, 'boxed_text_type.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'boxed_text_type_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_indented_boxed_text(self): '''Tests that the indented argument works as appropriate. ''' @@ -61,6 +74,18 @@ def test_indented_boxed_text(self): expected_string = self.read_test_file(self.processor_name, 'indented_boxed_text_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) + def test_indented_and_type_boxed_text(self): + '''Tests that the indented and type arguments work as expected when both used. + ''' + test_string = self.read_test_file(self.processor_name, 'indented_type_boxed_text.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'indented_type_boxed_text_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + def test_multiple_boxed_text(self): '''Tests that multiple different matches (that are not within others) are matched and processed correctly. @@ -88,6 +113,8 @@ def test_recursive_boxed_text(self): expected_string = self.read_test_file(self.processor_name, 'recursive_boxed_text_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) + + #~ # Doc Tests #~ diff --git a/verto/tests/assets/boxed-text/boxed_text_type.md b/verto/tests/assets/boxed-text/boxed_text_type.md new file mode 100644 index 00000000..bb5fe6ff --- /dev/null +++ b/verto/tests/assets/boxed-text/boxed_text_type.md @@ -0,0 +1,7 @@ +{boxed-text type="quote"} + +This text is displayed using a Bootstrap 4 card. + +Where some more text might exist. + +{boxed-text end} diff --git a/verto/tests/assets/boxed-text/boxed_text_type_expected.html b/verto/tests/assets/boxed-text/boxed_text_type_expected.html new file mode 100644 index 00000000..22ecc381 --- /dev/null +++ b/verto/tests/assets/boxed-text/boxed_text_type_expected.html @@ -0,0 +1,4 @@ +
+

This text is displayed using a Bootstrap 4 card.

+

Where some more text might exist.

+
diff --git a/verto/tests/assets/boxed-text/indented_type_boxed_text.md b/verto/tests/assets/boxed-text/indented_type_boxed_text.md new file mode 100644 index 00000000..c3ddbe57 --- /dev/null +++ b/verto/tests/assets/boxed-text/indented_type_boxed_text.md @@ -0,0 +1,5 @@ +{boxed-text indented="yes" type="cats"} + +This text is displayed using a Bootstrap 4 card. + +{boxed-text end} diff --git a/verto/tests/assets/boxed-text/indented_type_boxed_text_expected.html b/verto/tests/assets/boxed-text/indented_type_boxed_text_expected.html new file mode 100644 index 00000000..b19d7440 --- /dev/null +++ b/verto/tests/assets/boxed-text/indented_type_boxed_text_expected.html @@ -0,0 +1,3 @@ +
+

This text is displayed using a Bootstrap 4 card.

+
diff --git a/verto/tests/assets/boxed-text/multiple_boxed_text.md b/verto/tests/assets/boxed-text/multiple_boxed_text.md index be8ba40f..28b06d95 100644 --- a/verto/tests/assets/boxed-text/multiple_boxed_text.md +++ b/verto/tests/assets/boxed-text/multiple_boxed_text.md @@ -6,7 +6,7 @@ This text is displayed using a Bootstrap 4 card. Aenean turpis diam, dictum nec odio ut, porta luctus nunc. Donec vulputate eu magna non finibus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam finibus lectus non lorem consectetur, id sollicitudin est tristique. Nulla in ultricies lectus, nec dapibus ante. Ut ullamcorper orci tincidunt ex mollis rutrum. Nam dapibus diam eu orci laoreet, et egestas quam consectetur. Vestibulum ligula leo, iaculis ac commodo lobortis, posuere ac dui. Aliquam egestas odio congue tempus cursus. Donec dictum dui facilisis enim molestie venenatis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. -{boxed-text} +{boxed-text type="cats"} Lorem ipsum dolor sit amet, consectetur adipiscing elit. In fermentum sit amet metus at congue. Fusce nec mauris accumsan, consequat mi ut, scelerisque erat. In hac habitasse platea dictumst. Phasellus maximus semper blandit. Nam consequat justo eget orci ultricies convallis. Praesent tempus sodales ipsum. Suspendisse faucibus quam vitae mollis rutrum. Fusce sit amet lacus sit amet arcu lobortis suscipit a vel nulla. diff --git a/verto/tests/assets/boxed-text/multiple_boxed_text_expected.html b/verto/tests/assets/boxed-text/multiple_boxed_text_expected.html index 2dbeb661..9d7bfc5f 100644 --- a/verto/tests/assets/boxed-text/multiple_boxed_text_expected.html +++ b/verto/tests/assets/boxed-text/multiple_boxed_text_expected.html @@ -2,7 +2,7 @@

This text is displayed using a Bootstrap 4 card.

Aenean turpis diam, dictum nec odio ut, porta luctus nunc. Donec vulputate eu magna non finibus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam finibus lectus non lorem consectetur, id sollicitudin est tristique. Nulla in ultricies lectus, nec dapibus ante. Ut ullamcorper orci tincidunt ex mollis rutrum. Nam dapibus diam eu orci laoreet, et egestas quam consectetur. Vestibulum ligula leo, iaculis ac commodo lobortis, posuere ac dui. Aliquam egestas odio congue tempus cursus. Donec dictum dui facilisis enim molestie venenatis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.

-
+

Lorem ipsum dolor sit amet, consectetur adipiscing elit. In fermentum sit amet metus at congue. Fusce nec mauris accumsan, consequat mi ut, scelerisque erat. In hac habitasse platea dictumst. Phasellus maximus semper blandit. Nam consequat justo eget orci ultricies convallis. Praesent tempus sodales ipsum. Suspendisse faucibus quam vitae mollis rutrum. Fusce sit amet lacus sit amet arcu lobortis suscipit a vel nulla.

Mauris vestibulum vestibulum neque a mollis. Curabitur ut urna eleifend urna eleifend mollis. Aliquam malesuada luctus purus, eu maximus elit finibus sed. Ut consectetur tempus tempus. Etiam lacinia at mauris eu sagittis. Donec ante urna, semper id aliquam id.

From a852f178ce4c3f4c775f8f04052e14d0f6c8a5af Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 8 May 2018 13:26:06 +1200 Subject: [PATCH 22/73] Figured out the bug! Fix is a WIP --- verto/processors/GenericTagBlockProcessor.py | 1 - verto/processors/ImageTagBlockProcessor.py | 1 - verto/processors/utils.py | 18 +++++++++++++----- verto/tests/assets/configuration/test.md | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/verto/processors/GenericTagBlockProcessor.py b/verto/processors/GenericTagBlockProcessor.py index 342d3de2..fd92676e 100644 --- a/verto/processors/GenericTagBlockProcessor.py +++ b/verto/processors/GenericTagBlockProcessor.py @@ -60,7 +60,6 @@ def run(self, parent, blocks): # print(match.group('args')) print('here') argument_values = parse_arguments(self.processor, match.group('args'), self.arguments) - print(argument_values) extra_args = self.custom_parsing(argument_values) argument_values.update(extra_args) diff --git a/verto/processors/ImageTagBlockProcessor.py b/verto/processors/ImageTagBlockProcessor.py index c19db29d..bee194d8 100644 --- a/verto/processors/ImageTagBlockProcessor.py +++ b/verto/processors/ImageTagBlockProcessor.py @@ -42,7 +42,6 @@ def custom_parsing(self, argument_values): Returns: extra_args (dict): dictionary to update the agument_values dict. ''' - print('cats') extra_args = {} argument = 'caption' diff --git a/verto/processors/utils.py b/verto/processors/utils.py index 689f5b91..90b162fd 100644 --- a/verto/processors/utils.py +++ b/verto/processors/utils.py @@ -46,12 +46,14 @@ def parse_flag(argument_key, arguments, default=False): ''' print() print(argument_key) - # print(arguments) - result = re.search(r'(^|\s+){}($|\s)'.format(argument_key), arguments) - print(result) + print(arguments) + # result = re.search(r'(^|\s+){}($|\s)'.format(argument_key), arguments) + # result = re.search(r'(^|\s+){}(=".*?")'.format(argument_key), arguments) + test = re.compile(r'(^|\s+){0}(=".*?")'.format(argument_key)) + print(test) + result = test.search(arguments) if result: argument_value = True - # print(argument_value) else: argument_value = default return argument_value @@ -71,12 +73,18 @@ def parse_arguments(processor, inputs, arguments): ArgumentMissingError: If any required arguments are missing or an argument an optional argument is dependent on is missing. ''' + print() + print('parse_arguments') argument_values = defaultdict(None) for argument, argument_info in arguments.items(): - # print(argument) + print(argument, end=" ") is_required = argument_info['required'] + print(is_required, end=' ') is_arg = parse_argument(argument, inputs, None) is not None + print(is_arg, end=' ') is_flag = parse_flag(argument, inputs) + print(is_flag) + print() if is_required and not (is_arg or is_flag): raise ArgumentMissingError(processor, argument, '{} is a required argument.'.format(argument)) diff --git a/verto/tests/assets/configuration/test.md b/verto/tests/assets/configuration/test.md index ab8d2178..c44b6348 100644 --- a/verto/tests/assets/configuration/test.md +++ b/verto/tests/assets/configuration/test.md @@ -1,4 +1,4 @@ -{image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left" alt="This is alt text"} +{image file-path="http://placehold.it/350x150" alt="This is alt text" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left"} Dancing with our hands tied. From 2542cf4d4ca021ca07a1597aaf6839d3dffcf0fb Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 8 May 2018 13:40:47 +1200 Subject: [PATCH 23/73] Updated changelog and version number --- docs/source/changelog.rst | 14 ++++++++++++++ verto/__init__.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 99a4f52d..baa8eca7 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -1,6 +1,20 @@ Changelog ####################################### +0.7.4 +======================================= + +- Modify :doc:`processors/interactive` processor to use ``slug`` rather than ``name`` to identify interactives +- Modify :doc:`processors/video` processor template for youtube videos +- Modify :doc:`processors/boxed-text` processor to have optional type parameter +- Update style error message to inclue line numbers +- Dependency updates: + + - Update ``python-slugify`` to 1.2.5. + - Update ``setuptools`` to 39.1.0. + - Update ``sphinx`` to 1.6.6. + - Update ``sphinx_rtx_theme`` to 0.3.0. + 0.7.3 ======================================= diff --git a/verto/__init__.py b/verto/__init__.py index 68cee75f..7a7d10fd 100644 --- a/verto/__init__.py +++ b/verto/__init__.py @@ -1,4 +1,4 @@ # flake8: noqa from .Verto import Verto -__version__ = '0.7.3' +__version__ = '0.7.4' From f4fc6bfa26810ca92d2f438e101e0cb03d231b34 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 8 May 2018 21:06:00 +1200 Subject: [PATCH 24/73] Altered "broken" regex --- verto/processors/utils.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/verto/processors/utils.py b/verto/processors/utils.py index 90b162fd..cd959b24 100644 --- a/verto/processors/utils.py +++ b/verto/processors/utils.py @@ -47,11 +47,8 @@ def parse_flag(argument_key, arguments, default=False): print() print(argument_key) print(arguments) - # result = re.search(r'(^|\s+){}($|\s)'.format(argument_key), arguments) - # result = re.search(r'(^|\s+){}(=".*?")'.format(argument_key), arguments) - test = re.compile(r'(^|\s+){0}(=".*?")'.format(argument_key)) - print(test) - result = test.search(arguments) + result = re.search(r'(^|\s+){}(.+?".*?")'.format(argument_key), arguments) + print(result) if result: argument_value = True else: From 752bb60236f2589dd16e03ea893e9beb222fb00d Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 14 May 2018 12:43:07 +1200 Subject: [PATCH 25/73] Fixed buggy util function, updated configuration tests --- verto/processors/ConditionalProcessor.py | 50 +- verto/processors/GenericTagBlockProcessor.py | 2 - verto/processors/utils.py | 75 +- verto/tests/ConfigurationTest.py | 627 ++++++++-------- verto/tests/ImageTagTest.py | 710 +++++++++--------- .../all_processors_custom_html_expected.html | 2 +- ...ll_processors_except_comment_expected.html | 4 +- ..._processors_custom_templates_expected.html | 4 +- .../custom_processors_expected.html | 4 +- .../assets/configuration/some_processors.md | 2 +- .../assets/configuration/some_processors_2.md | 2 +- .../some_processors_2_expected.html | 2 +- .../some_processors_expected.html | 2 +- verto/tests/assets/configuration/test.md | 7 - .../assets/configuration/test_expected.html | 9 - verto/tests/start_tests.py | 46 +- 16 files changed, 768 insertions(+), 780 deletions(-) delete mode 100644 verto/tests/assets/configuration/test.md delete mode 100644 verto/tests/assets/configuration/test_expected.html diff --git a/verto/processors/ConditionalProcessor.py b/verto/processors/ConditionalProcessor.py index 38b13199..0b285706 100644 --- a/verto/processors/ConditionalProcessor.py +++ b/verto/processors/ConditionalProcessor.py @@ -1,6 +1,6 @@ from markdown.blockprocessors import BlockProcessor from verto.errors.TagNotMatchedError import TagNotMatchedError -from verto.processors.utils import etree, parse_arguments, parse_flag, blocks_to_string +from verto.processors.utils import etree, parse_arguments, blocks_to_string from verto.utils.HtmlParser import HtmlParser from verto.utils.HtmlSerializer import HtmlSerializer from collections import OrderedDict @@ -57,14 +57,20 @@ def run(self, parent, blocks): context = dict() start_tag = self.pattern.search(block) - is_if = parse_flag('if', start_tag.group('args')) + is_if = tag_starts_with('if', start_tag.group('args')) # elif or else before an if conditional if not is_if: - is_elif = parse_flag('elif', start_tag.group('args')) - is_else = parse_flag('else', start_tag.group('args')) - is_end = parse_flag('end', start_tag.group('args')) - string = 'elif' if is_elif else 'else' if is_else else 'end' if is_end else 'unrecognised' + string = '' + if tag_starts_with('elif', start_tag.group('args')): + string = 'elif' + elif tag_starts_with('else', start_tag.group('args')): + string = 'else' + elif tag_starts_with('end', start_tag.group('args')): + 'end' + else: + string='unrecognised' + msg = '{} conditional found before if'.format(string) raise TagNotMatchedError(self.processor, block, msg) @@ -85,7 +91,7 @@ def run(self, parent, blocks): # Process elif statements elifs = OrderedDict() - while next_tag is not None and parse_flag('elif', next_tag.group('args')): + while next_tag is not None and tag_starts_with('elif', next_tag.group('args')): argument_values = parse_arguments(self.processor, next_tag.group('args'), self.arguments) elif_expression = argument_values['condition'] next_tag, block, content_blocks = self.get_content(blocks) @@ -94,7 +100,7 @@ def run(self, parent, blocks): context['elifs'] = elifs # Process else statement - has_else = next_tag is not None and parse_flag('else', next_tag.group('args')) + has_else = next_tag is not None and tag_starts_with('else', next_tag.group('args')) else_content = '' if has_else: argument_values = parse_arguments(self.processor, next_tag.group('args'), self.arguments) @@ -103,7 +109,7 @@ def run(self, parent, blocks): context['has_else'] = has_else context['else_content'] = else_content - if (next_tag is None or (next_tag is not None and not parse_flag('end', next_tag.group('args')))): + if (next_tag is None or (next_tag is not None and not tag_starts_with('end', next_tag.group('args')))): msg = 'end conditional not found' raise TagNotMatchedError(self.processor, block, msg) @@ -143,10 +149,10 @@ def get_content(self, blocks): # Do we have either a start or end tag next_tag = self.pattern.search(block) - is_if = next_tag is not None and parse_flag('if', next_tag.group('args')) - is_elif = next_tag is not None and parse_flag('elif', next_tag.group('args')) - is_else = next_tag is not None and parse_flag('else', next_tag.group('args')) - is_end = next_tag is not None and parse_flag('end', next_tag.group('args')) + is_if = next_tag is not None and tag_starts_with('if', next_tag.group('args')) + is_elif = next_tag is not None and tag_starts_with('elif', next_tag.group('args')) + is_else = next_tag is not None and tag_starts_with('else', next_tag.group('args')) + is_end = next_tag is not None and tag_starts_with('end', next_tag.group('args')) # Keep track of how many inner boxed-text start tags we have seen if is_if: @@ -189,3 +195,21 @@ def parse_blocks(self, blocks): for child in content_tree: content += HtmlSerializer.tostring(child) return content + + +def tag_starts_with(argument_key, arguments, default=False): + '''Search for the given argument in a string of all arguments, + treating the argument as a flag only. + + Args: + argument_key: the name of the argument. + arguments: a string of the argument inputs. + default: the default value if not found. + Returns: + True if argument is found, otherwise None. + ''' + result = re.search(r'(^|\s+){}($|\s)'.format(argument_key), arguments) + if result: + return True + else: + return default diff --git a/verto/processors/GenericTagBlockProcessor.py b/verto/processors/GenericTagBlockProcessor.py index fd92676e..ff8587d6 100644 --- a/verto/processors/GenericTagBlockProcessor.py +++ b/verto/processors/GenericTagBlockProcessor.py @@ -57,8 +57,6 @@ def run(self, parent, blocks): if after.strip() != '': blocks.insert(0, after) - # print(match.group('args')) - print('here') argument_values = parse_arguments(self.processor, match.group('args'), self.arguments) extra_args = self.custom_parsing(argument_values) diff --git a/verto/processors/utils.py b/verto/processors/utils.py index cd959b24..23e4c591 100644 --- a/verto/processors/utils.py +++ b/verto/processors/utils.py @@ -17,7 +17,7 @@ def parse_argument(argument_key, arguments, default=None): Value of an argument as a string if found, otherwise None. ''' is_argument = re.search(r'(^|\s+){}='.format(argument_key), arguments) - if not is_argument: + if not is_argument: # if not found in string, return default return default result = re.match(r'(^|\s+){}="([^"]*("(?<=\\")[^"]*)*)"'.format(argument_key), arguments[is_argument.start():]) @@ -28,32 +28,46 @@ def parse_argument(argument_key, arguments, default=None): if result: argument_value = result.group(2).replace(r'\"', r'"') + return argument_value else: - argument_value = default - return argument_value + return default def parse_flag(argument_key, arguments, default=False): - '''Search for the given argument in a string of all arguments, + '''search for the given argument in a string of all arguments, treating the argument as a flag only. - Args: - argument_key: The name of the argument. - arguments: A string of the argument inputs. - default: The default value if not found. - Returns: - True if argument is found, otherwise None. + args: + argument_key: the name of the argument. + arguments: a string of the argument inputs. + default: the default value if not found. + returns: + true if argument is found, otherwise none. ''' - print() - print(argument_key) - print(arguments) result = re.search(r'(^|\s+){}(.+?".*?")'.format(argument_key), arguments) - print(result) + # result = re.search(r'(^|\s+){}($|\s)'.format(argument_key), arguments) if result: - argument_value = True + return True else: - argument_value = default - return argument_value + return default + +def tag_starts_with(argument_key, arguments, default=False): + '''search for the given argument in a string of all arguments, + treating the argument as a flag only. + + args: + argument_key: the name of the argument. + arguments: a string of the argument inputs. + default: the default value if not found. + returns: + true if argument is found, otherwise none. + ''' + # result = re.search(r'(^|\s+){}(.+?".*?")'.format(argument_key), arguments) + result = re.search(r'(^|\s+){}($|\s)'.format(argument_key), arguments) + if result: + return True + else: + return default def parse_arguments(processor, inputs, arguments): @@ -70,22 +84,14 @@ def parse_arguments(processor, inputs, arguments): ArgumentMissingError: If any required arguments are missing or an argument an optional argument is dependent on is missing. ''' - print() - print('parse_arguments') argument_values = defaultdict(None) for argument, argument_info in arguments.items(): - print(argument, end=" ") is_required = argument_info['required'] - print(is_required, end=' ') - is_arg = parse_argument(argument, inputs, None) is not None - print(is_arg, end=' ') - is_flag = parse_flag(argument, inputs) - print(is_flag) - print() - - if is_required and not (is_arg or is_flag): + is_arg = parse_argument(argument, inputs, None) is not None # true when argument is found + + if is_required and not is_arg: raise ArgumentMissingError(processor, argument, '{} is a required argument.'.format(argument)) - elif not is_required and (is_arg or is_flag): + elif not is_required and is_arg: dependencies = argument_info.get('dependencies', []) for other_argument in dependencies: if (parse_argument(other_argument, inputs, None) is None and @@ -93,9 +99,7 @@ def parse_arguments(processor, inputs, arguments): message = '{} is a required argument because {} exists.'.format(other_argument, argument) raise ArgumentMissingError(processor, argument, message) - if is_flag: - argument_values[argument] = True - elif is_arg: + if is_arg: value = parse_argument(argument, inputs, None) if value and value.strip() == '': message = '{} cannot be blank.'.format(argument) @@ -117,19 +121,12 @@ def process_parameters(ext, processor, parameters, argument_values): Returns: A dictionary of parameter to converted values. ''' - # for i in parameters: - # print(i) - # print() - # for i in argument_values: - # print(i) - # print() context = dict() transformations = OrderedDict() for parameter, parameter_info in parameters.items(): argument_name = parameter_info['argument'] parameter_default = parameter_info.get('default', None) argument_value = argument_values.get(argument_name, parameter_default) - # print(argument_name, argument_value) parameter_value = argument_value if parameter_info.get('transform', None): diff --git a/verto/tests/ConfigurationTest.py b/verto/tests/ConfigurationTest.py index befbea1d..1c452a41 100644 --- a/verto/tests/ConfigurationTest.py +++ b/verto/tests/ConfigurationTest.py @@ -28,350 +28,335 @@ def __init__(self, *args, **kwargs): 'video-youtube': 'https://www.youtube.com/embed/{{ identifier }}?rel=0' } - # def test_multiple_calls(self): - # '''Checks all fields of VertoResult are correct for multiple Verto calls. - # ''' - # test_cases = [( - # 'all_processors.md', - # VertoResult( - # html_string=self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True), - # title='Example Title', - # required_files={ - # 'interactives': { - # 'binary-cards' - # }, - # 'images': set(), - # 'page_scripts': set(), - # 'scratch_images': { - # ScratchImageMetaData( - # hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', - # text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' - # ), - # } - # }, - # heading_tree=( - # HeadingNode( - # title='Example Title', - # title_slug='example-title', - # level=1, - # children=(), - # ), - # HeadingNode( - # title='Example Title 2', - # title_slug='example-title-2', - # level=1, - # children=() - # ), - # ), - # required_glossary_terms={ - # 'algorithm': [] - # } - # ) - # ), ( - # 'some_processors.md', - # VertoResult( - # html_string=self.read_test_file(self.test_name, 'some_processors_expected.html', strip=True), - # title='Another Example Title', - # required_files={ - # 'interactives': set(), - # 'images': {'totally-legit-image.png'}, - # 'page_scripts': set(), - # 'scratch_images': set() - # }, - # heading_tree=(HeadingNode( - # title='Another Example Title', - # title_slug='another-example-title', - # level=1, - # children=(HeadingNode( - # title='This is an H2', - # title_slug='this-is-an-h2', - # level=2, - # children=() - # ),), - # ),), - # required_glossary_terms={ - # 'chomsky-hierarchy': - # [('Formal languages', 'glossary-chomsky-hierarchy')] - # } - # ) - # ), ( - # 'some_processors_2.md', - # VertoResult( - # html_string=self.read_test_file(self.test_name, 'some_processors_2_expected.html', strip=True), - # title='Another Example Title', - # required_files={ - # 'interactives': set(), - # 'images': { - # 'totally-legit-image.png', - # 'finite-state-automata-no-trap-example.png', - # 'finite-state-automata-trap-added-example.png', - # 'finite-state-automata-trap-added-extreme-example.png', - # }, - # 'page_scripts': set(), - # 'scratch_images': set() - # }, - # heading_tree=(HeadingNode( - # title='Another Example Title', - # title_slug='another-example-title', - # level=1, - # children=(), - # ),), - # required_glossary_terms={ - # 'hello': [], - # 'algorithm': - # [('computer program', 'glossary-algorithm'), - # ('algorithm cost', 'glossary-algorithm-2'), - # ('searching algorithms', 'glossary-algorithm-3'), - # ('sorting algorithms', 'glossary-algorithm-4')] - # } - # ) - # )] - - # verto = Verto() - # for filename, expected_result in test_cases: - # test_string = self.read_test_file(self.test_name, filename) - # verto_result = verto.convert(test_string) + def test_multiple_calls(self): + '''Checks all fields of VertoResult are correct for multiple Verto calls. + ''' + test_cases = [( + 'all_processors.md', + VertoResult( + html_string=self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True), + title='Example Title', + required_files={ + 'interactives': { + 'binary-cards' + }, + 'images': set(), + 'page_scripts': set(), + 'scratch_images': { + ScratchImageMetaData( + hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', + text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' + ), + } + }, + heading_tree=( + HeadingNode( + title='Example Title', + title_slug='example-title', + level=1, + children=(), + ), + HeadingNode( + title='Example Title 2', + title_slug='example-title-2', + level=1, + children=() + ), + ), + required_glossary_terms={ + 'algorithm': [] + } + ) + ), ( + 'some_processors.md', + VertoResult( + html_string=self.read_test_file(self.test_name, 'some_processors_expected.html', strip=True), + title='Another Example Title', + required_files={ + 'interactives': set(), + 'images': {'totally-legit-image.png'}, + 'page_scripts': set(), + 'scratch_images': set() + }, + heading_tree=(HeadingNode( + title='Another Example Title', + title_slug='another-example-title', + level=1, + children=(HeadingNode( + title='This is an H2', + title_slug='this-is-an-h2', + level=2, + children=() + ),), + ),), + required_glossary_terms={ + 'chomsky-hierarchy': + [('Formal languages', 'glossary-chomsky-hierarchy')] + } + ) + ), ( + 'some_processors_2.md', + VertoResult( + html_string=self.read_test_file(self.test_name, 'some_processors_2_expected.html', strip=True), + title='Another Example Title', + required_files={ + 'interactives': set(), + 'images': { + 'totally-legit-image.png', + 'finite-state-automata-no-trap-example.png', + 'finite-state-automata-trap-added-example.png', + 'finite-state-automata-trap-added-extreme-example.png', + }, + 'page_scripts': set(), + 'scratch_images': set() + }, + heading_tree=(HeadingNode( + title='Another Example Title', + title_slug='another-example-title', + level=1, + children=(), + ),), + required_glossary_terms={ + 'hello': [], + 'algorithm': + [('computer program', 'glossary-algorithm'), + ('algorithm cost', 'glossary-algorithm-2'), + ('searching algorithms', 'glossary-algorithm-3'), + ('sorting algorithms', 'glossary-algorithm-4')] + } + ) + )] - # self.assertEqual(verto_result.title, expected_result.title) - # self.assertEqual(verto_result.required_files, expected_result.required_files) - # self.assertTupleEqual(verto_result.heading_tree, expected_result.heading_tree) - # self.assertDictEqual(verto_result.required_glossary_terms, expected_result.required_glossary_terms) - # verto.clear_saved_data() + verto = Verto() + for filename, expected_result in test_cases: + test_string = self.read_test_file(self.test_name, filename) + verto_result = verto.convert(test_string) - # def test_multiple_calls_without_clearing(self): - # '''Tests that if the verto extension is not cleared that information such as required_files and slugs are persistent. - # ''' - # filename = 'all_processors.md' - # other_filename = 'otherfile.md' - # expected_result = VertoResult( - # html_string=self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True), - # title='Example Title', - # required_files={ - # 'interactives': { - # 'binary-cards' - # }, - # 'images': set(), - # 'page_scripts': set(), - # 'scratch_images': { - # ScratchImageMetaData( - # hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', - # text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' - # ), - # } - # }, - # heading_tree=( - # HeadingNode( - # title='Example Title', - # title_slug='example-title', - # level=1, - # children=(), - # ), - # HeadingNode( - # title='Example Title 2', - # title_slug='example-title-2', - # level=1, - # children=() - # ), - # ), - # required_glossary_terms={ - # 'algorithm': [] - # } - # ) - # expected_otherfile_result = VertoResult( - # html_string=self.read_test_file(self.test_name, 'otherfile_expected.html', strip=True), - # title='Example Title', - # required_files={ - # 'interactives': { - # 'binary-cards' - # }, - # 'images': { - # 'pixel-diamond.png' - # }, - # 'page_scripts': set(), - # 'scratch_images': { - # ScratchImageMetaData( - # hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', - # text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' - # ), - # ScratchImageMetaData( - # hash='b78bff524e54a18116e1e898a93e360827f874a8b0b508e1edc47d21516495ad', - # text='never\ngoing\nto\ngive\nyou\nup' - # ), - # } - # }, - # heading_tree=(HeadingNode( - # title='Example Title', - # title_slug='example-title-3', - # level=1, - # children=(), - # ), - # ), - # required_glossary_terms={ - # 'algorithm': [] - # } - # ) + self.assertEqual(verto_result.title, expected_result.title) + self.assertEqual(verto_result.required_files, expected_result.required_files) + self.assertTupleEqual(verto_result.heading_tree, expected_result.heading_tree) + self.assertDictEqual(verto_result.required_glossary_terms, expected_result.required_glossary_terms) + verto.clear_saved_data() - # verto = Verto() - # # First file - # test_string = self.read_test_file(self.test_name, filename) - # verto_result = verto.convert(test_string) + def test_multiple_calls_without_clearing(self): + '''Tests that if the verto extension is not cleared that information such as required_files and slugs are persistent. + ''' + filename = 'all_processors.md' + other_filename = 'otherfile.md' + expected_result = VertoResult( + html_string=self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True), + title='Example Title', + required_files={ + 'interactives': { + 'binary-cards' + }, + 'images': set(), + 'page_scripts': set(), + 'scratch_images': { + ScratchImageMetaData( + hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', + text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' + ), + } + }, + heading_tree=( + HeadingNode( + title='Example Title', + title_slug='example-title', + level=1, + children=(), + ), + HeadingNode( + title='Example Title 2', + title_slug='example-title-2', + level=1, + children=() + ), + ), + required_glossary_terms={ + 'algorithm': [] + } + ) + expected_otherfile_result = VertoResult( + html_string=self.read_test_file(self.test_name, 'otherfile_expected.html', strip=True), + title='Example Title', + required_files={ + 'interactives': { + 'binary-cards' + }, + 'images': { + 'pixel-diamond.png' + }, + 'page_scripts': set(), + 'scratch_images': { + ScratchImageMetaData( + hash='a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576', + text='when flag clicked\nclear\nforever\npen down\nif < and > then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees' + ), + ScratchImageMetaData( + hash='b78bff524e54a18116e1e898a93e360827f874a8b0b508e1edc47d21516495ad', + text='never\ngoing\nto\ngive\nyou\nup' + ), + } + }, + heading_tree=(HeadingNode( + title='Example Title', + title_slug='example-title-3', + level=1, + children=(), + ), + ), + required_glossary_terms={ + 'algorithm': [] + } + ) - # self.assertEqual(verto_result.title, expected_result.title) - # self.assertEqual(verto_result.required_files, expected_result.required_files) - # self.assertTupleEqual(verto_result.heading_tree, expected_result.heading_tree) - # self.assertDictEqual(verto_result.required_glossary_terms, expected_result.required_glossary_terms) + verto = Verto() + # First file + test_string = self.read_test_file(self.test_name, filename) + verto_result = verto.convert(test_string) - # # Another file - # test_string = self.read_test_file(self.test_name, other_filename) - # verto_result = verto.convert(test_string) + self.assertEqual(verto_result.title, expected_result.title) + self.assertEqual(verto_result.required_files, expected_result.required_files) + self.assertTupleEqual(verto_result.heading_tree, expected_result.heading_tree) + self.assertDictEqual(verto_result.required_glossary_terms, expected_result.required_glossary_terms) - # self.assertEqual(verto_result.title, expected_otherfile_result.title) - # self.assertEqual(verto_result.required_files, expected_otherfile_result.required_files) - # self.assertTupleEqual(verto_result.heading_tree, expected_otherfile_result.heading_tree) - # self.assertDictEqual(verto_result.required_glossary_terms, expected_otherfile_result.required_glossary_terms) + # Another file + test_string = self.read_test_file(self.test_name, other_filename) + verto_result = verto.convert(test_string) - # def test_custom_processors_and_custom_templates_on_creation(self): - # '''Checks if custom processors and custom templates work together on creation of verto. - # ''' - # processors = {'image-tag', 'boxed-text'} - # verto = Verto(processors=processors, html_templates=self.custom_templates) - # test_string = self.read_test_file(self.test_name, 'all_processors.md') - # converted_test_string = verto.convert(test_string).html_string - # expected_string = self.read_test_file(self.test_name, 'custom_processors_custom_templates_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + self.assertEqual(verto_result.title, expected_otherfile_result.title) + self.assertEqual(verto_result.required_files, expected_otherfile_result.required_files) + self.assertTupleEqual(verto_result.heading_tree, expected_otherfile_result.heading_tree) + self.assertDictEqual(verto_result.required_glossary_terms, expected_otherfile_result.required_glossary_terms) - # def test_custom_processors_and_custom_templates_after_creation(self): - # '''Checks if custom processors and custom templates work together after creation of verto. - # ''' - # processors = {'image-tag', 'boxed-text'} - # verto = Verto() - # verto.update_processors(processors) - # verto.update_templates(self.custom_templates) - # test_string = self.read_test_file(self.test_name, 'all_processors.md') - # converted_test_string = verto.convert(test_string).html_string - # expected_string = self.read_test_file(self.test_name, 'custom_processors_custom_templates_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + def test_custom_processors_and_custom_templates_on_creation(self): + '''Checks if custom processors and custom templates work together on creation of verto. + ''' + processors = {'image-tag', 'boxed-text'} + verto = Verto(processors=processors, html_templates=self.custom_templates) + test_string = self.read_test_file(self.test_name, 'all_processors.md') + converted_test_string = verto.convert(test_string).html_string + expected_string = self.read_test_file(self.test_name, 'custom_processors_custom_templates_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_default_processors_on_creation(self): - # '''Checks if all expected default processors work on default creation. - # ''' - # verto = Verto() - # test_string = self.read_test_file(self.test_name, 'all_processors.md') - # converted_test_string = verto.convert(test_string).html_string - # expected_string = self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + def test_custom_processors_and_custom_templates_after_creation(self): + '''Checks if custom processors and custom templates work together after creation of verto. + ''' + processors = {'image-tag', 'boxed-text'} + verto = Verto() + verto.update_processors(processors) + verto.update_templates(self.custom_templates) + test_string = self.read_test_file(self.test_name, 'all_processors.md') + converted_test_string = verto.convert(test_string).html_string + expected_string = self.read_test_file(self.test_name, 'custom_processors_custom_templates_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_custom_processors_on_creation(self): - # '''Checks if system only uses specified processors. - # ''' - # processors = {'panel', 'image-container'} - # verto = Verto(processors=processors) - # test_string = self.read_test_file(self.test_name, 'all_processors.md') - # converted_test_string = verto.convert(test_string).html_string - # expected_string = self.read_test_file(self.test_name, 'custom_processors_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + def test_default_processors_on_creation(self): + '''Checks if all expected default processors work on default creation. + ''' + verto = Verto() + test_string = self.read_test_file(self.test_name, 'all_processors.md') + converted_test_string = verto.convert(test_string).html_string + expected_string = self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_custom_processors_after_creation(self): - # '''Checks if extension correct changes processors. - # ''' - # verto = Verto() - # processors = Verto.processor_defaults() - # processors.add('example_processor') - # processors.remove('comment') - # verto.update_processors(processors) - # # Check example_processor is now stored in extension processors - # self.assertEqual(verto.verto_extension.processors, processors) - # # Check comments are now skipped - # test_string = self.read_test_file(self.test_name, 'all_processors.md') - # converted_test_string = verto.convert(test_string).html_string - # expected_string = self.read_test_file(self.test_name, 'all_processors_except_comment_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + def test_custom_processors_on_creation(self): + '''Checks if system only uses specified processors. + ''' + processors = {'panel', 'image-container'} + verto = Verto(processors=processors) + test_string = self.read_test_file(self.test_name, 'all_processors.md') + converted_test_string = verto.convert(test_string).html_string + expected_string = self.read_test_file(self.test_name, 'custom_processors_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_unique_custom_processors(self): - # '''Checks if unique processors are stored when duplicates provided. - # ''' - # processors = ['comment', 'comment', 'comment'] - # verto = Verto(processors=processors) - # self.assertEqual(verto.verto_extension.processors, set(processors)) - # processors = list(Verto.processor_defaults()) - # processors.append('example_processor') - # processors.append('example_processor') - # processors.append('example_processor') - # verto.update_processors(processors) - # self.assertTrue(verto.verto_extension.processors, processors) + def test_custom_processors_after_creation(self): + '''Checks if extension correct changes processors. + ''' + verto = Verto() + processors = Verto.processor_defaults() + processors.add('example_processor') + processors.remove('comment') + verto.update_processors(processors) + # Check example_processor is now stored in extension processors + self.assertEqual(verto.verto_extension.processors, processors) + # Check comments are now skipped + test_string = self.read_test_file(self.test_name, 'all_processors.md') + converted_test_string = verto.convert(test_string).html_string + expected_string = self.read_test_file(self.test_name, 'all_processors_except_comment_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_custom_templates_on_creation(self): - # '''Checks custom templates are used when given on creation. - # ''' - # verto = Verto(html_templates=self.custom_templates) - # test_string = self.read_test_file(self.test_name, 'all_processors.md') - # converted_test_string = verto.convert(test_string).html_string - # expected_string = self.read_test_file(self.test_name, 'all_processors_custom_html_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + def test_unique_custom_processors(self): + '''Checks if unique processors are stored when duplicates provided. + ''' + processors = ['comment', 'comment', 'comment'] + verto = Verto(processors=processors) + self.assertEqual(verto.verto_extension.processors, set(processors)) + processors = list(Verto.processor_defaults()) + processors.append('example_processor') + processors.append('example_processor') + processors.append('example_processor') + verto.update_processors(processors) + self.assertTrue(verto.verto_extension.processors, processors) - # def test_custom_templates_after_creation(self): - # '''Checks custom templates are used when given after creation. - # ''' - # verto = Verto() - # verto.update_templates(self.custom_templates) - # test_string = self.read_test_file(self.test_name, 'all_processors.md') - # converted_test_string = verto.convert(test_string).html_string - # expected_string = self.read_test_file(self.test_name, 'all_processors_custom_html_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + def test_custom_templates_on_creation(self): + '''Checks custom templates are used when given on creation. + ''' + verto = Verto(html_templates=self.custom_templates) + test_string = self.read_test_file(self.test_name, 'all_processors.md') + converted_test_string = verto.convert(test_string).html_string + expected_string = self.read_test_file(self.test_name, 'all_processors_custom_html_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_reset_templates_after_custom(self): - # '''Checks custom templates are reset when given at creation. - # ''' - # verto = Verto(html_templates=self.custom_templates) - # verto.clear_templates() - # test_string = self.read_test_file(self.test_name, 'all_processors.md') - # converted_test_string = verto.convert(test_string).html_string - # expected_string = self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + def test_custom_templates_after_creation(self): + '''Checks custom templates are used when given after creation. + ''' + verto = Verto() + verto.update_templates(self.custom_templates) + test_string = self.read_test_file(self.test_name, 'all_processors.md') + converted_test_string = verto.convert(test_string).html_string + expected_string = self.read_test_file(self.test_name, 'all_processors_custom_html_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - def test_alt(self): + def test_reset_templates_after_custom(self): '''Checks custom templates are reset when given at creation. ''' - verto = Verto() + verto = Verto(html_templates=self.custom_templates) verto.clear_templates() - test_string = self.read_test_file(self.test_name, 'test.md') + test_string = self.read_test_file(self.test_name, 'all_processors.md') converted_test_string = verto.convert(test_string).html_string - expected_string = self.read_test_file(self.test_name, 'test_expected.html', strip=True) - print() - print(converted_test_string) - print() - print(expected_string) - print() + expected_string = self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - # def test_multiline_custom_templates(self): - # '''Checks that multiple multiline custom templates are loaded and used correctly. - # ''' - # custom_templates = { - # 'image': \ -# '''
-# -#
''', + def test_multiline_custom_templates(self): + '''Checks that multiple multiline custom templates are loaded and used correctly. + ''' + custom_templates = { + 'image': \ +'''
+ +
''', - # 'boxed-text': \ -# '''
-#
-# {{ text }} -#
-#
''', + 'boxed-text': \ +'''
+
+{{ text }} +
+
''', - # 'heading': \ -# '''<{{ heading_type }} id="{{ title_slug }}"> -# -# {{ level_1 }}.{{ level_2 }}.{{ level_3 }}.{{ level_4 }}.{{ level_5 }}.{{ level_6 }}. -# -# {{ title }} -# ''' + 'heading': \ +'''<{{ heading_type }} id="{{ title_slug }}"> + +{{ level_1 }}.{{ level_2 }}.{{ level_3 }}.{{ level_4 }}.{{ level_5 }}.{{ level_6 }}. + +{{ title }} +''' - # } + } - # verto = Verto(html_templates=custom_templates) - # test_string = self.read_test_file(self.test_name, 'all_processors.md') - # converted_test_string = verto.convert(test_string).html_string - # expected_string = self.read_test_file(self.test_name, 'multiline_templates_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + verto = Verto(html_templates=custom_templates) + test_string = self.read_test_file(self.test_name, 'all_processors.md') + converted_test_string = verto.convert(test_string).html_string + expected_string = self.read_test_file(self.test_name, 'multiline_templates_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) diff --git a/verto/tests/ImageTagTest.py b/verto/tests/ImageTagTest.py index c07f3664..e1f2b38e 100644 --- a/verto/tests/ImageTagTest.py +++ b/verto/tests/ImageTagTest.py @@ -43,406 +43,406 @@ def test_caption(self): # should not be matched expected_string = self.read_test_file(self.processor_name, 'caption_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - # def test_no_caption(self): - # '''Tests to ensure that an image with no caption is rendered correctly and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'no_caption.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'no_caption_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'pixel-diamond.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_caption_false(self): - # '''Tests caption argument is ignored when set to false and that expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'caption_false.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'caption_false_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'cats.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_invalid_caption_parameter(self): - # '''Tests that ArgumentValueError is raised when aaption-link argument is give but a caption is not provided. - # ''' - # test_string = self.read_test_file(self.processor_name, 'invalid_caption_error.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - # def test_source_hover_no_caption(self): - # '''Tests that multiple arguments are rendered correctly when no caption argument is included and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'source_hover_no_caption.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([False, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'source_hover_no_caption_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'finite-state-automata-no-trap-example.png', - # 'finite-state-automata-trap-added-example.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_alt_hover_caption_false(self): - # '''Tests that multiple arguments are rendered correctly when caption argument is false and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'alt_hover_caption_false.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([False, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'alt_hover_caption_false_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'finite-state-automata-no-trap-example.png', - # 'finite-state-automata-trap-added-example.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_multiple_images_captions_false(self): - # '''Tests to ensure that multiple internally reference images produce the desired output and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'multiple_images_captions_false.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([False, True, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'multiple_images_captions_false_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'the-first-image.png', - # 'Lipsum.png', - # 'pixel-diamond.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_external_image(self): - # '''Tests that external images are processed and that the expected images are unchanged. - # ''' - # test_string = self.read_test_file(self.processor_name, 'external_image.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'external_image_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # def test_contains_hover_text(self): - # '''Tests that argument for hover-text produces expected output and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'contains_hover_text.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([False, True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'contains_hover_text_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'computer-studying-turing-test.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_missing_alt_parameter(self): - # '''Tests that missing alt argument produces correct error. - # ''' - # test_string = self.read_test_file(self.processor_name, 'missing_alt_parameter.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - # def test_contains_source(self): - # '''Tests that argument for source produces expected output and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'contains_source.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([False, True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'contains_source_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'computer-studying-turing-test.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_align_left(self): - # '''Tests that argument for align produces expected output when set to left and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'align_left.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'align_left_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'computer-studying-turing-test.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_align_right(self): - # '''Tests that argument for align produces expected output when set to right and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'align_right.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'align_right_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'computer-studying-turing-test.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_align_center(self): - # '''Tests that argument for align produces expected output when set to center and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'align_center.md') - # blocks = self.to_blocks(test_string) + def test_no_caption(self): + '''Tests to ensure that an image with no caption is rendered correctly and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'no_caption.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'no_caption_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'pixel-diamond.png' + } + self.assertSetEqual(expected_images, images) + + def test_caption_false(self): + '''Tests caption argument is ignored when set to false and that expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'caption_false.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'caption_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'cats.png' + } + self.assertSetEqual(expected_images, images) + + def test_invalid_caption_parameter(self): + '''Tests that ArgumentValueError is raised when aaption-link argument is give but a caption is not provided. + ''' + test_string = self.read_test_file(self.processor_name, 'invalid_caption_error.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + def test_source_hover_no_caption(self): + '''Tests that multiple arguments are rendered correctly when no caption argument is included and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'source_hover_no_caption.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'source_hover_no_caption_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'finite-state-automata-no-trap-example.png', + 'finite-state-automata-trap-added-example.png' + } + self.assertSetEqual(expected_images, images) + + def test_alt_hover_caption_false(self): + '''Tests that multiple arguments are rendered correctly when caption argument is false and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'alt_hover_caption_false.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'alt_hover_caption_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'finite-state-automata-no-trap-example.png', + 'finite-state-automata-trap-added-example.png' + } + self.assertSetEqual(expected_images, images) + + def test_multiple_images_captions_false(self): + '''Tests to ensure that multiple internally reference images produce the desired output and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'multiple_images_captions_false.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'multiple_images_captions_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'the-first-image.png', + 'Lipsum.png', + 'pixel-diamond.png' + } + self.assertSetEqual(expected_images, images) + + def test_external_image(self): + '''Tests that external images are processed and that the expected images are unchanged. + ''' + test_string = self.read_test_file(self.processor_name, 'external_image.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'external_image_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_contains_hover_text(self): + '''Tests that argument for hover-text produces expected output and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'contains_hover_text.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'contains_hover_text_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_missing_alt_parameter(self): + '''Tests that missing alt argument produces correct error. + ''' + test_string = self.read_test_file(self.processor_name, 'missing_alt_parameter.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - # self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'align_center_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + def test_contains_source(self): + '''Tests that argument for source produces expected output and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'contains_source.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'contains_source_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_align_left(self): + '''Tests that argument for align produces expected output when set to left and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'align_left.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'align_left_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_align_right(self): + '''Tests that argument for align produces expected output when set to right and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'align_right.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'align_right_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_align_center(self): + '''Tests that argument for align produces expected output when set to center and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'align_center.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'align_center_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'computer-studying-turing-test.png' - # } - # self.assertSetEqual(expected_images, images) + def test_caption_link_error(self): + '''Tests that ArgumentMissingError is raised when caption-link argument is give but a caption is not provided. + ''' + test_string = self.read_test_file(self.processor_name, 'caption_link_error.md') + blocks = self.to_blocks(test_string) - # def test_caption_link_error(self): - # '''Tests that ArgumentMissingError is raised when caption-link argument is give but a caption is not provided. - # ''' - # test_string = self.read_test_file(self.processor_name, 'caption_link_error.md') - # blocks = self.to_blocks(test_string) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - # self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - # def test_align_undefined_error(self): - # '''Tests that ArgumentValueError is raised when undefined align value is given. - # ''' - # test_string = self.read_test_file(self.processor_name, 'align_undefined_error.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + def test_align_undefined_error(self): + '''Tests that ArgumentValueError is raised when undefined align value is given. + ''' + test_string = self.read_test_file(self.processor_name, 'align_undefined_error.md') + blocks = self.to_blocks(test_string) - # self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # def test_image_in_numbered_list(self): - # '''Test image rendered correctly in numbered list. - # ''' - # test_string = self.read_test_file(self.processor_name, 'image_in_numbered_list.md') - # blocks = self.to_blocks(test_string) + self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - # self.assertListEqual([False, False, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + def test_image_in_numbered_list(self): + '''Test image rendered correctly in numbered list. + ''' + test_string = self.read_test_file(self.processor_name, 'image_in_numbered_list.md') + blocks = self.to_blocks(test_string) - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'image_in_numbered_list_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + self.assertListEqual([False, False, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'image_in_numbered_list_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_image_width_value(self): - # '''Test image rendered correctly with width value. - # ''' - # test_string = self.read_test_file(self.processor_name, 'file_width_value.md') - # blocks = self.to_blocks(test_string) + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) - # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + def test_image_width_value(self): + '''Test image rendered correctly with width value. + ''' + test_string = self.read_test_file(self.processor_name, 'file_width_value.md') + blocks = self.to_blocks(test_string) - # html_template = self.read_test_file(self.processor_name, 'file_width_value_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'file_width_value_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + html_template = self.read_test_file(self.processor_name, 'file_width_value_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) - - # def test_image_width_value_no_units(self): - # '''Test image rendered correctly with width value with no units. - # ''' - # test_string = self.read_test_file(self.processor_name, 'file_width_value_no_units.md') - # blocks = self.to_blocks(test_string) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'file_width_value_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) - # html_template = self.read_test_file(self.processor_name, 'file_width_value_no_units_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + def test_image_width_value_no_units(self): + '''Test image rendered correctly with width value with no units. + ''' + test_string = self.read_test_file(self.processor_name, 'file_width_value_no_units.md') + blocks = self.to_blocks(test_string) - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'file_width_value_no_units_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) + html_template = self.read_test_file(self.processor_name, 'file_width_value_no_units_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - # def test_image_invalid_width_value_1(self): - # '''Test image rendered correctly with width value. - # ''' - # test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1.md') - # blocks = self.to_blocks(test_string) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'file_width_value_no_units_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) - # html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + def test_image_invalid_width_value_1(self): + '''Test image rendered correctly with width value. + ''' + test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1.md') + blocks = self.to_blocks(test_string) - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # def test_image_invalid_width_value_2(self): - # '''Test image rendered correctly with width value. - # ''' - # test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2.md') - # blocks = self.to_blocks(test_string) + html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) - # html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + def test_image_invalid_width_value_2(self): + '''Test image rendered correctly with width value. + ''' + test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2.md') + blocks = self.to_blocks(test_string) - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) + html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - # def test_image_width_value_external_image(self): - # '''Test image rendered correctly with width value. - # ''' - # test_string = self.read_test_file(self.processor_name, 'file_width_value_external_image.md') - # blocks = self.to_blocks(test_string) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) - # html_template = self.read_test_file(self.processor_name, 'file_width_value_external_image_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + def test_image_width_value_external_image(self): + '''Test image rendered correctly with width value. + ''' + test_string = self.read_test_file(self.processor_name, 'file_width_value_external_image.md') + blocks = self.to_blocks(test_string) - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'file_width_value_external_image_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) + html_template = self.read_test_file(self.processor_name, 'file_width_value_external_image_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - # #~ - # # Doc Tests - # #~ + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'file_width_value_external_image_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_doc_example_basic(self): - # '''Basic example of common usage. - # ''' - # test_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage.md') - # blocks = self.to_blocks(test_string) + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) - # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + #~ + # Doc Tests + #~ - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + def test_doc_example_basic(self): + '''Basic example of common usage. + ''' + test_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage.md') + blocks = self.to_blocks(test_string) - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # def test_doc_example_override_html(self): - # '''Basic example showing how to override the html-template. - # ''' - # test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') - # blocks = self.to_blocks(test_string) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) - # html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + def test_doc_example_override_html(self): + '''Basic example showing how to override the html-template. + ''' + test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) - # def test_doc_example_2_override_html(self): - # '''Basic example showing how to override the html-template for relative files in a specific file only. - # ''' - # test_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html.md') - # blocks = self.to_blocks(test_string) + def test_doc_example_2_override_html(self): + '''Basic example showing how to override the html-template for relative files in a specific file only. + ''' + test_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html.md') + blocks = self.to_blocks(test_string) - # self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # html_template = self.read_test_file(self.processor_name, 'doc_example_2_override_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + html_template = self.read_test_file(self.processor_name, 'doc_example_2_override_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) diff --git a/verto/tests/assets/configuration/all_processors_custom_html_expected.html b/verto/tests/assets/configuration/all_processors_custom_html_expected.html index 4bf36292..41904832 100644 --- a/verto/tests/assets/configuration/all_processors_custom_html_expected.html +++ b/verto/tests/assets/configuration/all_processors_custom_html_expected.html @@ -20,7 +20,7 @@

This text is the panel's contents.

-
+testtest

Computer Science Report for 2.44

Put your introduction to what bits are here.

diff --git a/verto/tests/assets/configuration/all_processors_except_comment_expected.html b/verto/tests/assets/configuration/all_processors_except_comment_expected.html index dc7e7c61..fc481627 100644 --- a/verto/tests/assets/configuration/all_processors_except_comment_expected.html +++ b/verto/tests/assets/configuration/all_processors_except_comment_expected.html @@ -22,12 +22,12 @@

- +This is alt text

Dancing with our hands tied.

Source

- +This is alt text

Source

diff --git a/verto/tests/assets/configuration/custom_processors_custom_templates_expected.html b/verto/tests/assets/configuration/custom_processors_custom_templates_expected.html index e9650c64..2226aeb0 100644 --- a/verto/tests/assets/configuration/custom_processors_custom_templates_expected.html +++ b/verto/tests/assets/configuration/custom_processors_custom_templates_expected.html @@ -8,10 +8,10 @@

Teacher Note

Guides for Algorithms

This text is the panel's contents.

{panel end}

-

{image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left"}

+

{image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left" alt="This is alt text"}

Dancing with our hands tied.

{image end}

-
+test

Computer Science Report for 2.44

Put your introduction to what bits are here.

diff --git a/verto/tests/assets/configuration/custom_processors_expected.html b/verto/tests/assets/configuration/custom_processors_expected.html index db6dc430..d49c836e 100644 --- a/verto/tests/assets/configuration/custom_processors_expected.html +++ b/verto/tests/assets/configuration/custom_processors_expected.html @@ -12,11 +12,11 @@

Example Title 2

- +This is alt text

Dancing with our hands tied.

Source

-

{image file-path="http://placehold.it/250x50" caption="false" source="https://placehold.it/" hover-text="This is hover text" alignment="left"}

+

{image file-path="http://placehold.it/250x50" caption="false" source="https://placehold.it/" hover-text="This is hover text" alignment="left" alt="This is alt text"}

{boxed-text}

Computer Science Report for 2.44

Put your introduction to what bits are here.

diff --git a/verto/tests/assets/configuration/some_processors.md b/verto/tests/assets/configuration/some_processors.md index 3b02c4b1..835f559d 100644 --- a/verto/tests/assets/configuration/some_processors.md +++ b/verto/tests/assets/configuration/some_processors.md @@ -2,7 +2,7 @@ ## This is an H2 -{image file-path="totally-legit-image.png"} +{image alt="This is alt text" file-path="totally-legit-image.png"} This is a sentence. diff --git a/verto/tests/assets/configuration/some_processors_2.md b/verto/tests/assets/configuration/some_processors_2.md index e4e675b1..5dd5a897 100644 --- a/verto/tests/assets/configuration/some_processors_2.md +++ b/verto/tests/assets/configuration/some_processors_2.md @@ -1,6 +1,6 @@ # Another Example Title -{image file-path="totally-legit-image.png"} +{image alt="This is alt text" file-path="totally-legit-image.png"} This is a sentence. diff --git a/verto/tests/assets/configuration/some_processors_2_expected.html b/verto/tests/assets/configuration/some_processors_2_expected.html index a5e37f5e..4b530eb2 100644 --- a/verto/tests/assets/configuration/some_processors_2_expected.html +++ b/verto/tests/assets/configuration/some_processors_2_expected.html @@ -5,7 +5,7 @@

Another Example Title

- +This is alt text

This is a sentence.

Here's another FSA to consider:

diff --git a/verto/tests/assets/configuration/some_processors_expected.html b/verto/tests/assets/configuration/some_processors_expected.html index af54bf2d..45b513b3 100644 --- a/verto/tests/assets/configuration/some_processors_expected.html +++ b/verto/tests/assets/configuration/some_processors_expected.html @@ -11,7 +11,7 @@

This is an H2

- +This is alt text

This is a sentence.

Chomsky Hierarchy

diff --git a/verto/tests/assets/configuration/test.md b/verto/tests/assets/configuration/test.md deleted file mode 100644 index c44b6348..00000000 --- a/verto/tests/assets/configuration/test.md +++ /dev/null @@ -1,7 +0,0 @@ -{image file-path="http://placehold.it/350x150" alt="This is alt text" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left"} - -Dancing with our hands tied. - -{image end} - -{image file-path="http://placehold.it/250x50" caption="false" source="https://placehold.it/" hover-text="This is hover text" alignment="left" alt="This is alt text"} diff --git a/verto/tests/assets/configuration/test_expected.html b/verto/tests/assets/configuration/test_expected.html deleted file mode 100644 index 4f34df4e..00000000 --- a/verto/tests/assets/configuration/test_expected.html +++ /dev/null @@ -1,9 +0,0 @@ -
-This is alt text -

Dancing with our hands tied.

-

Source

-
-
-This is alt text -

Source

-
diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 42483421..5cfc39b3 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -85,31 +85,31 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - # unittest.makeSuite(BoxedTextTest), - # unittest.makeSuite(ButtonLinkTest), + unittest.makeSuite(BoxedTextTest), + unittest.makeSuite(ButtonLinkTest), unittest.makeSuite(CommentTest), - # unittest.makeSuite(ConditionalTest), - # unittest.makeSuite(FrameTest), - # unittest.makeSuite(GlossaryLinkTest), - # unittest.makeSuite(HeadingTest), - # unittest.makeSuite(ImageInlineTest), + unittest.makeSuite(ConditionalTest), + unittest.makeSuite(FrameTest), + unittest.makeSuite(GlossaryLinkTest), + unittest.makeSuite(HeadingTest), + unittest.makeSuite(ImageInlineTest), unittest.makeSuite(ImageTagTest), - # unittest.makeSuite(ImageContainerTest), - # unittest.makeSuite(InteractiveTest), - # unittest.makeSuite(JinjaTest), - # unittest.makeSuite(PanelTest), - # unittest.makeSuite(SaveTitleTest), - # unittest.makeSuite(ScratchTest), - # unittest.makeSuite(ScratchInlineTest), - # unittest.makeSuite(StyleTest), - # unittest.makeSuite(RelativeLinkTest), - # unittest.makeSuite(RemoveTest), - # unittest.makeSuite(RemoveTitleTest), - # unittest.makeSuite(TableOfContentsTest), - # unittest.makeSuite(VideoTest), - - # unittest.makeSuite(HtmlParserTest), - # unittest.makeSuite(MarkdownOverrideTest), + unittest.makeSuite(ImageContainerTest), + unittest.makeSuite(InteractiveTest), + unittest.makeSuite(JinjaTest), + unittest.makeSuite(PanelTest), + unittest.makeSuite(SaveTitleTest), + unittest.makeSuite(ScratchTest), + unittest.makeSuite(ScratchInlineTest), + unittest.makeSuite(StyleTest), + unittest.makeSuite(RelativeLinkTest), + unittest.makeSuite(RemoveTest), + unittest.makeSuite(RemoveTitleTest), + unittest.makeSuite(TableOfContentsTest), + unittest.makeSuite(VideoTest), + + unittest.makeSuite(HtmlParserTest), + unittest.makeSuite(MarkdownOverrideTest), )) From a2236dfe2f9b62da7cd1c9596fcd05dba611db22 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 14 May 2018 13:29:08 +1200 Subject: [PATCH 26/73] WIP updating tests to require alt text --- verto/processors/utils.py | 18 -------- .../doc_example_2_override_html.md | 2 +- .../doc_example_2_override_html_expected.html | 2 +- .../doc_example_2_override_html_template.html | 2 +- .../doc_example_override_html.md | 2 +- .../doc_example_override_html_expected.html | 2 +- .../doc_example_override_html_template.html | 2 +- .../file_invalid_width_value_1.md | 2 +- .../file_invalid_width_value_1_expected.html | 2 +- .../file_invalid_width_value_2.md | 2 +- .../file_invalid_width_value_2_expected.html | 2 +- .../image-container/file_width_value.md | 2 +- .../file_width_value_expected.html | 2 +- .../file_width_value_external_image.md | 2 +- ...e_width_value_external_image_expected.html | 2 +- .../file_width_value_no_units.md | 2 +- .../file_width_value_no_units_expected.html | 2 +- ...le_width_value_no_units_html_template.html | 1 + .../image-container/image_in_image_tag.md | 4 +- .../image-container/image_in_numbered_list.md | 2 +- .../image_in_numbered_list_expected.html | 2 +- .../multiple_images_captions_true.md | 2 +- ...ultiple_images_captions_true_expected.html | 2 +- .../image-tag/doc_example_override_html.md | 2 +- .../assets/panel/contains_inner_image.md | 2 +- .../panel/contains_inner_image_expected.html | 2 +- verto/tests/start_tests.py | 44 +++++++++---------- 27 files changed, 48 insertions(+), 65 deletions(-) diff --git a/verto/processors/utils.py b/verto/processors/utils.py index 23e4c591..fe28c988 100644 --- a/verto/processors/utils.py +++ b/verto/processors/utils.py @@ -45,29 +45,11 @@ def parse_flag(argument_key, arguments, default=False): true if argument is found, otherwise none. ''' result = re.search(r'(^|\s+){}(.+?".*?")'.format(argument_key), arguments) - # result = re.search(r'(^|\s+){}($|\s)'.format(argument_key), arguments) if result: return True else: return default -def tag_starts_with(argument_key, arguments, default=False): - '''search for the given argument in a string of all arguments, - treating the argument as a flag only. - - args: - argument_key: the name of the argument. - arguments: a string of the argument inputs. - default: the default value if not found. - returns: - true if argument is found, otherwise none. - ''' - # result = re.search(r'(^|\s+){}(.+?".*?")'.format(argument_key), arguments) - result = re.search(r'(^|\s+){}($|\s)'.format(argument_key), arguments) - if result: - return True - else: - return default def parse_arguments(processor, inputs, arguments): diff --git a/verto/tests/assets/image-container/doc_example_2_override_html.md b/verto/tests/assets/image-container/doc_example_2_override_html.md index b9349730..c2c765a8 100644 --- a/verto/tests/assets/image-container/doc_example_2_override_html.md +++ b/verto/tests/assets/image-container/doc_example_2_override_html.md @@ -1,4 +1,4 @@ -{image file-path="apple.png" caption="true"} +{image alt="Placeholder alt text" file-path="apple.png" caption="true"} Don't pretend it's such a mystery. diff --git a/verto/tests/assets/image-container/doc_example_2_override_html_expected.html b/verto/tests/assets/image-container/doc_example_2_override_html_expected.html index b5f8b829..6ae9c715 100644 --- a/verto/tests/assets/image-container/doc_example_2_override_html_expected.html +++ b/verto/tests/assets/image-container/doc_example_2_override_html_expected.html @@ -1,4 +1,4 @@
- +Placeholder alt text

Caption:

Don't pretend it's such a mystery.
diff --git a/verto/tests/assets/image-container/doc_example_2_override_html_template.html b/verto/tests/assets/image-container/doc_example_2_override_html_template.html index 8c8660e2..a03d37a5 100644 --- a/verto/tests/assets/image-container/doc_example_2_override_html_template.html +++ b/verto/tests/assets/image-container/doc_example_2_override_html_template.html @@ -1,4 +1,4 @@
- + {{ alt }}

Caption:

{{ caption }}
diff --git a/verto/tests/assets/image-container/doc_example_override_html.md b/verto/tests/assets/image-container/doc_example_override_html.md index 06449b4b..355fd32a 100644 --- a/verto/tests/assets/image-container/doc_example_override_html.md +++ b/verto/tests/assets/image-container/doc_example_override_html.md @@ -1,4 +1,4 @@ -{image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/"} +{image alt="Placeholder alt text" file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/"} This is the caption text. diff --git a/verto/tests/assets/image-container/doc_example_override_html_expected.html b/verto/tests/assets/image-container/doc_example_override_html_expected.html index e1a30e24..59580456 100644 --- a/verto/tests/assets/image-container/doc_example_override_html_expected.html +++ b/verto/tests/assets/image-container/doc_example_override_html_expected.html @@ -1,4 +1,4 @@
- + Placeholder alt text

This is the caption text.

diff --git a/verto/tests/assets/image-container/doc_example_override_html_template.html b/verto/tests/assets/image-container/doc_example_override_html_template.html index 886e565a..e0be7c19 100644 --- a/verto/tests/assets/image-container/doc_example_override_html_template.html +++ b/verto/tests/assets/image-container/doc_example_override_html_template.html @@ -1,4 +1,4 @@
- + {{ alt }}

{{ caption }}

diff --git a/verto/tests/assets/image-container/file_invalid_width_value_1.md b/verto/tests/assets/image-container/file_invalid_width_value_1.md index 50779ab5..d6443e04 100644 --- a/verto/tests/assets/image-container/file_invalid_width_value_1.md +++ b/verto/tests/assets/image-container/file_invalid_width_value_1.md @@ -1,4 +1,4 @@ -{image file-path="path/to/image@.png" caption="true" hover-text="This is hover text" alignment="left"} +{image alt="ducks" file-path="path/to/image@.png" caption="true" hover-text="This is hover text" alignment="left"} This is the caption text. diff --git a/verto/tests/assets/image-container/file_invalid_width_value_1_expected.html b/verto/tests/assets/image-container/file_invalid_width_value_1_expected.html index 1fa1577a..fc2aebde 100644 --- a/verto/tests/assets/image-container/file_invalid_width_value_1_expected.html +++ b/verto/tests/assets/image-container/file_invalid_width_value_1_expected.html @@ -1,4 +1,4 @@
- +ducks

This is the caption text.

diff --git a/verto/tests/assets/image-container/file_invalid_width_value_2.md b/verto/tests/assets/image-container/file_invalid_width_value_2.md index 67ee5a4f..ea85f8aa 100644 --- a/verto/tests/assets/image-container/file_invalid_width_value_2.md +++ b/verto/tests/assets/image-container/file_invalid_width_value_2.md @@ -1,4 +1,4 @@ -{image file-path="path/to/image@em20.png" caption="true" hover-text="This is hover text" alignment="left"} +{image alt="ducks" file-path="path/to/image@em20.png" caption="true" hover-text="This is hover text" alignment="left"} This is the caption text. diff --git a/verto/tests/assets/image-container/file_invalid_width_value_2_expected.html b/verto/tests/assets/image-container/file_invalid_width_value_2_expected.html index 5d932441..e806d814 100644 --- a/verto/tests/assets/image-container/file_invalid_width_value_2_expected.html +++ b/verto/tests/assets/image-container/file_invalid_width_value_2_expected.html @@ -1,4 +1,4 @@
- +ducks

This is the caption text.

diff --git a/verto/tests/assets/image-container/file_width_value.md b/verto/tests/assets/image-container/file_width_value.md index 018577b6..b8b34654 100644 --- a/verto/tests/assets/image-container/file_width_value.md +++ b/verto/tests/assets/image-container/file_width_value.md @@ -1,4 +1,4 @@ -{image file-path="path/to/image@500px.png" caption="true" hover-text="This is hover text" alignment="left"} +{image file-path="path/to/image@500px.png" caption="true" hover-text="This is hover text" alt="cats" alignment="left"} This is the caption text. diff --git a/verto/tests/assets/image-container/file_width_value_expected.html b/verto/tests/assets/image-container/file_width_value_expected.html index eb89417f..1c7de037 100644 --- a/verto/tests/assets/image-container/file_width_value_expected.html +++ b/verto/tests/assets/image-container/file_width_value_expected.html @@ -1,4 +1,4 @@
- +cats

This is the caption text.

diff --git a/verto/tests/assets/image-container/file_width_value_external_image.md b/verto/tests/assets/image-container/file_width_value_external_image.md index 40cb4077..a04bf37f 100644 --- a/verto/tests/assets/image-container/file_width_value_external_image.md +++ b/verto/tests/assets/image-container/file_width_value_external_image.md @@ -1,4 +1,4 @@ -{image file-path="https://www.verto.io/images/image@200px.png" caption="true" hover-text="This is hover text" alignment="left"} +{image file-path="https://www.verto.io/images/image@200px.png" caption="true" alt="cats" hover-text="This is hover text" alignment="left"} This is the caption text. diff --git a/verto/tests/assets/image-container/file_width_value_external_image_expected.html b/verto/tests/assets/image-container/file_width_value_external_image_expected.html index 838b6e67..54ff24b4 100644 --- a/verto/tests/assets/image-container/file_width_value_external_image_expected.html +++ b/verto/tests/assets/image-container/file_width_value_external_image_expected.html @@ -1,4 +1,4 @@
- +cats

This is the caption text.

diff --git a/verto/tests/assets/image-container/file_width_value_no_units.md b/verto/tests/assets/image-container/file_width_value_no_units.md index 75353b01..4c393c8d 100644 --- a/verto/tests/assets/image-container/file_width_value_no_units.md +++ b/verto/tests/assets/image-container/file_width_value_no_units.md @@ -1,4 +1,4 @@ -{image file-path="path/to/image@700.png" caption="true"} +{image alt="alt text" file-path="path/to/image@700.png" caption="true"} This is the caption text. diff --git a/verto/tests/assets/image-container/file_width_value_no_units_expected.html b/verto/tests/assets/image-container/file_width_value_no_units_expected.html index 1b4706cf..9cc958a1 100644 --- a/verto/tests/assets/image-container/file_width_value_no_units_expected.html +++ b/verto/tests/assets/image-container/file_width_value_no_units_expected.html @@ -1,4 +1,4 @@
- +alt text

This is the caption text.

diff --git a/verto/tests/assets/image-container/file_width_value_no_units_html_template.html b/verto/tests/assets/image-container/file_width_value_no_units_html_template.html index 8f1b76f7..49a507fd 100644 --- a/verto/tests/assets/image-container/file_width_value_no_units_html_template.html +++ b/verto/tests/assets/image-container/file_width_value_no_units_html_template.html @@ -1,5 +1,6 @@
ducks

Lorem

- +ducks

Placeholder image

Source

diff --git a/verto/tests/assets/image-container/multiple_images_captions_true.md b/verto/tests/assets/image-container/multiple_images_captions_true.md index 4efba9f4..3921fe4b 100644 --- a/verto/tests/assets/image-container/multiple_images_captions_true.md +++ b/verto/tests/assets/image-container/multiple_images_captions_true.md @@ -1,6 +1,6 @@ Imagine we have the following simple black and white image. -{image file-path="the-first-image.png" caption="true"} +{image file-path="the-first-image.png" alt="Alt text for an image" caption="true"} This is the first caption. diff --git a/verto/tests/assets/image-container/multiple_images_captions_true_expected.html b/verto/tests/assets/image-container/multiple_images_captions_true_expected.html index 209044bf..243b6e5a 100644 --- a/verto/tests/assets/image-container/multiple_images_captions_true_expected.html +++ b/verto/tests/assets/image-container/multiple_images_captions_true_expected.html @@ -1,6 +1,6 @@

Imagine we have the following simple black and white image.

- +Alt text for an image

This is the first caption.

diff --git a/verto/tests/assets/image-tag/doc_example_override_html.md b/verto/tests/assets/image-tag/doc_example_override_html.md index 205d12ba..ab7d539f 100644 --- a/verto/tests/assets/image-tag/doc_example_override_html.md +++ b/verto/tests/assets/image-tag/doc_example_override_html.md @@ -1 +1 @@ -{image file-path="http://placehold.it/350x150" alt="placeholder image" source="https://placehold.it/"} +{image alt="dogs" file-path="http://placehold.it/350x150" alt="placeholder image" source="https://placehold.it/"} diff --git a/verto/tests/assets/panel/contains_inner_image.md b/verto/tests/assets/panel/contains_inner_image.md index 7fbdcc00..2b53aa02 100644 --- a/verto/tests/assets/panel/contains_inner_image.md +++ b/verto/tests/assets/panel/contains_inner_image.md @@ -6,7 +6,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc non accumsan libero, et suscipit velit. Phasellus quis lorem eget lacus rutrum lobortis. Integer tincidunt convallis arcu a porttitor. Ut urna sapien, egestas mollis lectus a, suscipit placerat ante. Vestibulum id congue tellus. Nullam dapibus felis eu ligula mattis, vel consectetur nibh aliquet. Maecenas nec elit orci. Curabitur ut massa maximus, ultrices diam at, porttitor erat. Praesent eu purus vitae ligula elementum iaculis in non eros. Quisque eu aliquet dolor, ut pharetra lacus. -{image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left"} +{image file-path="http://placehold.it/350x150" caption="true" alt="alt text" source="https://placehold.it/" hover-text="This is hover text" alignment="left"} Placeholder image diff --git a/verto/tests/assets/panel/contains_inner_image_expected.html b/verto/tests/assets/panel/contains_inner_image_expected.html index 5b149fb3..8d621ad7 100644 --- a/verto/tests/assets/panel/contains_inner_image_expected.html +++ b/verto/tests/assets/panel/contains_inner_image_expected.html @@ -5,7 +5,7 @@

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc non accumsan libero, et suscipit velit. Phasellus quis lorem eget lacus rutrum lobortis. Integer tincidunt convallis arcu a porttitor. Ut urna sapien, egestas mollis lectus a, suscipit placerat ante. Vestibulum id congue tellus. Nullam dapibus felis eu ligula mattis, vel consectetur nibh aliquet. Maecenas nec elit orci. Curabitur ut massa maximus, ultrices diam at, porttitor erat. Praesent eu purus vitae ligula elementum iaculis in non eros. Quisque eu aliquet dolor, ut pharetra lacus.

- +alt text

Placeholder image

Source

diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 5cfc39b3..15800e42 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -85,31 +85,31 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - unittest.makeSuite(BoxedTextTest), - unittest.makeSuite(ButtonLinkTest), - unittest.makeSuite(CommentTest), - unittest.makeSuite(ConditionalTest), - unittest.makeSuite(FrameTest), - unittest.makeSuite(GlossaryLinkTest), - unittest.makeSuite(HeadingTest), + # unittest.makeSuite(BoxedTextTest), + # unittest.makeSuite(ButtonLinkTest), + # unittest.makeSuite(CommentTest), + # unittest.makeSuite(ConditionalTest), + # unittest.makeSuite(FrameTest), + # unittest.makeSuite(GlossaryLinkTest), + # unittest.makeSuite(HeadingTest), unittest.makeSuite(ImageInlineTest), unittest.makeSuite(ImageTagTest), unittest.makeSuite(ImageContainerTest), - unittest.makeSuite(InteractiveTest), - unittest.makeSuite(JinjaTest), - unittest.makeSuite(PanelTest), - unittest.makeSuite(SaveTitleTest), - unittest.makeSuite(ScratchTest), - unittest.makeSuite(ScratchInlineTest), - unittest.makeSuite(StyleTest), - unittest.makeSuite(RelativeLinkTest), - unittest.makeSuite(RemoveTest), - unittest.makeSuite(RemoveTitleTest), - unittest.makeSuite(TableOfContentsTest), - unittest.makeSuite(VideoTest), - - unittest.makeSuite(HtmlParserTest), - unittest.makeSuite(MarkdownOverrideTest), + # unittest.makeSuite(InteractiveTest), + # unittest.makeSuite(JinjaTest), + # unittest.makeSuite(PanelTest), + # unittest.makeSuite(SaveTitleTest), + # unittest.makeSuite(ScratchTest), + # unittest.makeSuite(ScratchInlineTest), + # unittest.makeSuite(StyleTest), + # unittest.makeSuite(RelativeLinkTest), + # unittest.makeSuite(RemoveTest), + # unittest.makeSuite(RemoveTitleTest), + # unittest.makeSuite(TableOfContentsTest), + # unittest.makeSuite(VideoTest), + + # unittest.makeSuite(HtmlParserTest), + # unittest.makeSuite(MarkdownOverrideTest), )) From e8f19434edea0657d8c7c67511ccf79f165fc8b8 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 15 May 2018 12:27:07 +1200 Subject: [PATCH 27/73] Fixed all image container and inline tests --- .../assets/image-container/align_center.md | 2 +- .../align_center_expected.html | 2 +- .../assets/image-container/align_left.md | 2 +- .../image-container/align_left_expected.html | 2 +- .../assets/image-container/align_right.md | 2 +- .../image-container/align_right_expected.html | 2 +- .../image-container/align_undefined_error.md | 2 +- ...caption_true_not_provided_numbered_list.md | 2 +- ...tion_true_numbered_list_missing_end_tag.md | 2 +- .../contains_caption_expected.html | 2 +- .../image-container/contains_caption_link.md | 2 +- .../contains_caption_link_expected.html | 2 +- .../image-container/contains_hover_text.md | 2 +- .../contains_hover_text_expected.html | 2 +- .../assets/image-container/contains_source.md | 2 +- .../contains_source_expected.html | 2 +- .../doc_example_2_override_html_template.html | 2 +- .../doc_example_basic_usage.md | 2 +- .../doc_example_basic_usage_expected.html | 2 +- .../assets/image-inline/argument_caption.md | 2 +- .../argument_caption_expected.html | 2 +- .../image-inline/argument_caption_link.md | 2 +- .../argument_caption_link_expected.html | 2 +- .../image-inline/argument_hover_text.md | 2 +- .../argument_hover_text_expected.html | 2 +- .../image-inline/argument_source_link.md | 2 +- .../argument_source_link_expected.html | 2 +- .../doc_example_2_override_html.md | 2 +- .../image-inline/doc_example_basic_usage.md | 2 +- .../doc_example_basic_usage_expected.html | 2 +- .../image-inline/doc_example_override_html.md | 2 +- .../doc_example_override_html_expected.html | 2 +- .../doc_example_override_html_template.html | 2 +- .../assets/image-inline/external_image.md | 2 +- .../image-inline/external_image_expected.html | 2 +- .../file_invalid_width_value_1.md | 2 +- .../file_invalid_width_value_1_expected.html | 2 +- .../file_invalid_width_value_2.md | 2 +- .../file_invalid_width_value_2_expected.html | 2 +- .../assets/image-inline/file_width_value.md | 2 +- .../file_width_value_expected.html | 2 +- .../file_width_value_external_image.md | 2 +- ...e_width_value_external_image_expected.html | 2 +- .../file_width_value_html_template.html | 1 + .../image-inline/file_width_value_no_units.md | 2 +- .../file_width_value_no_units_expected.html | 2 +- ...le_width_value_no_units_html_template.html | 1 + .../assets/image-inline/internal_image.md | 2 +- .../image-inline/internal_image_expected.html | 2 +- .../image-inline/multiple_internal_images.md | 2 +- .../multiple_internal_images_expected.html | 4 +- .../assets/image-inline/numbered_list.md | 2 +- .../image-inline/numbered_list_expected.html | 2 +- .../tests/assets/image-inline/table_embed.md | 8 ++-- .../image-inline/table_embed_expected.html | 4 +- verto/tests/start_tests.py | 44 +++++++++---------- 56 files changed, 82 insertions(+), 80 deletions(-) diff --git a/verto/tests/assets/image-container/align_center.md b/verto/tests/assets/image-container/align_center.md index b26706b7..e027f644 100644 --- a/verto/tests/assets/image-container/align_center.md +++ b/verto/tests/assets/image-container/align_center.md @@ -1,4 +1,4 @@ -{image file-path="computer-studying-turing-test.png" caption="true" alignment="center"} +{image alt="alt text" file-path="computer-studying-turing-test.png" caption="true" alignment="center"} This is a caption for a computer studying the turing test. diff --git a/verto/tests/assets/image-container/align_center_expected.html b/verto/tests/assets/image-container/align_center_expected.html index 262ae566..4a6d9a8f 100644 --- a/verto/tests/assets/image-container/align_center_expected.html +++ b/verto/tests/assets/image-container/align_center_expected.html @@ -1,4 +1,4 @@
- +alt text

This is a caption for a computer studying the turing test.

diff --git a/verto/tests/assets/image-container/align_left.md b/verto/tests/assets/image-container/align_left.md index 88ac54c1..8e814886 100644 --- a/verto/tests/assets/image-container/align_left.md +++ b/verto/tests/assets/image-container/align_left.md @@ -1,4 +1,4 @@ -{image file-path="computer-studying-turing-test.png" alignment="left" caption="true"} +{image alt="alt text" file-path="computer-studying-turing-test.png" alignment="left" caption="true"} Cats cats cats. diff --git a/verto/tests/assets/image-container/align_left_expected.html b/verto/tests/assets/image-container/align_left_expected.html index 2369410c..e4dc2421 100644 --- a/verto/tests/assets/image-container/align_left_expected.html +++ b/verto/tests/assets/image-container/align_left_expected.html @@ -1,4 +1,4 @@
- +alt text

Cats cats cats.

diff --git a/verto/tests/assets/image-container/align_right.md b/verto/tests/assets/image-container/align_right.md index 4d997b94..5f126959 100644 --- a/verto/tests/assets/image-container/align_right.md +++ b/verto/tests/assets/image-container/align_right.md @@ -1,4 +1,4 @@ -{image caption="true" file-path="computer-studying-turing-test.png" alignment="right"} +{image caption="true" alt="alt text" file-path="computer-studying-turing-test.png" alignment="right"} Hey hey hey, look who it is! A caption! diff --git a/verto/tests/assets/image-container/align_right_expected.html b/verto/tests/assets/image-container/align_right_expected.html index dfb21c1a..3c8ae5c7 100644 --- a/verto/tests/assets/image-container/align_right_expected.html +++ b/verto/tests/assets/image-container/align_right_expected.html @@ -1,4 +1,4 @@
- +alt text

Hey hey hey, look who it is! A caption!

diff --git a/verto/tests/assets/image-container/align_undefined_error.md b/verto/tests/assets/image-container/align_undefined_error.md index e9e15de6..70c36826 100644 --- a/verto/tests/assets/image-container/align_undefined_error.md +++ b/verto/tests/assets/image-container/align_undefined_error.md @@ -1,4 +1,4 @@ -{image file-path="computer-studying-turing-test.png" alignment="around-about-here" caption="true"} +{image alt="alt text" file-path="computer-studying-turing-test.png" alignment="around-about-here" caption="true"} This is the caption. diff --git a/verto/tests/assets/image-container/caption_true_not_provided_numbered_list.md b/verto/tests/assets/image-container/caption_true_not_provided_numbered_list.md index ecb5bf2e..b89cc604 100644 --- a/verto/tests/assets/image-container/caption_true_not_provided_numbered_list.md +++ b/verto/tests/assets/image-container/caption_true_not_provided_numbered_list.md @@ -6,7 +6,7 @@ 2. Lorem - {image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left"} + {image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left" alt="alt text"} {image end} diff --git a/verto/tests/assets/image-container/caption_true_numbered_list_missing_end_tag.md b/verto/tests/assets/image-container/caption_true_numbered_list_missing_end_tag.md index 3183eb06..e2c2f59e 100644 --- a/verto/tests/assets/image-container/caption_true_numbered_list_missing_end_tag.md +++ b/verto/tests/assets/image-container/caption_true_numbered_list_missing_end_tag.md @@ -6,7 +6,7 @@ 2. Lorem - {image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left"} + {image file-path="http://placehold.it/350x150" alt="alt text" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left"} This is a caption diff --git a/verto/tests/assets/image-container/contains_caption_expected.html b/verto/tests/assets/image-container/contains_caption_expected.html index c889960f..e056d598 100644 --- a/verto/tests/assets/image-container/contains_caption_expected.html +++ b/verto/tests/assets/image-container/contains_caption_expected.html @@ -1,4 +1,4 @@
- +alt text

Lipsum

diff --git a/verto/tests/assets/image-container/contains_caption_link.md b/verto/tests/assets/image-container/contains_caption_link.md index 1b743b6a..8baab5b2 100644 --- a/verto/tests/assets/image-container/contains_caption_link.md +++ b/verto/tests/assets/image-container/contains_caption_link.md @@ -1,4 +1,4 @@ -{image file-path="computer-studying-turing-test.png" caption="true" caption-link="example.com"} +{image alt="alt text" file-path="computer-studying-turing-test.png" caption="true" caption-link="example.com"} Lipsum diff --git a/verto/tests/assets/image-container/contains_caption_link_expected.html b/verto/tests/assets/image-container/contains_caption_link_expected.html index e2d38f64..a41f9f04 100644 --- a/verto/tests/assets/image-container/contains_caption_link_expected.html +++ b/verto/tests/assets/image-container/contains_caption_link_expected.html @@ -1,4 +1,4 @@
- +alt text

Lipsum

diff --git a/verto/tests/assets/image-container/contains_hover_text.md b/verto/tests/assets/image-container/contains_hover_text.md index 715bd4d0..ab5e254e 100644 --- a/verto/tests/assets/image-container/contains_hover_text.md +++ b/verto/tests/assets/image-container/contains_hover_text.md @@ -1,4 +1,4 @@ -{image file-path="computer-studying-turing-test.png" hover-text="Lipsum" caption="true"} +{image alt="alt text" file-path="computer-studying-turing-test.png" hover-text="Lipsum" caption="true"} This is why we can't have nice things. diff --git a/verto/tests/assets/image-container/contains_hover_text_expected.html b/verto/tests/assets/image-container/contains_hover_text_expected.html index 17a98075..17baafb5 100644 --- a/verto/tests/assets/image-container/contains_hover_text_expected.html +++ b/verto/tests/assets/image-container/contains_hover_text_expected.html @@ -1,4 +1,4 @@
- +alt text

This is why we can't have nice things.

diff --git a/verto/tests/assets/image-container/contains_source.md b/verto/tests/assets/image-container/contains_source.md index 25aeb33f..85e3a910 100644 --- a/verto/tests/assets/image-container/contains_source.md +++ b/verto/tests/assets/image-container/contains_source.md @@ -1,4 +1,4 @@ -{image caption="true" file-path="computer-studying-turing-test.png" source="example.com"} +{image alt="alt text" caption="true" file-path="computer-studying-turing-test.png" source="example.com"} Dancing with our hands tied. diff --git a/verto/tests/assets/image-container/contains_source_expected.html b/verto/tests/assets/image-container/contains_source_expected.html index ba041d06..fb3a88e4 100644 --- a/verto/tests/assets/image-container/contains_source_expected.html +++ b/verto/tests/assets/image-container/contains_source_expected.html @@ -1,5 +1,5 @@
- +alt text

Dancing with our hands tied.

Source

diff --git a/verto/tests/assets/image-container/doc_example_2_override_html_template.html b/verto/tests/assets/image-container/doc_example_2_override_html_template.html index a03d37a5..dc86abc1 100644 --- a/verto/tests/assets/image-container/doc_example_2_override_html_template.html +++ b/verto/tests/assets/image-container/doc_example_2_override_html_template.html @@ -1,4 +1,4 @@
- {{ alt }} +{{ alt }}

Caption:

{{ caption }}
diff --git a/verto/tests/assets/image-container/doc_example_basic_usage.md b/verto/tests/assets/image-container/doc_example_basic_usage.md index c9946610..39655a87 100644 --- a/verto/tests/assets/image-container/doc_example_basic_usage.md +++ b/verto/tests/assets/image-container/doc_example_basic_usage.md @@ -1,4 +1,4 @@ -{image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left"} +{image alt="Alt text" file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left"} This is the caption text. diff --git a/verto/tests/assets/image-container/doc_example_basic_usage_expected.html b/verto/tests/assets/image-container/doc_example_basic_usage_expected.html index a0ecbb06..26088f64 100644 --- a/verto/tests/assets/image-container/doc_example_basic_usage_expected.html +++ b/verto/tests/assets/image-container/doc_example_basic_usage_expected.html @@ -1,5 +1,5 @@
- +Alt text

This is the caption text.

Source

diff --git a/verto/tests/assets/image-inline/argument_caption.md b/verto/tests/assets/image-inline/argument_caption.md index 79ddbbed..29d60962 100644 --- a/verto/tests/assets/image-inline/argument_caption.md +++ b/verto/tests/assets/image-inline/argument_caption.md @@ -1 +1 @@ -An inline image: {image-inline file-path="http://placehold.it/350x150" caption="Lipsum Lorem"}. +An inline image: {image-inline file-path="http://placehold.it/350x150" alt="alt text" caption="Lipsum Lorem"}. diff --git a/verto/tests/assets/image-inline/argument_caption_expected.html b/verto/tests/assets/image-inline/argument_caption_expected.html index 4ce5ee90..0ac71dfc 100644 --- a/verto/tests/assets/image-inline/argument_caption_expected.html +++ b/verto/tests/assets/image-inline/argument_caption_expected.html @@ -1,4 +1,4 @@

An inline image:

- +alt text

Lipsum Lorem

.

diff --git a/verto/tests/assets/image-inline/argument_caption_link.md b/verto/tests/assets/image-inline/argument_caption_link.md index 49b3a6f3..e2e528ee 100644 --- a/verto/tests/assets/image-inline/argument_caption_link.md +++ b/verto/tests/assets/image-inline/argument_caption_link.md @@ -1 +1 @@ -An inline image: {image-inline file-path="http://placehold.it/350x150" caption="Lipsum Lorem" caption-link="http://www.example.com"}. +An inline image: {image-inline alt="alt text" file-path="http://placehold.it/350x150" caption="Lipsum Lorem" caption-link="http://www.example.com"}. diff --git a/verto/tests/assets/image-inline/argument_caption_link_expected.html b/verto/tests/assets/image-inline/argument_caption_link_expected.html index 518067a8..14fc74bd 100644 --- a/verto/tests/assets/image-inline/argument_caption_link_expected.html +++ b/verto/tests/assets/image-inline/argument_caption_link_expected.html @@ -1,4 +1,4 @@

An inline image:

.

diff --git a/verto/tests/assets/image-inline/argument_hover_text.md b/verto/tests/assets/image-inline/argument_hover_text.md index e9f7c1f2..c2610454 100644 --- a/verto/tests/assets/image-inline/argument_hover_text.md +++ b/verto/tests/assets/image-inline/argument_hover_text.md @@ -1 +1 @@ -An inline image: {image-inline file-path="http://placehold.it/350x150" hover-text="Lipsum Lorem"}. +An inline image: {image-inline alt="alt text" file-path="http://placehold.it/350x150" hover-text="Lipsum Lorem"}. diff --git a/verto/tests/assets/image-inline/argument_hover_text_expected.html b/verto/tests/assets/image-inline/argument_hover_text_expected.html index a1ee85e3..93499ef7 100644 --- a/verto/tests/assets/image-inline/argument_hover_text_expected.html +++ b/verto/tests/assets/image-inline/argument_hover_text_expected.html @@ -1,3 +1,3 @@

An inline image:

- +alt text
.

diff --git a/verto/tests/assets/image-inline/argument_source_link.md b/verto/tests/assets/image-inline/argument_source_link.md index e4ab1fe3..f9aa9324 100644 --- a/verto/tests/assets/image-inline/argument_source_link.md +++ b/verto/tests/assets/image-inline/argument_source_link.md @@ -1 +1 @@ -An inline image: {image-inline file-path="http://placehold.it/350x150" source="http://www.example.com"}. +An inline image: {image-inline file-path="http://placehold.it/350x150" alt="alt text" source="http://www.example.com"}. diff --git a/verto/tests/assets/image-inline/argument_source_link_expected.html b/verto/tests/assets/image-inline/argument_source_link_expected.html index 2b48541c..299356e8 100644 --- a/verto/tests/assets/image-inline/argument_source_link_expected.html +++ b/verto/tests/assets/image-inline/argument_source_link_expected.html @@ -1,4 +1,4 @@

An inline image:

- +alt text

Source

.

diff --git a/verto/tests/assets/image-inline/doc_example_2_override_html.md b/verto/tests/assets/image-inline/doc_example_2_override_html.md index 1dd140e3..015bcc3b 100644 --- a/verto/tests/assets/image-inline/doc_example_2_override_html.md +++ b/verto/tests/assets/image-inline/doc_example_2_override_html.md @@ -1 +1 @@ -An inline image: {image-inline file-path="path/to/image@500px.png"}. +An inline image: {image-inline alt="alt text" file-path="path/to/image@500px.png"}. diff --git a/verto/tests/assets/image-inline/doc_example_basic_usage.md b/verto/tests/assets/image-inline/doc_example_basic_usage.md index b026c2d8..568de38c 100644 --- a/verto/tests/assets/image-inline/doc_example_basic_usage.md +++ b/verto/tests/assets/image-inline/doc_example_basic_usage.md @@ -1 +1 @@ -An inline image: {image-inline file-path="img/example.png"}. +An inline image: {image-inline alt="alt text" file-path="img/example.png"}. diff --git a/verto/tests/assets/image-inline/doc_example_basic_usage_expected.html b/verto/tests/assets/image-inline/doc_example_basic_usage_expected.html index 5889401f..7d759e42 100644 --- a/verto/tests/assets/image-inline/doc_example_basic_usage_expected.html +++ b/verto/tests/assets/image-inline/doc_example_basic_usage_expected.html @@ -1,3 +1,3 @@

An inline image:

- +alt text
.

diff --git a/verto/tests/assets/image-inline/doc_example_override_html.md b/verto/tests/assets/image-inline/doc_example_override_html.md index f1fe58dd..7b89f7cd 100644 --- a/verto/tests/assets/image-inline/doc_example_override_html.md +++ b/verto/tests/assets/image-inline/doc_example_override_html.md @@ -1 +1 @@ -An inline image: {image-inline file-path="http://placehold.it/350x150" caption="Placeholder image" source="https://placehold.it/"}. +An inline image: {image-inline alt="alt text" file-path="http://placehold.it/350x150" caption="Placeholder image" source="https://placehold.it/"}. diff --git a/verto/tests/assets/image-inline/doc_example_override_html_expected.html b/verto/tests/assets/image-inline/doc_example_override_html_expected.html index 74e3ca2a..a958f675 100644 --- a/verto/tests/assets/image-inline/doc_example_override_html_expected.html +++ b/verto/tests/assets/image-inline/doc_example_override_html_expected.html @@ -1,3 +1,3 @@

An inline image:

- +alt text
.

diff --git a/verto/tests/assets/image-inline/doc_example_override_html_template.html b/verto/tests/assets/image-inline/doc_example_override_html_template.html index 28028df8..12ec513c 100644 --- a/verto/tests/assets/image-inline/doc_example_override_html_template.html +++ b/verto/tests/assets/image-inline/doc_example_override_html_template.html @@ -1,3 +1,3 @@
- +{{ alt }}
diff --git a/verto/tests/assets/image-inline/external_image.md b/verto/tests/assets/image-inline/external_image.md index 6e542791..a94a8a87 100644 --- a/verto/tests/assets/image-inline/external_image.md +++ b/verto/tests/assets/image-inline/external_image.md @@ -1 +1 @@ -An external image: {image-inline file-path="http://placehold.it/350x150"}. +An external image: {image-inline alt="alt text" file-path="http://placehold.it/350x150"}. diff --git a/verto/tests/assets/image-inline/external_image_expected.html b/verto/tests/assets/image-inline/external_image_expected.html index 331d87ca..6ec2e360 100644 --- a/verto/tests/assets/image-inline/external_image_expected.html +++ b/verto/tests/assets/image-inline/external_image_expected.html @@ -1,3 +1,3 @@

An external image:

- +alt text
.

diff --git a/verto/tests/assets/image-inline/file_invalid_width_value_1.md b/verto/tests/assets/image-inline/file_invalid_width_value_1.md index 2b3edb48..dc79375e 100644 --- a/verto/tests/assets/image-inline/file_invalid_width_value_1.md +++ b/verto/tests/assets/image-inline/file_invalid_width_value_1.md @@ -1 +1 @@ -An inline image: {image-inline file-path="path/to/image@.png"}. +An inline image: {image-inline alt="alt text" file-path="path/to/image@.png"}. diff --git a/verto/tests/assets/image-inline/file_invalid_width_value_1_expected.html b/verto/tests/assets/image-inline/file_invalid_width_value_1_expected.html index 4fe1428f..6b52c77e 100644 --- a/verto/tests/assets/image-inline/file_invalid_width_value_1_expected.html +++ b/verto/tests/assets/image-inline/file_invalid_width_value_1_expected.html @@ -1,3 +1,3 @@

An inline image:

- +alt text
.

diff --git a/verto/tests/assets/image-inline/file_invalid_width_value_2.md b/verto/tests/assets/image-inline/file_invalid_width_value_2.md index e04fc1e1..1c551c0f 100644 --- a/verto/tests/assets/image-inline/file_invalid_width_value_2.md +++ b/verto/tests/assets/image-inline/file_invalid_width_value_2.md @@ -1 +1 @@ -An inline image: {image-inline file-path="path/to/image@em20.png"}. +An inline image: {image-inline alt="alt text" file-path="path/to/image@em20.png"}. diff --git a/verto/tests/assets/image-inline/file_invalid_width_value_2_expected.html b/verto/tests/assets/image-inline/file_invalid_width_value_2_expected.html index a4bf5d06..bddd800d 100644 --- a/verto/tests/assets/image-inline/file_invalid_width_value_2_expected.html +++ b/verto/tests/assets/image-inline/file_invalid_width_value_2_expected.html @@ -1,3 +1,3 @@

An inline image:

- +alt text
.

diff --git a/verto/tests/assets/image-inline/file_width_value.md b/verto/tests/assets/image-inline/file_width_value.md index 1dd140e3..015bcc3b 100644 --- a/verto/tests/assets/image-inline/file_width_value.md +++ b/verto/tests/assets/image-inline/file_width_value.md @@ -1 +1 @@ -An inline image: {image-inline file-path="path/to/image@500px.png"}. +An inline image: {image-inline alt="alt text" file-path="path/to/image@500px.png"}. diff --git a/verto/tests/assets/image-inline/file_width_value_expected.html b/verto/tests/assets/image-inline/file_width_value_expected.html index 6e3cd862..a0b01db8 100644 --- a/verto/tests/assets/image-inline/file_width_value_expected.html +++ b/verto/tests/assets/image-inline/file_width_value_expected.html @@ -1,3 +1,3 @@

An inline image:

- +alt text
.

diff --git a/verto/tests/assets/image-inline/file_width_value_external_image.md b/verto/tests/assets/image-inline/file_width_value_external_image.md index fdeda0a1..b19997d5 100644 --- a/verto/tests/assets/image-inline/file_width_value_external_image.md +++ b/verto/tests/assets/image-inline/file_width_value_external_image.md @@ -1 +1 @@ -An inline image: {image-inline file-path="https://www.verto.io/images/image@200px.png"}. +An inline image: {image-inline alt="alt text" file-path="https://www.verto.io/images/image@200px.png"}. diff --git a/verto/tests/assets/image-inline/file_width_value_external_image_expected.html b/verto/tests/assets/image-inline/file_width_value_external_image_expected.html index 2ceca220..f254979b 100644 --- a/verto/tests/assets/image-inline/file_width_value_external_image_expected.html +++ b/verto/tests/assets/image-inline/file_width_value_external_image_expected.html @@ -1,3 +1,3 @@

An inline image:

- +alt text
.

diff --git a/verto/tests/assets/image-inline/file_width_value_html_template.html b/verto/tests/assets/image-inline/file_width_value_html_template.html index 73d9a88f..cd4e6dac 100644 --- a/verto/tests/assets/image-inline/file_width_value_html_template.html +++ b/verto/tests/assets/image-inline/file_width_value_html_template.html @@ -1,5 +1,6 @@
alt textAn inline image:
- +alt text
.

diff --git a/verto/tests/assets/image-inline/file_width_value_no_units_html_template.html b/verto/tests/assets/image-inline/file_width_value_no_units_html_template.html index 73d9a88f..cd4e6dac 100644 --- a/verto/tests/assets/image-inline/file_width_value_no_units_html_template.html +++ b/verto/tests/assets/image-inline/file_width_value_no_units_html_template.html @@ -1,5 +1,6 @@
alt textAn internal image:
- +alt text
.

diff --git a/verto/tests/assets/image-inline/multiple_internal_images.md b/verto/tests/assets/image-inline/multiple_internal_images.md index 6b2e9495..e2db0421 100644 --- a/verto/tests/assets/image-inline/multiple_internal_images.md +++ b/verto/tests/assets/image-inline/multiple_internal_images.md @@ -1 +1 @@ -An internal image: {image-inline file-path="img/example.png"} and some other related image {image-inline file-path="img/placeholder.jpg"}. +An internal image: {image-inline alt="alt text" file-path="img/example.png"} and some other related image {image-inline alt="alt text" file-path="img/placeholder.jpg"}. diff --git a/verto/tests/assets/image-inline/multiple_internal_images_expected.html b/verto/tests/assets/image-inline/multiple_internal_images_expected.html index a4d96d7b..e304cada 100644 --- a/verto/tests/assets/image-inline/multiple_internal_images_expected.html +++ b/verto/tests/assets/image-inline/multiple_internal_images_expected.html @@ -1,5 +1,5 @@

An internal image:

- +alt text
and some other related image
- +alt text
.

diff --git a/verto/tests/assets/image-inline/numbered_list.md b/verto/tests/assets/image-inline/numbered_list.md index 86ade6c2..ac6621a2 100644 --- a/verto/tests/assets/image-inline/numbered_list.md +++ b/verto/tests/assets/image-inline/numbered_list.md @@ -4,6 +4,6 @@ * Ni * San -2. Lorem {image-inline file-path="http://placehold.it/350x150" caption="Placeholder image" source="https://placehold.it/" hover-text="This is hover text"} +2. Lorem {image-inline alt="alt text" file-path="http://placehold.it/350x150" caption="Placeholder image" source="https://placehold.it/" hover-text="This is hover text"} 3. Ipsem diff --git a/verto/tests/assets/image-inline/numbered_list_expected.html b/verto/tests/assets/image-inline/numbered_list_expected.html index d93521fd..62573ad1 100644 --- a/verto/tests/assets/image-inline/numbered_list_expected.html +++ b/verto/tests/assets/image-inline/numbered_list_expected.html @@ -9,7 +9,7 @@
  • Lorem

    - +alt text

    Placeholder image

    Source

    diff --git a/verto/tests/assets/image-inline/table_embed.md b/verto/tests/assets/image-inline/table_embed.md index 62912681..7a5b1baf 100644 --- a/verto/tests/assets/image-inline/table_embed.md +++ b/verto/tests/assets/image-inline/table_embed.md @@ -1,4 +1,4 @@ -| Input | Output | -| ----- | ------------------------------------------- | -| 31 | {image-inline file-path="img/example1.png"} | -| 11 | {image-inline file-path="img/example2.png"} | +| Input | Output | +| ----- | ---------------------------------------------------------- | +| 31 | {image-inline alt="alt text" file-path="img/example1.png"} | +| 11 | {image-inline alt="alt text" file-path="img/example2.png"} | diff --git a/verto/tests/assets/image-inline/table_embed_expected.html b/verto/tests/assets/image-inline/table_embed_expected.html index 7054919e..c91fc530 100644 --- a/verto/tests/assets/image-inline/table_embed_expected.html +++ b/verto/tests/assets/image-inline/table_embed_expected.html @@ -10,7 +10,7 @@ 31
    - +alt text
    @@ -18,7 +18,7 @@ 11
    - +alt text
    diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 15800e42..5cfc39b3 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -85,31 +85,31 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - # unittest.makeSuite(BoxedTextTest), - # unittest.makeSuite(ButtonLinkTest), - # unittest.makeSuite(CommentTest), - # unittest.makeSuite(ConditionalTest), - # unittest.makeSuite(FrameTest), - # unittest.makeSuite(GlossaryLinkTest), - # unittest.makeSuite(HeadingTest), + unittest.makeSuite(BoxedTextTest), + unittest.makeSuite(ButtonLinkTest), + unittest.makeSuite(CommentTest), + unittest.makeSuite(ConditionalTest), + unittest.makeSuite(FrameTest), + unittest.makeSuite(GlossaryLinkTest), + unittest.makeSuite(HeadingTest), unittest.makeSuite(ImageInlineTest), unittest.makeSuite(ImageTagTest), unittest.makeSuite(ImageContainerTest), - # unittest.makeSuite(InteractiveTest), - # unittest.makeSuite(JinjaTest), - # unittest.makeSuite(PanelTest), - # unittest.makeSuite(SaveTitleTest), - # unittest.makeSuite(ScratchTest), - # unittest.makeSuite(ScratchInlineTest), - # unittest.makeSuite(StyleTest), - # unittest.makeSuite(RelativeLinkTest), - # unittest.makeSuite(RemoveTest), - # unittest.makeSuite(RemoveTitleTest), - # unittest.makeSuite(TableOfContentsTest), - # unittest.makeSuite(VideoTest), - - # unittest.makeSuite(HtmlParserTest), - # unittest.makeSuite(MarkdownOverrideTest), + unittest.makeSuite(InteractiveTest), + unittest.makeSuite(JinjaTest), + unittest.makeSuite(PanelTest), + unittest.makeSuite(SaveTitleTest), + unittest.makeSuite(ScratchTest), + unittest.makeSuite(ScratchInlineTest), + unittest.makeSuite(StyleTest), + unittest.makeSuite(RelativeLinkTest), + unittest.makeSuite(RemoveTest), + unittest.makeSuite(RemoveTitleTest), + unittest.makeSuite(TableOfContentsTest), + unittest.makeSuite(VideoTest), + + unittest.makeSuite(HtmlParserTest), + unittest.makeSuite(MarkdownOverrideTest), )) From 5e6dc8eb6a879906080fd7619ec21efbbdabe703 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 15 May 2018 12:46:34 +1200 Subject: [PATCH 28/73] Added some additional tests for missing alt tag --- verto/tests/ImageContainerTest.py | 10 ++++++++++ verto/tests/ImageInlineTest.py | 15 +++++---------- .../image-container/missing_alt_parameter.md | 5 +++++ .../image-inline/argument_alt_expected.html | 3 --- .../{argument_alt.md => missing_argument_alt.md} | 2 +- 5 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 verto/tests/assets/image-container/missing_alt_parameter.md delete mode 100644 verto/tests/assets/image-inline/argument_alt_expected.html rename verto/tests/assets/image-inline/{argument_alt.md => missing_argument_alt.md} (74%) diff --git a/verto/tests/ImageContainerTest.py b/verto/tests/ImageContainerTest.py index f6db09d0..68f1dba4 100644 --- a/verto/tests/ImageContainerTest.py +++ b/verto/tests/ImageContainerTest.py @@ -135,6 +135,16 @@ def test_caption_true_numbered_list_missing_end_tag(self): self.assertRaises(TagNotMatchedError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + def test_missing_alt_parameter(self): + '''Tests that missing alt argument produces correct error. + ''' + test_string = self.read_test_file(self.processor_name, 'missing_alt_parameter.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + def test_image_in_image_tag(self): '''Test that ImageCaptionContainsImageError is raised when the first line in an image container block is another image container block. ''' diff --git a/verto/tests/ImageInlineTest.py b/verto/tests/ImageInlineTest.py index cb6ba0b5..9e331179 100644 --- a/verto/tests/ImageInlineTest.py +++ b/verto/tests/ImageInlineTest.py @@ -4,6 +4,7 @@ from collections import defaultdict from verto.VertoExtension import VertoExtension from verto.processors.ImageInlinePattern import ImageInlinePattern +from verto.errors.ArgumentMissingError import ArgumentMissingError from verto.tests.ProcessorTest import ProcessorTest class ImageInlineTest(ProcessorTest): @@ -123,20 +124,14 @@ def test_multiple_internal_images(self): # Argument tests #~ - def test_argument_alt(self): - '''Test that the alt argument is correctly rendered.''' - test_string = self.read_test_file(self.processor_name, 'argument_alt.md') + def test_missing_argument_alt(self): + '''Test that ArgumentMissingError is thrown when alt argument is missing''' + test_string = self.read_test_file(self.processor_name, 'missing_argument_alt.md') processor = ImageInlinePattern(self.ext, self.md.parser) self.assertIsNotNone(re.search(processor.compiled_re, test_string)) - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'argument_alt_expected.html', strip=True).strip() - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) def test_argument_caption(self): '''Test that the caption argument is correctly rendered.''' diff --git a/verto/tests/assets/image-container/missing_alt_parameter.md b/verto/tests/assets/image-container/missing_alt_parameter.md new file mode 100644 index 00000000..1c1a7d71 --- /dev/null +++ b/verto/tests/assets/image-container/missing_alt_parameter.md @@ -0,0 +1,5 @@ +{image file-path="computer-studying-turing-test.png" caption="true"} + +This is the caption text. + +{image end} \ No newline at end of file diff --git a/verto/tests/assets/image-inline/argument_alt_expected.html b/verto/tests/assets/image-inline/argument_alt_expected.html deleted file mode 100644 index cd24ec04..00000000 --- a/verto/tests/assets/image-inline/argument_alt_expected.html +++ /dev/null @@ -1,3 +0,0 @@ -

    An inline image:

    -Lipsum -
    .

    diff --git a/verto/tests/assets/image-inline/argument_alt.md b/verto/tests/assets/image-inline/missing_argument_alt.md similarity index 74% rename from verto/tests/assets/image-inline/argument_alt.md rename to verto/tests/assets/image-inline/missing_argument_alt.md index c5bbcae0..9506de51 100644 --- a/verto/tests/assets/image-inline/argument_alt.md +++ b/verto/tests/assets/image-inline/missing_argument_alt.md @@ -1 +1 @@ -An inline image: {image-inline file-path="http://placehold.it/350x150" alt="Lipsum"}. +An inline image: {image-inline file-path="http://placehold.it/350x150"}. From 4aad015d946d4cd2565f9ac44e7b05a6a7ee5999 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 15 May 2018 12:53:49 +1200 Subject: [PATCH 29/73] Style fixes --- verto/processors/ConditionalProcessor.py | 2 +- verto/processors/utils.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/verto/processors/ConditionalProcessor.py b/verto/processors/ConditionalProcessor.py index 0b285706..f4cac837 100644 --- a/verto/processors/ConditionalProcessor.py +++ b/verto/processors/ConditionalProcessor.py @@ -69,7 +69,7 @@ def run(self, parent, blocks): elif tag_starts_with('end', start_tag.group('args')): 'end' else: - string='unrecognised' + string = 'unrecognised' msg = '{} conditional found before if'.format(string) raise TagNotMatchedError(self.processor, block, msg) diff --git a/verto/processors/utils.py b/verto/processors/utils.py index fe28c988..9802dc9d 100644 --- a/verto/processors/utils.py +++ b/verto/processors/utils.py @@ -17,7 +17,7 @@ def parse_argument(argument_key, arguments, default=None): Value of an argument as a string if found, otherwise None. ''' is_argument = re.search(r'(^|\s+){}='.format(argument_key), arguments) - if not is_argument: # if not found in string, return default + if not is_argument: return default result = re.match(r'(^|\s+){}="([^"]*("(?<=\\")[^"]*)*)"'.format(argument_key), arguments[is_argument.start():]) @@ -51,7 +51,6 @@ def parse_flag(argument_key, arguments, default=False): return default - def parse_arguments(processor, inputs, arguments): '''Parses the arguments of a given input and ensures they meet the defined requirements. @@ -69,7 +68,7 @@ def parse_arguments(processor, inputs, arguments): argument_values = defaultdict(None) for argument, argument_info in arguments.items(): is_required = argument_info['required'] - is_arg = parse_argument(argument, inputs, None) is not None # true when argument is found + is_arg = parse_argument(argument, inputs, None) is not None if is_required and not is_arg: raise ArgumentMissingError(processor, argument, '{} is a required argument.'.format(argument)) From a0d4e1bd512aaf3d67b042992a82bc2f3acfd0f0 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Sun, 20 May 2018 08:52:33 +1200 Subject: [PATCH 30/73] Update setuptools from 39.1.0 to 39.2.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ab72fc89..fca5dfc1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ markdown==2.6.11 Jinja2==2.10 python-slugify==1.2.5 -setuptools==39.1.0 +setuptools==39.2.0 # Required dependencies for building documentation sphinx==1.7.4 From b7ffff49bf151c9748a740c8a4f5e3cca989865e Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Tue, 29 May 2018 19:13:50 +1200 Subject: [PATCH 31/73] Update sphinx from 1.7.4 to 1.7.5 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ab72fc89..0a7210cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ python-slugify==1.2.5 setuptools==39.1.0 # Required dependencies for building documentation -sphinx==1.7.4 +sphinx==1.7.5 sphinx_rtd_theme==0.3.0 From 91ac2676b02f4c945a7cafb1f840983c46b9442f Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Sun, 10 Jun 2018 14:31:52 +1200 Subject: [PATCH 32/73] Added functionality for changing which arguments are required --- verto/Verto.py | 7 ++++--- verto/VertoExtension.py | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/verto/Verto.py b/verto/Verto.py index bd8dc370..c6c571c7 100644 --- a/verto/Verto.py +++ b/verto/Verto.py @@ -29,7 +29,7 @@ class Verto(object): to HTML. ''' - def __init__(self, processors=DEFAULT_PROCESSORS, html_templates={}, extensions=[]): + def __init__(self, processors=DEFAULT_PROCESSORS, html_templates={}, extensions=[], custom_rules={}): '''Creates a Verto object. Args: @@ -50,7 +50,7 @@ def __init__(self, processors=DEFAULT_PROCESSORS, html_templates={}, extensions= ### WIP # Overwrite processor-info file with any rules given here self.custom_rules = { - 'image': { + 'image-container': { 'alt': False } } @@ -62,7 +62,8 @@ def create_converter(self): self.verto_extension = VertoExtension( processors=self.processors, html_templates=self.html_templates, - extensions=self.extensions + extensions=self.extensions, + custom_rules=self.custom_rules, ) all_extensions = self.extensions + [self.verto_extension] self.converter = markdown.Markdown(extensions=all_extensions) diff --git a/verto/VertoExtension.py b/verto/VertoExtension.py index 9241d422..7292eb17 100644 --- a/verto/VertoExtension.py +++ b/verto/VertoExtension.py @@ -46,7 +46,7 @@ class VertoExtension(Extension): the Verto converter. ''' - def __init__(self, processors=[], html_templates={}, extensions=[], *args, **kwargs): + def __init__(self, processors=[], html_templates={}, extensions=[], custom_rules={}, *args, **kwargs): ''' Args: processors: A set of processor names given as strings for which @@ -61,7 +61,9 @@ def __init__(self, processors=[], html_templates={}, extensions=[], *args, **kwa ''' super().__init__(*args, **kwargs) self.jinja_templates = self.loadJinjaTemplates(html_templates) + self.custom_rules = custom_rules self.processor_info = self.loadProcessorInfo() + # print(self.processor_info) self.processors = processors self.title = None self.heading_tree = None @@ -218,7 +220,10 @@ def loadProcessorInfo(self): The json object of the file where objects are ordered dictionaries. ''' json_data = pkg_resources.resource_string('verto', 'processor-info.json').decode('utf-8') - return json.loads(json_data, object_pairs_hook=OrderedDict) + json_data = json.loads(json_data, object_pairs_hook=OrderedDict) + if len(self.custom_rules) != 0: + self.modify_rules(json_data) + return json_data def get_heading_tree(self): ''' @@ -240,3 +245,12 @@ def _set_heading_tree(self, tree): assert isinstance(tree, tuple) assert all(isinstance(child, HeadingNode) for child in tree) self.heading_tree = tree + + # refactor to modify_required_arguments + def modify_rules(self, json_data): + for processor, arguments_to_modify in self.custom_rules.items(): + for argument in arguments_to_modify.items(): + new_required = str(argument[1]).lower() + json_data[processor]['arguments'][argument[0]]['required'] = new_required + return json_data + From f66fd2d0794880ed233e9cd69d3049ca74887c6f Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Sun, 10 Jun 2018 14:32:32 +1200 Subject: [PATCH 33/73] Update sphinx_rtd_theme from 0.3.0 to 0.4.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ab72fc89..b9450c0d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,4 @@ setuptools==39.1.0 # Required dependencies for building documentation sphinx==1.7.4 -sphinx_rtd_theme==0.3.0 +sphinx_rtd_theme==0.4.0 From 71c12c7dbc3db507987d2f010947699f1090b969 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Fri, 6 Jul 2018 12:28:34 +1200 Subject: [PATCH 34/73] WIP testing custom argument rules --- verto/Verto.py | 6 +- verto/VertoExtension.py | 13 +- verto/processors/utils.py | 2 + verto/tests/ImageContainerTest.py | 889 +++++++++--------- .../tests/assets/image-container/alt_false.md | 11 + .../image-container/alt_false_expected.html | 8 + verto/tests/start_tests.py | 48 +- 7 files changed, 516 insertions(+), 461 deletions(-) create mode 100644 verto/tests/assets/image-container/alt_false.md create mode 100644 verto/tests/assets/image-container/alt_false_expected.html diff --git a/verto/Verto.py b/verto/Verto.py index c6c571c7..5ca5d87a 100644 --- a/verto/Verto.py +++ b/verto/Verto.py @@ -29,7 +29,7 @@ class Verto(object): to HTML. ''' - def __init__(self, processors=DEFAULT_PROCESSORS, html_templates={}, extensions=[], custom_rules={}): + def __init__(self, processors=DEFAULT_PROCESSORS, html_templates={}, extensions=[], custom_argument_rules={}): '''Creates a Verto object. Args: @@ -49,7 +49,7 @@ def __init__(self, processors=DEFAULT_PROCESSORS, html_templates={}, extensions= self.extensions = list(extensions) ### WIP # Overwrite processor-info file with any rules given here - self.custom_rules = { + self.custom_argument_rules = { 'image-container': { 'alt': False } @@ -63,7 +63,7 @@ def create_converter(self): processors=self.processors, html_templates=self.html_templates, extensions=self.extensions, - custom_rules=self.custom_rules, + custom_argument_rules=self.custom_argument_rules, ) all_extensions = self.extensions + [self.verto_extension] self.converter = markdown.Markdown(extensions=all_extensions) diff --git a/verto/VertoExtension.py b/verto/VertoExtension.py index 7292eb17..3e862112 100644 --- a/verto/VertoExtension.py +++ b/verto/VertoExtension.py @@ -46,7 +46,7 @@ class VertoExtension(Extension): the Verto converter. ''' - def __init__(self, processors=[], html_templates={}, extensions=[], custom_rules={}, *args, **kwargs): + def __init__(self, processors=[], html_templates={}, extensions=[], custom_argument_rules={}, *args, **kwargs): ''' Args: processors: A set of processor names given as strings for which @@ -61,7 +61,7 @@ def __init__(self, processors=[], html_templates={}, extensions=[], custom_rules ''' super().__init__(*args, **kwargs) self.jinja_templates = self.loadJinjaTemplates(html_templates) - self.custom_rules = custom_rules + self.custom_argument_rules = custom_argument_rules self.processor_info = self.loadProcessorInfo() # print(self.processor_info) self.processors = processors @@ -221,8 +221,13 @@ def loadProcessorInfo(self): ''' json_data = pkg_resources.resource_string('verto', 'processor-info.json').decode('utf-8') json_data = json.loads(json_data, object_pairs_hook=OrderedDict) - if len(self.custom_rules) != 0: + if len(self.custom_argument_rules) != 0: self.modify_rules(json_data) + x = json_data["image-container"] + for i in x['arguments']: + print(i) + print(x['arguments']['alt']) + print() return json_data def get_heading_tree(self): @@ -248,7 +253,7 @@ def _set_heading_tree(self, tree): # refactor to modify_required_arguments def modify_rules(self, json_data): - for processor, arguments_to_modify in self.custom_rules.items(): + for processor, arguments_to_modify in self.custom_argument_rules.items(): for argument in arguments_to_modify.items(): new_required = str(argument[1]).lower() json_data[processor]['arguments'][argument[0]]['required'] = new_required diff --git a/verto/processors/utils.py b/verto/processors/utils.py index 9802dc9d..0ef97106 100644 --- a/verto/processors/utils.py +++ b/verto/processors/utils.py @@ -65,8 +65,10 @@ def parse_arguments(processor, inputs, arguments): ArgumentMissingError: If any required arguments are missing or an argument an optional argument is dependent on is missing. ''' + print('parse_arguments') argument_values = defaultdict(None) for argument, argument_info in arguments.items(): + print(argument, argument_info) is_required = argument_info['required'] is_arg = parse_argument(argument, inputs, None) is not None diff --git a/verto/tests/ImageContainerTest.py b/verto/tests/ImageContainerTest.py index 68f1dba4..a19f0665 100644 --- a/verto/tests/ImageContainerTest.py +++ b/verto/tests/ImageContainerTest.py @@ -2,6 +2,7 @@ from unittest.mock import Mock from collections import defaultdict +from verto.Verto import Verto from verto.VertoExtension import VertoExtension from verto.processors.ImageContainerBlockProcessor import ImageContainerBlockProcessor from verto.errors.ImageMissingCaptionError import ImageMissingCaptionError @@ -34,474 +35,502 @@ def __init__(self, *args, **kwargs): self.ext.processor_info = ProcessorTest.loadProcessorInfo(self) self.ext.required_files = defaultdict(set) - def test_caption_true(self): - '''Tests to ensure that caption is rendered correctly and expected images are updated. + def test_custom_arguments_alt_false(self): + '''Tests to ensure that image tag is rendered correctly when alt tag is not required and expected images are updated. ''' - test_string = self.read_test_file(self.processor_name, 'caption_true.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'caption_true_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'cats.png' - } - self.assertSetEqual(expected_images, images) - - def test_caption_false(self): - '''Tests processor does not match image tag when caption argument is not included. - ''' - test_string = self.read_test_file(self.processor_name, 'caption_false.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'caption_false_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - def test_no_caption(self): - '''Tests processor does not match image tag when caption argument is not included. - ''' - test_string = self.read_test_file(self.processor_name, 'no_caption.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'no_caption_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - def test_alt_hover_caption(self): - '''Tests that multiple arguments are rendered correctly when caption argument is included and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'alt_hover_caption.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False, True, False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'alt_hover_caption_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'finite-state-automata-no-trap-example.png', - 'finite-state-automata-trap-added-example.png' - } - self.assertSetEqual(expected_images, images) - - def test_caption_true_not_provided(self): - '''Tests that ImageMissingCaptionError is thrown when caption argument is true but not provided. - ''' - test_string = self.read_test_file(self.processor_name, 'caption_true_not_provided.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - self.assertRaises(ImageMissingCaptionError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - def test_caption_true_missing_end_tag(self): # throw error - '''Tests that TagNotMatchedError is thrown when image tag is missing end tag. - ''' - test_string = self.read_test_file(self.processor_name, 'caption_true_missing_end_tag.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - self.assertRaises(TagNotMatchedError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - def test_caption_true_not_provided_numbered_list(self): - '''Tests that ImageMissingCaptionError is thrown when caption argument is true but not provided in numbered list. - ''' - test_string = self.read_test_file(self.processor_name, 'caption_true_not_provided_numbered_list.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, False, False, True, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - self.assertRaises(ImageMissingCaptionError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - def test_caption_true_numbered_list_missing_end_tag(self): - '''Tests that TagNotMatchedError is thrown when image tag is missing end tag. - ''' - test_string = self.read_test_file(self.processor_name, 'caption_true_numbered_list_missing_end_tag.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, False, False, True, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - self.assertRaises(TagNotMatchedError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - def test_missing_alt_parameter(self): - '''Tests that missing alt argument produces correct error. - ''' - test_string = self.read_test_file(self.processor_name, 'missing_alt_parameter.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - def test_image_in_image_tag(self): - '''Test that ImageCaptionContainsImageError is raised when the first line in an image container block is another image container block. - ''' - test_string = self.read_test_file(self.processor_name, 'image_in_image_tag.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, True, False, True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - self.assertRaises(ImageCaptionContainsImageError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - def test_multiple_images_captions_true(self): - '''Tests to ensure that multiple internally reference images ar rendered correctly and expected images is updated. - ''' - test_string = self.read_test_file(self.processor_name, 'multiple_images_captions_true.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False, True, True, False, True, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'multiple_images_captions_true_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'the-first-image.png', - 'Lipsum.png', - 'pixel-diamond.png' - } - self.assertSetEqual(expected_images, images) - - def test_contains_multiple_images_some_captions(self): - '''Tests to ensure that multiple internally reference images ar rendered correctly and expected images is updated and that images without captions are ignored. - ''' - test_string = self.read_test_file(self.processor_name, 'contains_multiple_images_some_captions.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False, True, False, True, False, True, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'contains_multiple_images_some_captions_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'finite-state-automata-no-trap-example.png', - 'finite-state-automata-trap-added-example.png' - } - self.assertSetEqual(expected_images, images) - - def test_external_image(self): - '''Tests that external images are processed and that the expected images are unchanged. - ''' - test_string = self.read_test_file(self.processor_name, 'external_image.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'external_image_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - def test_contains_hover_text(self): - '''Tests that argument for hover-text produces expected output and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'contains_hover_text.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'contains_hover_text_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' - } - self.assertSetEqual(expected_images, images) - - def test_contains_caption_link(self): - '''Tests that argument for caption-link produces expected output and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'contains_caption_link.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'contains_caption_link_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' - } - self.assertSetEqual(expected_images, images) - - def test_contains_alt(self): - '''Tests that argument for alt produces expected output and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'contains_alt.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'contains_alt_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' - } - self.assertSetEqual(expected_images, images) - - def test_contains_source(self): - '''Tests that argument for source produces expected output and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'contains_source.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'contains_source_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' + custom_argument_rules = { + 'image-container': { + 'alt': False + } } - self.assertSetEqual(expected_images, images) - - def test_align_left(self): - '''Tests that argument for align produces expected output when set to left and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'align_left.md') + test_string = self.read_test_file(self.processor_name, 'alt_false.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + print('here') + verto = Verto(custom_argument_rules=custom_argument_rules) - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'align_left_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' - } - self.assertSetEqual(expected_images, images) - - def test_align_right(self): - '''Tests that argument for align produces expected output when set to right and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'align_right.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'align_right_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' - } - self.assertSetEqual(expected_images, images) - - def test_align_center(self): - '''Tests that argument for align produces expected output when set to center and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'align_center.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'align_center_expected.html', strip=True) + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + converted_test_string = verto.convert(test_string).html_string + expected_string = self.read_test_file(self.processor_name, 'alt_false_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) images = self.verto_extension.required_files['images'] expected_images = { - 'computer-studying-turing-test.png' + 'cats.png' } self.assertSetEqual(expected_images, images) - def test_align_undefined_error(self): - '''Tests that ArgumentValueError is raised when undefined align value is given. - ''' - test_string = self.read_test_file(self.processor_name, 'align_undefined_error.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - def test_image_in_numbered_list(self): - '''Tests that image with in numbered list is rendered correctly and expected images are updated. - ''' - test_string = self.read_test_file(self.processor_name, 'image_in_numbered_list.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, False, False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'image_in_numbered_list_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) - - def test_image_width_value(self): - '''Test image rendered correctly with width value. - ''' - test_string = self.read_test_file(self.processor_name, 'file_width_value.md') - blocks = self.to_blocks(test_string) - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # def test_caption_true(self): + # '''Tests to ensure that caption is rendered correctly and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'caption_true.md') + # blocks = self.to_blocks(test_string) - html_template = self.read_test_file(self.processor_name, 'file_width_value_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'file_width_value_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'caption_true_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - def test_image_width_value_no_units(self): - '''Test image rendered correctly with width value with no units. - ''' - test_string = self.read_test_file(self.processor_name, 'file_width_value_no_units.md') - blocks = self.to_blocks(test_string) + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'cats.png' + # } + # self.assertSetEqual(expected_images, images) - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # def test_caption_false(self): + # '''Tests processor does not match image tag when caption argument is not included. + # ''' + # test_string = self.read_test_file(self.processor_name, 'caption_false.md') + # blocks = self.to_blocks(test_string) - html_template = self.read_test_file(self.processor_name, 'file_width_value_no_units_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'file_width_value_no_units_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # self.assertListEqual([False, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'caption_false_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - def test_image_invalid_width_value_1(self): - '''Test image rendered correctly with width value. - ''' - test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1.md') - blocks = self.to_blocks(test_string) + # def test_no_caption(self): + # '''Tests processor does not match image tag when caption argument is not included. + # ''' + # test_string = self.read_test_file(self.processor_name, 'no_caption.md') + # blocks = self.to_blocks(test_string) - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # self.assertListEqual([False, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'no_caption_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # def test_alt_hover_caption(self): + # '''Tests that multiple arguments are rendered correctly when caption argument is included and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'alt_hover_caption.md') + # blocks = self.to_blocks(test_string) - def test_image_invalid_width_value_2(self): - '''Test image rendered correctly with width value. - ''' - test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2.md') - blocks = self.to_blocks(test_string) + # self.assertListEqual([False, True, False, True, False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'alt_hover_caption_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) - html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'finite-state-automata-no-trap-example.png', + # 'finite-state-automata-trap-added-example.png' + # } + # self.assertSetEqual(expected_images, images) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # def test_caption_true_not_provided(self): + # '''Tests that ImageMissingCaptionError is thrown when caption argument is true but not provided. + # ''' + # test_string = self.read_test_file(self.processor_name, 'caption_true_not_provided.md') + # blocks = self.to_blocks(test_string) - def test_image_width_value_external_image(self): - '''Test image rendered correctly with width value. - ''' - test_string = self.read_test_file(self.processor_name, 'file_width_value_external_image.md') - blocks = self.to_blocks(test_string) + # self.assertListEqual([False, True, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # self.assertRaises(ImageMissingCaptionError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - html_template = self.read_test_file(self.processor_name, 'file_width_value_external_image_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'file_width_value_external_image_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # def test_caption_true_missing_end_tag(self): # throw error + # '''Tests that TagNotMatchedError is thrown when image tag is missing end tag. + # ''' + # test_string = self.read_test_file(self.processor_name, 'caption_true_missing_end_tag.md') + # blocks = self.to_blocks(test_string) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # self.assertListEqual([False, True, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - #~ - # Doc Tests - #~ + # self.assertRaises(TagNotMatchedError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - def test_doc_example_basic(self): - '''Basic example of common usage. - ''' - test_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage.md') - blocks = self.to_blocks(test_string) + # def test_caption_true_not_provided_numbered_list(self): + # '''Tests that ImageMissingCaptionError is thrown when caption argument is true but not provided in numbered list. + # ''' + # test_string = self.read_test_file(self.processor_name, 'caption_true_not_provided_numbered_list.md') + # blocks = self.to_blocks(test_string) - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # self.assertListEqual([False, False, False, True, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) + # self.assertRaises(ImageMissingCaptionError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # def test_caption_true_numbered_list_missing_end_tag(self): + # '''Tests that TagNotMatchedError is thrown when image tag is missing end tag. + # ''' + # test_string = self.read_test_file(self.processor_name, 'caption_true_numbered_list_missing_end_tag.md') + # blocks = self.to_blocks(test_string) - def test_doc_example_override_html(self): - '''Basic example showing how to override the html-template. - ''' - test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') - blocks = self.to_blocks(test_string) + # self.assertListEqual([False, False, False, True, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + # self.assertRaises(TagNotMatchedError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + # def test_missing_alt_parameter(self): + # '''Tests that missing alt argument produces correct error. + # ''' + # test_string = self.read_test_file(self.processor_name, 'missing_alt_parameter.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + # def test_image_in_image_tag(self): + # '''Test that ImageCaptionContainsImageError is raised when the first line in an image container block is another image container block. + # ''' + # test_string = self.read_test_file(self.processor_name, 'image_in_image_tag.md') + # blocks = self.to_blocks(test_string) - html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # self.assertListEqual([True, True, False, True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # self.assertRaises(ImageCaptionContainsImageError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) - - def test_doc_example_2_override_html(self): # TODO check docstring - '''Basic example showing how to override the html-template for relative files in a specific file only. - ''' - test_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - html_template = self.read_test_file(self.processor_name, 'doc_example_2_override_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = self.verto_extension.required_files['images'] - expected_images = set() - self.assertSetEqual(expected_images, images) + # def test_multiple_images_captions_true(self): + # '''Tests to ensure that multiple internally reference images ar rendered correctly and expected images is updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'multiple_images_captions_true.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, True, False, True, True, False, True, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'multiple_images_captions_true_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'the-first-image.png', + # 'Lipsum.png', + # 'pixel-diamond.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_contains_multiple_images_some_captions(self): + # '''Tests to ensure that multiple internally reference images ar rendered correctly and expected images is updated and that images without captions are ignored. + # ''' + # test_string = self.read_test_file(self.processor_name, 'contains_multiple_images_some_captions.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, True, False, True, False, True, False, True, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'contains_multiple_images_some_captions_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'finite-state-automata-no-trap-example.png', + # 'finite-state-automata-trap-added-example.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_external_image(self): + # '''Tests that external images are processed and that the expected images are unchanged. + # ''' + # test_string = self.read_test_file(self.processor_name, 'external_image.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'external_image_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # def test_contains_hover_text(self): + # '''Tests that argument for hover-text produces expected output and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'contains_hover_text.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'contains_hover_text_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'computer-studying-turing-test.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_contains_caption_link(self): + # '''Tests that argument for caption-link produces expected output and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'contains_caption_link.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'contains_caption_link_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'computer-studying-turing-test.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_contains_alt(self): + # '''Tests that argument for alt produces expected output and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'contains_alt.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'contains_alt_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'computer-studying-turing-test.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_contains_source(self): + # '''Tests that argument for source produces expected output and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'contains_source.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'contains_source_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'computer-studying-turing-test.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_align_left(self): + # '''Tests that argument for align produces expected output when set to left and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'align_left.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'align_left_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'computer-studying-turing-test.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_align_right(self): + # '''Tests that argument for align produces expected output when set to right and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'align_right.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'align_right_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'computer-studying-turing-test.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_align_center(self): + # '''Tests that argument for align produces expected output when set to center and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'align_center.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'align_center_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = { + # 'computer-studying-turing-test.png' + # } + # self.assertSetEqual(expected_images, images) + + # def test_align_undefined_error(self): + # '''Tests that ArgumentValueError is raised when undefined align value is given. + # ''' + # test_string = self.read_test_file(self.processor_name, 'align_undefined_error.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + # def test_image_in_numbered_list(self): + # '''Tests that image with in numbered list is rendered correctly and expected images are updated. + # ''' + # test_string = self.read_test_file(self.processor_name, 'image_in_numbered_list.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, False, False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'image_in_numbered_list_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) + + # def test_image_width_value(self): + # '''Test image rendered correctly with width value. + # ''' + # test_string = self.read_test_file(self.processor_name, 'file_width_value.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # html_template = self.read_test_file(self.processor_name, 'file_width_value_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'file_width_value_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) + + # def test_image_width_value_no_units(self): + # '''Test image rendered correctly with width value with no units. + # ''' + # test_string = self.read_test_file(self.processor_name, 'file_width_value_no_units.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # html_template = self.read_test_file(self.processor_name, 'file_width_value_no_units_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'file_width_value_no_units_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) + + # def test_image_invalid_width_value_1(self): + # '''Test image rendered correctly with width value. + # ''' + # test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) + + # def test_image_invalid_width_value_2(self): + # '''Test image rendered correctly with width value. + # ''' + # test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) + + # def test_image_width_value_external_image(self): + # '''Test image rendered correctly with width value. + # ''' + # test_string = self.read_test_file(self.processor_name, 'file_width_value_external_image.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # html_template = self.read_test_file(self.processor_name, 'file_width_value_external_image_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'file_width_value_external_image_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) + + # #~ + # # Doc Tests + # #~ + + # def test_doc_example_basic(self): + # '''Basic example of common usage. + # ''' + # test_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) + + # def test_doc_example_override_html(self): + # '''Basic example showing how to override the html-template. + # ''' + # test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) + + # def test_doc_example_2_override_html(self): # TODO check docstring + # '''Basic example showing how to override the html-template for relative files in a specific file only. + # ''' + # test_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # html_template = self.read_test_file(self.processor_name, 'doc_example_2_override_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # images = self.verto_extension.required_files['images'] + # expected_images = set() + # self.assertSetEqual(expected_images, images) diff --git a/verto/tests/assets/image-container/alt_false.md b/verto/tests/assets/image-container/alt_false.md new file mode 100644 index 00000000..d98fe8cb --- /dev/null +++ b/verto/tests/assets/image-container/alt_false.md @@ -0,0 +1,11 @@ +Here's another FSA to consider: + +{image file-path="cats.png" caption="true"} + +This is a caption. + +{image end} + +It's fairly clear what it will accept: strings like "ab", "abab", "abababababab", and, of course {math}\epsilon{math end}. +But there are some missing transitions: if you are in state 1 and get a "b" there's nowhere to go. +If an input cannot be accepted, it will be rejected, as in this case. We could have put in a trap state to make this clear: diff --git a/verto/tests/assets/image-container/alt_false_expected.html b/verto/tests/assets/image-container/alt_false_expected.html new file mode 100644 index 00000000..407dcc1e --- /dev/null +++ b/verto/tests/assets/image-container/alt_false_expected.html @@ -0,0 +1,8 @@ +

    Here's another FSA to consider:

    +
    + +

    This is a caption.

    +
    +

    It's fairly clear what it will accept: strings like "ab", "abab", "abababababab", and, of course {math}\epsilon{math end}. +But there are some missing transitions: if you are in state 1 and get a "b" there's nowhere to go. +If an input cannot be accepted, it will be rejected, as in this case. We could have put in a trap state to make this clear:

    diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 5cfc39b3..1c867357 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -85,31 +85,31 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - unittest.makeSuite(BoxedTextTest), - unittest.makeSuite(ButtonLinkTest), - unittest.makeSuite(CommentTest), - unittest.makeSuite(ConditionalTest), - unittest.makeSuite(FrameTest), - unittest.makeSuite(GlossaryLinkTest), - unittest.makeSuite(HeadingTest), - unittest.makeSuite(ImageInlineTest), - unittest.makeSuite(ImageTagTest), + # unittest.makeSuite(BoxedTextTest), + # unittest.makeSuite(ButtonLinkTest), + # unittest.makeSuite(CommentTest), + # unittest.makeSuite(ConditionalTest), + # unittest.makeSuite(FrameTest), + # unittest.makeSuite(GlossaryLinkTest), + # unittest.makeSuite(HeadingTest), + # unittest.makeSuite(ImageInlineTest), + # unittest.makeSuite(ImageTagTest), unittest.makeSuite(ImageContainerTest), - unittest.makeSuite(InteractiveTest), - unittest.makeSuite(JinjaTest), - unittest.makeSuite(PanelTest), - unittest.makeSuite(SaveTitleTest), - unittest.makeSuite(ScratchTest), - unittest.makeSuite(ScratchInlineTest), - unittest.makeSuite(StyleTest), - unittest.makeSuite(RelativeLinkTest), - unittest.makeSuite(RemoveTest), - unittest.makeSuite(RemoveTitleTest), - unittest.makeSuite(TableOfContentsTest), - unittest.makeSuite(VideoTest), - - unittest.makeSuite(HtmlParserTest), - unittest.makeSuite(MarkdownOverrideTest), + # unittest.makeSuite(InteractiveTest), + # unittest.makeSuite(JinjaTest), + # unittest.makeSuite(PanelTest), + # unittest.makeSuite(SaveTitleTest), + # unittest.makeSuite(ScratchTest), + # unittest.makeSuite(ScratchInlineTest), + # unittest.makeSuite(StyleTest), + # unittest.makeSuite(RelativeLinkTest), + # unittest.makeSuite(RemoveTest), + # unittest.makeSuite(RemoveTitleTest), + # unittest.makeSuite(TableOfContentsTest), + # unittest.makeSuite(VideoTest), + + # unittest.makeSuite(HtmlParserTest), + # unittest.makeSuite(MarkdownOverrideTest), )) From 3f3df9625dfbcb00731fb6aca6957d79a5b0a611 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Sun, 8 Jul 2018 22:37:51 +1200 Subject: [PATCH 35/73] worked out the bug, left note on idea for how to solve --- verto/VertoExtension.py | 8 ++++---- verto/processors/utils.py | 7 +++++-- verto/tests/ImageContainerTest.py | 5 +++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/verto/VertoExtension.py b/verto/VertoExtension.py index 3e862112..90302993 100644 --- a/verto/VertoExtension.py +++ b/verto/VertoExtension.py @@ -224,10 +224,10 @@ def loadProcessorInfo(self): if len(self.custom_argument_rules) != 0: self.modify_rules(json_data) x = json_data["image-container"] - for i in x['arguments']: - print(i) - print(x['arguments']['alt']) - print() + # for i in x['arguments']: + # print(i) + # print(x['arguments']['alt']) + # print() return json_data def get_heading_tree(self): diff --git a/verto/processors/utils.py b/verto/processors/utils.py index 0ef97106..cc85141a 100644 --- a/verto/processors/utils.py +++ b/verto/processors/utils.py @@ -65,14 +65,16 @@ def parse_arguments(processor, inputs, arguments): ArgumentMissingError: If any required arguments are missing or an argument an optional argument is dependent on is missing. ''' - print('parse_arguments') argument_values = defaultdict(None) for argument, argument_info in arguments.items(): - print(argument, argument_info) is_required = argument_info['required'] is_arg = parse_argument(argument, inputs, None) is not None + print('cats') + print(argument, argument_info) + print(is_required, is_arg) # false, false if is_required and not is_arg: + print('ducks') raise ArgumentMissingError(processor, argument, '{} is a required argument.'.format(argument)) elif not is_required and is_arg: dependencies = argument_info.get('dependencies', []) @@ -80,6 +82,7 @@ def parse_arguments(processor, inputs, arguments): if (parse_argument(other_argument, inputs, None) is None and parse_flag(other_argument, inputs, None) is None): message = '{} is a required argument because {} exists.'.format(other_argument, argument) + print('dogs') raise ArgumentMissingError(processor, argument, message) if is_arg: diff --git a/verto/tests/ImageContainerTest.py b/verto/tests/ImageContainerTest.py index a19f0665..6512ec13 100644 --- a/verto/tests/ImageContainerTest.py +++ b/verto/tests/ImageContainerTest.py @@ -38,9 +38,11 @@ def __init__(self, *args, **kwargs): def test_custom_arguments_alt_false(self): '''Tests to ensure that image tag is rendered correctly when alt tag is not required and expected images are updated. ''' + # WIP problem is with defining the booleon values + # this could be it's own json file? custom_argument_rules = { 'image-container': { - 'alt': False + 'alt': false } } test_string = self.read_test_file(self.processor_name, 'alt_false.md') @@ -51,7 +53,6 @@ def test_custom_arguments_alt_false(self): self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) converted_test_string = verto.convert(test_string).html_string expected_string = self.read_test_file(self.processor_name, 'alt_false_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) From bc05f355cb6d087668773cbb5318243b85a5daa2 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Mon, 9 Jul 2018 18:07:08 +1200 Subject: [PATCH 36/73] Update setuptools from 39.2.0 to 40.0.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 42b1452f..7bd722fb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ markdown==2.6.11 Jinja2==2.10 python-slugify==1.2.5 -setuptools==39.2.0 +setuptools==40.0.0 # Required dependencies for building documentation sphinx==1.7.5 From 09b08a1abc50f6a422ea00124784097b32a44216 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 16 Jul 2018 10:01:08 +1200 Subject: [PATCH 37/73] Now loads a json file for custom rules --- verto/VertoExtension.py | 3 +-- verto/processors/utils.py | 7 ++++--- verto/tests/ImageContainerTest.py | 20 ++++++++++++------- .../alt_false_custom_argument_rules.json | 5 +++++ 4 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 verto/tests/assets/image-container/alt_false_custom_argument_rules.json diff --git a/verto/VertoExtension.py b/verto/VertoExtension.py index 90302993..473a3cf0 100644 --- a/verto/VertoExtension.py +++ b/verto/VertoExtension.py @@ -255,7 +255,6 @@ def _set_heading_tree(self, tree): def modify_rules(self, json_data): for processor, arguments_to_modify in self.custom_argument_rules.items(): for argument in arguments_to_modify.items(): - new_required = str(argument[1]).lower() + new_required = str(argument[1]) # .lower() json_data[processor]['arguments'][argument[0]]['required'] = new_required return json_data - diff --git a/verto/processors/utils.py b/verto/processors/utils.py index cc85141a..49e3b281 100644 --- a/verto/processors/utils.py +++ b/verto/processors/utils.py @@ -68,12 +68,13 @@ def parse_arguments(processor, inputs, arguments): argument_values = defaultdict(None) for argument, argument_info in arguments.items(): is_required = argument_info['required'] - is_arg = parse_argument(argument, inputs, None) is not None + is_arg = parse_argument(argument, inputs, None) is not None # True if in line print('cats') print(argument, argument_info) - print(is_required, is_arg) # false, false + print(is_required, is_arg) # false, false + print(not is_arg) # False means was in line - if is_required and not is_arg: + if is_required and not is_arg: # false print('ducks') raise ArgumentMissingError(processor, argument, '{} is a required argument.'.format(argument)) elif not is_required and is_arg: diff --git a/verto/tests/ImageContainerTest.py b/verto/tests/ImageContainerTest.py index 6512ec13..87dca8d4 100644 --- a/verto/tests/ImageContainerTest.py +++ b/verto/tests/ImageContainerTest.py @@ -1,6 +1,9 @@ import markdown from unittest.mock import Mock -from collections import defaultdict +from collections import defaultdict, OrderedDict +import json +import pkg_resources +import os.path from verto.Verto import Verto from verto.VertoExtension import VertoExtension @@ -40,15 +43,18 @@ def test_custom_arguments_alt_false(self): ''' # WIP problem is with defining the booleon values # this could be it's own json file? - custom_argument_rules = { - 'image-container': { - 'alt': false - } - } + # custom_argument_rules = { + # 'image-container': { + # 'alt': false + # } + # } + # custom_argument_rules_path = os.path.join(os.path.dirname(__file__), 'verto/tests/assets/image-container/alt_false_custom_argument_rules.json') + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/alt_false_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + # custom_argument_rules = json.loads(custom_argument_rules_path, object_pairs_hook=OrderedDict) test_string = self.read_test_file(self.processor_name, 'alt_false.md') blocks = self.to_blocks(test_string) - print('here') verto = Verto(custom_argument_rules=custom_argument_rules) self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) diff --git a/verto/tests/assets/image-container/alt_false_custom_argument_rules.json b/verto/tests/assets/image-container/alt_false_custom_argument_rules.json new file mode 100644 index 00000000..5772d7eb --- /dev/null +++ b/verto/tests/assets/image-container/alt_false_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "image-container": { + "alt": false + } +} From c2ca862ea3e1a2aa7895360568706a4c38c4000e Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 17 Jul 2018 10:59:33 +1200 Subject: [PATCH 38/73] Woohoo! Got it working! --- verto/VertoExtension.py | 8 +------- verto/processors/utils.py | 8 +------- verto/tests/ImageContainerTest.py | 20 +++++++------------- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/verto/VertoExtension.py b/verto/VertoExtension.py index 473a3cf0..d115cf20 100644 --- a/verto/VertoExtension.py +++ b/verto/VertoExtension.py @@ -63,7 +63,6 @@ def __init__(self, processors=[], html_templates={}, extensions=[], custom_argum self.jinja_templates = self.loadJinjaTemplates(html_templates) self.custom_argument_rules = custom_argument_rules self.processor_info = self.loadProcessorInfo() - # print(self.processor_info) self.processors = processors self.title = None self.heading_tree = None @@ -223,11 +222,6 @@ def loadProcessorInfo(self): json_data = json.loads(json_data, object_pairs_hook=OrderedDict) if len(self.custom_argument_rules) != 0: self.modify_rules(json_data) - x = json_data["image-container"] - # for i in x['arguments']: - # print(i) - # print(x['arguments']['alt']) - # print() return json_data def get_heading_tree(self): @@ -255,6 +249,6 @@ def _set_heading_tree(self, tree): def modify_rules(self, json_data): for processor, arguments_to_modify in self.custom_argument_rules.items(): for argument in arguments_to_modify.items(): - new_required = str(argument[1]) # .lower() + new_required = argument[1] # .lower() json_data[processor]['arguments'][argument[0]]['required'] = new_required return json_data diff --git a/verto/processors/utils.py b/verto/processors/utils.py index 49e3b281..bb582d38 100644 --- a/verto/processors/utils.py +++ b/verto/processors/utils.py @@ -69,13 +69,8 @@ def parse_arguments(processor, inputs, arguments): for argument, argument_info in arguments.items(): is_required = argument_info['required'] is_arg = parse_argument(argument, inputs, None) is not None # True if in line - print('cats') - print(argument, argument_info) - print(is_required, is_arg) # false, false - print(not is_arg) # False means was in line - if is_required and not is_arg: # false - print('ducks') + if is_required and not is_arg: # required argument and not in line raise ArgumentMissingError(processor, argument, '{} is a required argument.'.format(argument)) elif not is_required and is_arg: dependencies = argument_info.get('dependencies', []) @@ -83,7 +78,6 @@ def parse_arguments(processor, inputs, arguments): if (parse_argument(other_argument, inputs, None) is None and parse_flag(other_argument, inputs, None) is None): message = '{} is a required argument because {} exists.'.format(other_argument, argument) - print('dogs') raise ArgumentMissingError(processor, argument, message) if is_arg: diff --git a/verto/tests/ImageContainerTest.py b/verto/tests/ImageContainerTest.py index 87dca8d4..072d2824 100644 --- a/verto/tests/ImageContainerTest.py +++ b/verto/tests/ImageContainerTest.py @@ -41,29 +41,23 @@ def __init__(self, *args, **kwargs): def test_custom_arguments_alt_false(self): '''Tests to ensure that image tag is rendered correctly when alt tag is not required and expected images are updated. ''' - # WIP problem is with defining the booleon values - # this could be it's own json file? - # custom_argument_rules = { - # 'image-container': { - # 'alt': false - # } - # } - # custom_argument_rules_path = os.path.join(os.path.dirname(__file__), 'verto/tests/assets/image-container/alt_false_custom_argument_rules.json') json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/alt_false_custom_argument_rules.json').decode('utf-8') custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) - # custom_argument_rules = json.loads(custom_argument_rules_path, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + test_string = self.read_test_file(self.processor_name, 'alt_false.md') blocks = self.to_blocks(test_string) - verto = Verto(custom_argument_rules=custom_argument_rules) - self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - converted_test_string = verto.convert(test_string).html_string + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) expected_string = self.read_test_file(self.processor_name, 'alt_false_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - images = self.verto_extension.required_files['images'] + images = verto_extension_custom_rules.required_files['images'] expected_images = { 'cats.png' } From fbcc61a77c19cfbebf0cf7785d35e1064add037f Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Tue, 17 Jul 2018 10:59:54 +1200 Subject: [PATCH 39/73] Update sphinx from 1.7.5 to 1.7.6 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 42b1452f..b1574487 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ python-slugify==1.2.5 setuptools==39.2.0 # Required dependencies for building documentation -sphinx==1.7.5 +sphinx==1.7.6 sphinx_rtd_theme==0.4.0 From 27de25fe928f73c406882d48e57168ab264f77e7 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 17 Jul 2018 11:50:45 +1200 Subject: [PATCH 40/73] Added tests for custom rules for image container --- verto/tests/ImageContainerTest.py | 956 ++++++++++-------- .../image-container/alt_false_source_true.md | 11 + ...lse_source_true_custom_argument_rules.json | 6 + .../alt_false_source_true_expected.html | 9 + .../assets/image-container/hover_true.md | 5 + .../hover_true_custom_argument_rules.json | 5 + .../image-container/hover_true_expected.html | 4 + .../hover_true_not_provided.md | 5 + 8 files changed, 555 insertions(+), 446 deletions(-) create mode 100644 verto/tests/assets/image-container/alt_false_source_true.md create mode 100644 verto/tests/assets/image-container/alt_false_source_true_custom_argument_rules.json create mode 100644 verto/tests/assets/image-container/alt_false_source_true_expected.html create mode 100644 verto/tests/assets/image-container/hover_true.md create mode 100644 verto/tests/assets/image-container/hover_true_custom_argument_rules.json create mode 100644 verto/tests/assets/image-container/hover_true_expected.html create mode 100644 verto/tests/assets/image-container/hover_true_not_provided.md diff --git a/verto/tests/ImageContainerTest.py b/verto/tests/ImageContainerTest.py index 072d2824..e59d05b1 100644 --- a/verto/tests/ImageContainerTest.py +++ b/verto/tests/ImageContainerTest.py @@ -3,9 +3,7 @@ from collections import defaultdict, OrderedDict import json import pkg_resources -import os.path -from verto.Verto import Verto from verto.VertoExtension import VertoExtension from verto.processors.ImageContainerBlockProcessor import ImageContainerBlockProcessor from verto.errors.ImageMissingCaptionError import ImageMissingCaptionError @@ -63,475 +61,541 @@ def test_custom_arguments_alt_false(self): } self.assertSetEqual(expected_images, images) + def test_custom_arguments_hover_true(self): + '''Tests to ensure that image tag is rendered correctly when hover argument is required and expected images are updated. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/hover_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) - # def test_caption_true(self): - # '''Tests to ensure that caption is rendered correctly and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'caption_true.md') - # blocks = self.to_blocks(test_string) + test_string = self.read_test_file(self.processor_name, 'hover_true.md') + blocks = self.to_blocks(test_string) - # self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'caption_true_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'hover_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = verto_extension_custom_rules.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_custom_arguments_alt_false_source_true(self): + '''Tests to ensure that image tag is rendered correctly when alt argument is not required and source argument is true expected images are updated. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/alt_false_source_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'alt_false_source_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'alt_false_source_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = verto_extension_custom_rules.required_files['images'] + expected_images = { + 'cats.png' + } + self.assertSetEqual(expected_images, images) - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'cats.png' - # } - # self.assertSetEqual(expected_images, images) + def test_custom_arguments_hover_true_not_provided(self): + '''Tests to ensure that image tag is rendered correctly when alt tag is not required and expected images are updated. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/hover_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) - # def test_caption_false(self): - # '''Tests processor does not match image tag when caption argument is not included. - # ''' - # test_string = self.read_test_file(self.processor_name, 'caption_false.md') - # blocks = self.to_blocks(test_string) + test_string = self.read_test_file(self.processor_name, 'hover_true_not_provided.md') + blocks = self.to_blocks(test_string) - # self.assertListEqual([False, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'caption_false_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) - # def test_no_caption(self): - # '''Tests processor does not match image tag when caption argument is not included. - # ''' - # test_string = self.read_test_file(self.processor_name, 'no_caption.md') - # blocks = self.to_blocks(test_string) + def test_caption_true(self): + '''Tests to ensure that caption is rendered correctly and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'caption_true.md') + blocks = self.to_blocks(test_string) - # self.assertListEqual([False, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'no_caption_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'caption_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_alt_hover_caption(self): - # '''Tests that multiple arguments are rendered correctly when caption argument is included and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'alt_hover_caption.md') - # blocks = self.to_blocks(test_string) + images = self.verto_extension.required_files['images'] + expected_images = { + 'cats.png' + } + self.assertSetEqual(expected_images, images) - # self.assertListEqual([False, True, False, True, False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + def test_caption_false(self): + '''Tests processor does not match image tag when caption argument is not included. + ''' + test_string = self.read_test_file(self.processor_name, 'caption_false.md') + blocks = self.to_blocks(test_string) - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'alt_hover_caption_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + self.assertListEqual([False, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'finite-state-automata-no-trap-example.png', - # 'finite-state-automata-trap-added-example.png' - # } - # self.assertSetEqual(expected_images, images) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'caption_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_caption_true_not_provided(self): - # '''Tests that ImageMissingCaptionError is thrown when caption argument is true but not provided. - # ''' - # test_string = self.read_test_file(self.processor_name, 'caption_true_not_provided.md') - # blocks = self.to_blocks(test_string) + def test_no_caption(self): + '''Tests processor does not match image tag when caption argument is not included. + ''' + test_string = self.read_test_file(self.processor_name, 'no_caption.md') + blocks = self.to_blocks(test_string) - # self.assertListEqual([False, True, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # self.assertRaises(ImageMissingCaptionError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'no_caption_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_caption_true_missing_end_tag(self): # throw error - # '''Tests that TagNotMatchedError is thrown when image tag is missing end tag. - # ''' - # test_string = self.read_test_file(self.processor_name, 'caption_true_missing_end_tag.md') - # blocks = self.to_blocks(test_string) + def test_alt_hover_caption(self): + '''Tests that multiple arguments are rendered correctly when caption argument is included and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'alt_hover_caption.md') + blocks = self.to_blocks(test_string) - # self.assertListEqual([False, True, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, True, False, True, False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # self.assertRaises(TagNotMatchedError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'alt_hover_caption_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_caption_true_not_provided_numbered_list(self): - # '''Tests that ImageMissingCaptionError is thrown when caption argument is true but not provided in numbered list. - # ''' - # test_string = self.read_test_file(self.processor_name, 'caption_true_not_provided_numbered_list.md') - # blocks = self.to_blocks(test_string) + images = self.verto_extension.required_files['images'] + expected_images = { + 'finite-state-automata-no-trap-example.png', + 'finite-state-automata-trap-added-example.png' + } + self.assertSetEqual(expected_images, images) - # self.assertListEqual([False, False, False, True, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + def test_caption_true_not_provided(self): + '''Tests that ImageMissingCaptionError is thrown when caption argument is true but not provided. + ''' + test_string = self.read_test_file(self.processor_name, 'caption_true_not_provided.md') + blocks = self.to_blocks(test_string) - # self.assertRaises(ImageMissingCaptionError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + self.assertListEqual([False, True, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # def test_caption_true_numbered_list_missing_end_tag(self): - # '''Tests that TagNotMatchedError is thrown when image tag is missing end tag. - # ''' - # test_string = self.read_test_file(self.processor_name, 'caption_true_numbered_list_missing_end_tag.md') - # blocks = self.to_blocks(test_string) + self.assertRaises(ImageMissingCaptionError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - # self.assertListEqual([False, False, False, True, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + def test_caption_true_missing_end_tag(self): # throw error + '''Tests that TagNotMatchedError is thrown when image tag is missing end tag. + ''' + test_string = self.read_test_file(self.processor_name, 'caption_true_missing_end_tag.md') + blocks = self.to_blocks(test_string) - # self.assertRaises(TagNotMatchedError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - # def test_missing_alt_parameter(self): - # '''Tests that missing alt argument produces correct error. - # ''' - # test_string = self.read_test_file(self.processor_name, 'missing_alt_parameter.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - # def test_image_in_image_tag(self): - # '''Test that ImageCaptionContainsImageError is raised when the first line in an image container block is another image container block. - # ''' - # test_string = self.read_test_file(self.processor_name, 'image_in_image_tag.md') - # blocks = self.to_blocks(test_string) + self.assertListEqual([False, True, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # self.assertListEqual([True, True, False, True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # self.assertRaises(ImageCaptionContainsImageError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + self.assertRaises(TagNotMatchedError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - # def test_multiple_images_captions_true(self): - # '''Tests to ensure that multiple internally reference images ar rendered correctly and expected images is updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'multiple_images_captions_true.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([False, True, False, True, True, False, True, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'multiple_images_captions_true_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'the-first-image.png', - # 'Lipsum.png', - # 'pixel-diamond.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_contains_multiple_images_some_captions(self): - # '''Tests to ensure that multiple internally reference images ar rendered correctly and expected images is updated and that images without captions are ignored. - # ''' - # test_string = self.read_test_file(self.processor_name, 'contains_multiple_images_some_captions.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([False, True, False, True, False, True, False, True, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'contains_multiple_images_some_captions_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'finite-state-automata-no-trap-example.png', - # 'finite-state-automata-trap-added-example.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_external_image(self): - # '''Tests that external images are processed and that the expected images are unchanged. - # ''' - # test_string = self.read_test_file(self.processor_name, 'external_image.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'external_image_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # def test_contains_hover_text(self): - # '''Tests that argument for hover-text produces expected output and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'contains_hover_text.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'contains_hover_text_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'computer-studying-turing-test.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_contains_caption_link(self): - # '''Tests that argument for caption-link produces expected output and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'contains_caption_link.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'contains_caption_link_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'computer-studying-turing-test.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_contains_alt(self): - # '''Tests that argument for alt produces expected output and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'contains_alt.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'contains_alt_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'computer-studying-turing-test.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_contains_source(self): - # '''Tests that argument for source produces expected output and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'contains_source.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'contains_source_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'computer-studying-turing-test.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_align_left(self): - # '''Tests that argument for align produces expected output when set to left and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'align_left.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'align_left_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'computer-studying-turing-test.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_align_right(self): - # '''Tests that argument for align produces expected output when set to right and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'align_right.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'align_right_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'computer-studying-turing-test.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_align_center(self): - # '''Tests that argument for align produces expected output when set to center and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'align_center.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'align_center_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = { - # 'computer-studying-turing-test.png' - # } - # self.assertSetEqual(expected_images, images) - - # def test_align_undefined_error(self): - # '''Tests that ArgumentValueError is raised when undefined align value is given. - # ''' - # test_string = self.read_test_file(self.processor_name, 'align_undefined_error.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - # def test_image_in_numbered_list(self): - # '''Tests that image with in numbered list is rendered correctly and expected images are updated. - # ''' - # test_string = self.read_test_file(self.processor_name, 'image_in_numbered_list.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([False, False, False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'image_in_numbered_list_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) - - # def test_image_width_value(self): - # '''Test image rendered correctly with width value. - # ''' - # test_string = self.read_test_file(self.processor_name, 'file_width_value.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # html_template = self.read_test_file(self.processor_name, 'file_width_value_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'file_width_value_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) - - # def test_image_width_value_no_units(self): - # '''Test image rendered correctly with width value with no units. - # ''' - # test_string = self.read_test_file(self.processor_name, 'file_width_value_no_units.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # html_template = self.read_test_file(self.processor_name, 'file_width_value_no_units_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'file_width_value_no_units_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) - - # def test_image_invalid_width_value_1(self): - # '''Test image rendered correctly with width value. - # ''' - # test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) - - # def test_image_invalid_width_value_2(self): - # '''Test image rendered correctly with width value. - # ''' - # test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) - - # def test_image_width_value_external_image(self): - # '''Test image rendered correctly with width value. - # ''' - # test_string = self.read_test_file(self.processor_name, 'file_width_value_external_image.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # html_template = self.read_test_file(self.processor_name, 'file_width_value_external_image_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'file_width_value_external_image_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) - - # #~ - # # Doc Tests - # #~ - - # def test_doc_example_basic(self): - # '''Basic example of common usage. - # ''' - # test_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) - - # def test_doc_example_override_html(self): - # '''Basic example showing how to override the html-template. - # ''' - # test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) - - # def test_doc_example_2_override_html(self): # TODO check docstring - # '''Basic example showing how to override the html-template for relative files in a specific file only. - # ''' - # test_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # html_template = self.read_test_file(self.processor_name, 'doc_example_2_override_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) - - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # images = self.verto_extension.required_files['images'] - # expected_images = set() - # self.assertSetEqual(expected_images, images) + def test_caption_true_not_provided_numbered_list(self): + '''Tests that ImageMissingCaptionError is thrown when caption argument is true but not provided in numbered list. + ''' + test_string = self.read_test_file(self.processor_name, 'caption_true_not_provided_numbered_list.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, False, False, True, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ImageMissingCaptionError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + def test_caption_true_numbered_list_missing_end_tag(self): + '''Tests that TagNotMatchedError is thrown when image tag is missing end tag. + ''' + test_string = self.read_test_file(self.processor_name, 'caption_true_numbered_list_missing_end_tag.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, False, False, True, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(TagNotMatchedError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + def test_missing_alt_parameter(self): + '''Tests that missing alt argument produces correct error. + ''' + test_string = self.read_test_file(self.processor_name, 'missing_alt_parameter.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + def test_image_in_image_tag(self): + '''Test that ImageCaptionContainsImageError is raised when the first line in an image container block is another image container block. + ''' + test_string = self.read_test_file(self.processor_name, 'image_in_image_tag.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, True, False, True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ImageCaptionContainsImageError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + def test_multiple_images_captions_true(self): + '''Tests to ensure that multiple internally reference images ar rendered correctly and expected images is updated. + ''' + test_string = self.read_test_file(self.processor_name, 'multiple_images_captions_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False, True, True, False, True, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'multiple_images_captions_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'the-first-image.png', + 'Lipsum.png', + 'pixel-diamond.png' + } + self.assertSetEqual(expected_images, images) + + def test_contains_multiple_images_some_captions(self): + '''Tests to ensure that multiple internally reference images ar rendered correctly and expected images is updated and that images without captions are ignored. + ''' + test_string = self.read_test_file(self.processor_name, 'contains_multiple_images_some_captions.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False, True, False, True, False, True, False, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'contains_multiple_images_some_captions_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'finite-state-automata-no-trap-example.png', + 'finite-state-automata-trap-added-example.png' + } + self.assertSetEqual(expected_images, images) + + def test_external_image(self): + '''Tests that external images are processed and that the expected images are unchanged. + ''' + test_string = self.read_test_file(self.processor_name, 'external_image.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'external_image_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_contains_hover_text(self): + '''Tests that argument for hover-text produces expected output and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'contains_hover_text.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'contains_hover_text_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_contains_caption_link(self): + '''Tests that argument for caption-link produces expected output and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'contains_caption_link.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'contains_caption_link_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_contains_alt(self): + '''Tests that argument for alt produces expected output and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'contains_alt.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'contains_alt_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_contains_source(self): + '''Tests that argument for source produces expected output and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'contains_source.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'contains_source_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_align_left(self): + '''Tests that argument for align produces expected output when set to left and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'align_left.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'align_left_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_align_right(self): + '''Tests that argument for align produces expected output when set to right and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'align_right.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'align_right_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_align_center(self): + '''Tests that argument for align produces expected output when set to center and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'align_center.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'align_center_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_align_undefined_error(self): + '''Tests that ArgumentValueError is raised when undefined align value is given. + ''' + test_string = self.read_test_file(self.processor_name, 'align_undefined_error.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + def test_image_in_numbered_list(self): + '''Tests that image with in numbered list is rendered correctly and expected images are updated. + ''' + test_string = self.read_test_file(self.processor_name, 'image_in_numbered_list.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, False, False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'image_in_numbered_list_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) + + def test_image_width_value(self): + '''Test image rendered correctly with width value. + ''' + test_string = self.read_test_file(self.processor_name, 'file_width_value.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + html_template = self.read_test_file(self.processor_name, 'file_width_value_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'file_width_value_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) + + def test_image_width_value_no_units(self): + '''Test image rendered correctly with width value with no units. + ''' + test_string = self.read_test_file(self.processor_name, 'file_width_value_no_units.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + html_template = self.read_test_file(self.processor_name, 'file_width_value_no_units_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'file_width_value_no_units_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) + + def test_image_invalid_width_value_1(self): + '''Test image rendered correctly with width value. + ''' + test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) + + def test_image_invalid_width_value_2(self): + '''Test image rendered correctly with width value. + ''' + test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + html_template = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) + + def test_image_width_value_external_image(self): + '''Test image rendered correctly with width value. + ''' + test_string = self.read_test_file(self.processor_name, 'file_width_value_external_image.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + html_template = self.read_test_file(self.processor_name, 'file_width_value_external_image_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'file_width_value_external_image_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) + + #~ + # Doc Tests + #~ + + def test_doc_example_basic(self): + '''Basic example of common usage. + ''' + test_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) + + def test_doc_example_override_html(self): + '''Basic example showing how to override the html-template. + ''' + test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) + + def test_doc_example_2_override_html(self): # TODO check docstring + '''Basic example showing how to override the html-template for relative files in a specific file only. + ''' + test_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + html_template = self.read_test_file(self.processor_name, 'doc_example_2_override_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'doc_example_2_override_html_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = self.verto_extension.required_files['images'] + expected_images = set() + self.assertSetEqual(expected_images, images) diff --git a/verto/tests/assets/image-container/alt_false_source_true.md b/verto/tests/assets/image-container/alt_false_source_true.md new file mode 100644 index 00000000..0f6519a0 --- /dev/null +++ b/verto/tests/assets/image-container/alt_false_source_true.md @@ -0,0 +1,11 @@ +Here's another FSA to consider: + +{image file-path="cats.png" caption="true" source="source.com"} + +This is a caption. + +{image end} + +It's fairly clear what it will accept: strings like "ab", "abab", "abababababab", and, of course {math}\epsilon{math end}. +But there are some missing transitions: if you are in state 1 and get a "b" there's nowhere to go. +If an input cannot be accepted, it will be rejected, as in this case. We could have put in a trap state to make this clear: diff --git a/verto/tests/assets/image-container/alt_false_source_true_custom_argument_rules.json b/verto/tests/assets/image-container/alt_false_source_true_custom_argument_rules.json new file mode 100644 index 00000000..e6e6b066 --- /dev/null +++ b/verto/tests/assets/image-container/alt_false_source_true_custom_argument_rules.json @@ -0,0 +1,6 @@ +{ + "image-container": { + "alt": false, + "source": true + } +} diff --git a/verto/tests/assets/image-container/alt_false_source_true_expected.html b/verto/tests/assets/image-container/alt_false_source_true_expected.html new file mode 100644 index 00000000..09f3c378 --- /dev/null +++ b/verto/tests/assets/image-container/alt_false_source_true_expected.html @@ -0,0 +1,9 @@ +

    Here's another FSA to consider:

    +
    + +

    This is a caption.

    +

    Source

    +
    +

    It's fairly clear what it will accept: strings like "ab", "abab", "abababababab", and, of course {math}\epsilon{math end}. +But there are some missing transitions: if you are in state 1 and get a "b" there's nowhere to go. +If an input cannot be accepted, it will be rejected, as in this case. We could have put in a trap state to make this clear:

    diff --git a/verto/tests/assets/image-container/hover_true.md b/verto/tests/assets/image-container/hover_true.md new file mode 100644 index 00000000..ab5e254e --- /dev/null +++ b/verto/tests/assets/image-container/hover_true.md @@ -0,0 +1,5 @@ +{image alt="alt text" file-path="computer-studying-turing-test.png" hover-text="Lipsum" caption="true"} + +This is why we can't have nice things. + +{image end} diff --git a/verto/tests/assets/image-container/hover_true_custom_argument_rules.json b/verto/tests/assets/image-container/hover_true_custom_argument_rules.json new file mode 100644 index 00000000..174a05ec --- /dev/null +++ b/verto/tests/assets/image-container/hover_true_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "image-container": { + "hover-text": true + } +} diff --git a/verto/tests/assets/image-container/hover_true_expected.html b/verto/tests/assets/image-container/hover_true_expected.html new file mode 100644 index 00000000..17baafb5 --- /dev/null +++ b/verto/tests/assets/image-container/hover_true_expected.html @@ -0,0 +1,4 @@ +
    +alt text +

    This is why we can't have nice things.

    +
    diff --git a/verto/tests/assets/image-container/hover_true_not_provided.md b/verto/tests/assets/image-container/hover_true_not_provided.md new file mode 100644 index 00000000..e027f644 --- /dev/null +++ b/verto/tests/assets/image-container/hover_true_not_provided.md @@ -0,0 +1,5 @@ +{image alt="alt text" file-path="computer-studying-turing-test.png" caption="true" alignment="center"} + +This is a caption for a computer studying the turing test. + +{image end} From a1ec09dbf87d403b1e6760375f4bb173efa94370 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Thu, 19 Jul 2018 11:41:08 +1200 Subject: [PATCH 41/73] Added custom argument tests to image tag --- verto/tests/ImageContainerTest.py | 188 +++++++++--------- verto/tests/ImageTagTest.py | 101 +++++++++- verto/tests/assets/image-tag/alt_false.md | 5 + .../alt_false_custom_argument_rules.json | 5 + .../assets/image-tag/alt_false_expected.html | 5 + .../assets/image-tag/alt_false_source_true.md | 11 + ...lse_source_true_custom_argument_rules.json | 6 + .../alt_false_source_true_expected.html | 13 ++ verto/tests/assets/image-tag/hover_true.md | 1 + .../hover_true_custom_argument_rules.json | 5 + .../assets/image-tag/hover_true_expected.html | 3 + .../image-tag/hover_true_not_provided.md | 1 + verto/tests/start_tests.py | 2 +- 13 files changed, 248 insertions(+), 98 deletions(-) create mode 100644 verto/tests/assets/image-tag/alt_false.md create mode 100644 verto/tests/assets/image-tag/alt_false_custom_argument_rules.json create mode 100644 verto/tests/assets/image-tag/alt_false_expected.html create mode 100644 verto/tests/assets/image-tag/alt_false_source_true.md create mode 100644 verto/tests/assets/image-tag/alt_false_source_true_custom_argument_rules.json create mode 100644 verto/tests/assets/image-tag/alt_false_source_true_expected.html create mode 100644 verto/tests/assets/image-tag/hover_true.md create mode 100644 verto/tests/assets/image-tag/hover_true_custom_argument_rules.json create mode 100644 verto/tests/assets/image-tag/hover_true_expected.html create mode 100644 verto/tests/assets/image-tag/hover_true_not_provided.md diff --git a/verto/tests/ImageContainerTest.py b/verto/tests/ImageContainerTest.py index e59d05b1..bd792c0a 100644 --- a/verto/tests/ImageContainerTest.py +++ b/verto/tests/ImageContainerTest.py @@ -36,98 +36,6 @@ def __init__(self, *args, **kwargs): self.ext.processor_info = ProcessorTest.loadProcessorInfo(self) self.ext.required_files = defaultdict(set) - def test_custom_arguments_alt_false(self): - '''Tests to ensure that image tag is rendered correctly when alt tag is not required and expected images are updated. - ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/alt_false_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) - verto_extension_custom_rules = VertoExtension( - processors=[self.processor_name], - custom_argument_rules=custom_argument_rules - ) - - test_string = self.read_test_file(self.processor_name, 'alt_false.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) - expected_string = self.read_test_file(self.processor_name, 'alt_false_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = verto_extension_custom_rules.required_files['images'] - expected_images = { - 'cats.png' - } - self.assertSetEqual(expected_images, images) - - def test_custom_arguments_hover_true(self): - '''Tests to ensure that image tag is rendered correctly when hover argument is required and expected images are updated. - ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/hover_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) - verto_extension_custom_rules = VertoExtension( - processors=[self.processor_name], - custom_argument_rules=custom_argument_rules - ) - - test_string = self.read_test_file(self.processor_name, 'hover_true.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) - expected_string = self.read_test_file(self.processor_name, 'hover_true_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = verto_extension_custom_rules.required_files['images'] - expected_images = { - 'computer-studying-turing-test.png' - } - self.assertSetEqual(expected_images, images) - - def test_custom_arguments_alt_false_source_true(self): - '''Tests to ensure that image tag is rendered correctly when alt argument is not required and source argument is true expected images are updated. - ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/alt_false_source_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) - verto_extension_custom_rules = VertoExtension( - processors=[self.processor_name], - custom_argument_rules=custom_argument_rules - ) - - test_string = self.read_test_file(self.processor_name, 'alt_false_source_true.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) - expected_string = self.read_test_file(self.processor_name, 'alt_false_source_true_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - images = verto_extension_custom_rules.required_files['images'] - expected_images = { - 'cats.png' - } - self.assertSetEqual(expected_images, images) - - def test_custom_arguments_hover_true_not_provided(self): - '''Tests to ensure that image tag is rendered correctly when alt tag is not required and expected images are updated. - ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/hover_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) - verto_extension_custom_rules = VertoExtension( - processors=[self.processor_name], - custom_argument_rules=custom_argument_rules - ) - - test_string = self.read_test_file(self.processor_name, 'hover_true_not_provided.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) - def test_caption_true(self): '''Tests to ensure that caption is rendered correctly and expected images are updated. ''' @@ -542,9 +450,101 @@ def test_image_width_value_external_image(self): expected_images = set() self.assertSetEqual(expected_images, images) - #~ + def test_custom_arguments_alt_false(self): + '''Tests to ensure that image tag is rendered correctly when alt tag is not required and expected images are updated. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/alt_false_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'alt_false.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'alt_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = verto_extension_custom_rules.required_files['images'] + expected_images = { + 'cats.png' + } + self.assertSetEqual(expected_images, images) + + def test_custom_arguments_hover_true(self): + '''Tests to ensure that image tag is rendered correctly when hover argument is required and expected images are updated. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/hover_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'hover_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'hover_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = verto_extension_custom_rules.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_custom_arguments_alt_false_source_true(self): + '''Tests to ensure that image tag is rendered correctly when alt argument is not required and source argument is true and expected images are updated. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/alt_false_source_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'alt_false_source_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False, True, False], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'alt_false_source_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = verto_extension_custom_rules.required_files['images'] + expected_images = { + 'cats.png' + } + self.assertSetEqual(expected_images, images) + + def test_custom_arguments_hover_true_not_provided(self): + '''Tests to ensure that correct error is raised when hover text is required and not provided. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/hover_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'hover_true_not_provided.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [ImageContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) + + # ~ # Doc Tests - #~ + # ~ def test_doc_example_basic(self): '''Basic example of common usage. diff --git a/verto/tests/ImageTagTest.py b/verto/tests/ImageTagTest.py index e1f2b38e..ff4e850e 100644 --- a/verto/tests/ImageTagTest.py +++ b/verto/tests/ImageTagTest.py @@ -1,6 +1,8 @@ import markdown from unittest.mock import Mock -from collections import defaultdict +from collections import defaultdict, OrderedDict +import json +import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.ImageTagBlockProcessor import ImageTagBlockProcessor @@ -389,9 +391,102 @@ def test_image_width_value_external_image(self): expected_images = set() self.assertSetEqual(expected_images, images) - #~ + def test_custom_arguments_alt_false(self): + '''Tests to ensure that image tag is rendered correctly when alt tag is not required and expected images are updated. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-tag/alt_false_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'alt_false.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'alt_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = verto_extension_custom_rules.required_files['images'] + expected_images = { + 'pixel-diamond.png' + } + self.assertSetEqual(expected_images, images) + + def test_custom_arguments_hover_true(self): + '''Tests to ensure that image tag is rendered correctly when hover argument is required and expected images are updated. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-tag/hover_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'hover_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'hover_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = verto_extension_custom_rules.required_files['images'] + expected_images = { + 'computer-studying-turing-test.png' + } + self.assertSetEqual(expected_images, images) + + def test_custom_arguments_alt_false_source_true(self): + '''Tests to ensure that image tag is rendered correctly when alt argument is not required and source argument is required and expected images are updated. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-tag/alt_false_source_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'alt_false_source_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False, True, False], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'alt_false_source_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = verto_extension_custom_rules.required_files['images'] + expected_images = { + 'finite-state-automata-trap-added-example.png', + 'finite-state-automata-no-trap-example.png' + } + self.assertSetEqual(expected_images, images) + + def test_custom_arguments_hover_true_not_provided(self): + '''Tests to ensure that correct error is raised when hover text is required and not provided. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-tag/hover_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'hover_true_not_provided.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [ImageTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) + + # ~ # Doc Tests - #~ + # ~ def test_doc_example_basic(self): '''Basic example of common usage. diff --git a/verto/tests/assets/image-tag/alt_false.md b/verto/tests/assets/image-tag/alt_false.md new file mode 100644 index 00000000..8eb8cc27 --- /dev/null +++ b/verto/tests/assets/image-tag/alt_false.md @@ -0,0 +1,5 @@ +Imagine we have the following simple black and white image. + +{image file-path="pixel-diamond.png"} + +One very simple way a computer can store this image in binary is by using a format where '0' means white and '1' means black (this is a "bit map", because we've mapped the pixels onto the values of bits). Using this method, the above image would be represented in the following way: diff --git a/verto/tests/assets/image-tag/alt_false_custom_argument_rules.json b/verto/tests/assets/image-tag/alt_false_custom_argument_rules.json new file mode 100644 index 00000000..bf09da76 --- /dev/null +++ b/verto/tests/assets/image-tag/alt_false_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "image-tag": { + "alt": false + } +} diff --git a/verto/tests/assets/image-tag/alt_false_expected.html b/verto/tests/assets/image-tag/alt_false_expected.html new file mode 100644 index 00000000..255ba843 --- /dev/null +++ b/verto/tests/assets/image-tag/alt_false_expected.html @@ -0,0 +1,5 @@ +

    Imagine we have the following simple black and white image.

    +
    + +
    +

    One very simple way a computer can store this image in binary is by using a format where '0' means white and '1' means black (this is a "bit map", because we've mapped the pixels onto the values of bits). Using this method, the above image would be represented in the following way:

    diff --git a/verto/tests/assets/image-tag/alt_false_source_true.md b/verto/tests/assets/image-tag/alt_false_source_true.md new file mode 100644 index 00000000..e9171c61 --- /dev/null +++ b/verto/tests/assets/image-tag/alt_false_source_true.md @@ -0,0 +1,11 @@ +Here's another FSA to consider: + +{image file-path="finite-state-automata-no-trap-example.png" hover-text="hover text is me" source="example.com"} + +It's fairly clear what it will accept: strings like "ab", "abab", "abababababab", and, of course {math}\epsilon{math end}. +But there are some missing transitions: if you are in state 1 and get a "b" there's nowhere to go. +If an input cannot be accepted, it will be rejected, as in this case. We could have put in a trap state to make this clear: + +{image file-path="finite-state-automata-trap-added-example.png" source="example.com" hover-text="also some hover text"} + +But things can get out of hand. What if there are more letters in the alphabet? We'd need something like this: diff --git a/verto/tests/assets/image-tag/alt_false_source_true_custom_argument_rules.json b/verto/tests/assets/image-tag/alt_false_source_true_custom_argument_rules.json new file mode 100644 index 00000000..853a1559 --- /dev/null +++ b/verto/tests/assets/image-tag/alt_false_source_true_custom_argument_rules.json @@ -0,0 +1,6 @@ +{ + "image-tag": { + "alt": false, + "source": true + } +} diff --git a/verto/tests/assets/image-tag/alt_false_source_true_expected.html b/verto/tests/assets/image-tag/alt_false_source_true_expected.html new file mode 100644 index 00000000..03d22a40 --- /dev/null +++ b/verto/tests/assets/image-tag/alt_false_source_true_expected.html @@ -0,0 +1,13 @@ +

    Here's another FSA to consider:

    +
    + +

    Source

    +
    +

    It's fairly clear what it will accept: strings like "ab", "abab", "abababababab", and, of course {math}\epsilon{math end}. +But there are some missing transitions: if you are in state 1 and get a "b" there's nowhere to go. +If an input cannot be accepted, it will be rejected, as in this case. We could have put in a trap state to make this clear:

    +
    + +

    Source

    +
    +

    But things can get out of hand. What if there are more letters in the alphabet? We'd need something like this:

    diff --git a/verto/tests/assets/image-tag/hover_true.md b/verto/tests/assets/image-tag/hover_true.md new file mode 100644 index 00000000..9e6b3b68 --- /dev/null +++ b/verto/tests/assets/image-tag/hover_true.md @@ -0,0 +1 @@ +{image alt="alt text" file-path="computer-studying-turing-test.png" hover-text="cats" caption="false" alignment="center"} diff --git a/verto/tests/assets/image-tag/hover_true_custom_argument_rules.json b/verto/tests/assets/image-tag/hover_true_custom_argument_rules.json new file mode 100644 index 00000000..ed656286 --- /dev/null +++ b/verto/tests/assets/image-tag/hover_true_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "image-tag": { + "hover-text": true + } +} diff --git a/verto/tests/assets/image-tag/hover_true_expected.html b/verto/tests/assets/image-tag/hover_true_expected.html new file mode 100644 index 00000000..6d43babc --- /dev/null +++ b/verto/tests/assets/image-tag/hover_true_expected.html @@ -0,0 +1,3 @@ +
    +alt text +
    diff --git a/verto/tests/assets/image-tag/hover_true_not_provided.md b/verto/tests/assets/image-tag/hover_true_not_provided.md new file mode 100644 index 00000000..7105c8fe --- /dev/null +++ b/verto/tests/assets/image-tag/hover_true_not_provided.md @@ -0,0 +1 @@ +{image alt="alt text" file-path="computer-studying-turing-test.png" caption="false" alignment="center"} diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 1c867357..9f5cfc9f 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -93,7 +93,7 @@ def unit_suite(): # unittest.makeSuite(GlossaryLinkTest), # unittest.makeSuite(HeadingTest), # unittest.makeSuite(ImageInlineTest), - # unittest.makeSuite(ImageTagTest), + unittest.makeSuite(ImageTagTest), unittest.makeSuite(ImageContainerTest), # unittest.makeSuite(InteractiveTest), # unittest.makeSuite(JinjaTest), From 05f4607a52ff8ed5b2904f50b36f7f9932e652a0 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Thu, 19 Jul 2018 22:10:18 +1200 Subject: [PATCH 42/73] Added custom argument rule tests to inline image --- verto/tests/ImageInlineTest.py | 111 ++++++++++++++++-- verto/tests/assets/image-inline/alt_false.md | 1 + .../alt_false_custom_argument_rules.json | 5 + .../image-inline/alt_false_expected.html | 3 + .../image-inline/alt_false_source_true.md | 1 + ...lse_source_true_custom_argument_rules.json | 6 + .../alt_false_source_true_expected.html | 4 + verto/tests/assets/image-inline/hover_true.md | 1 + .../hover_true_custom_argument_rules.json | 5 + .../image-inline/hover_true_expected.html | 3 + .../image-inline/hover_true_not_provided.md | 1 + verto/tests/start_tests.py | 2 +- 12 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 verto/tests/assets/image-inline/alt_false.md create mode 100644 verto/tests/assets/image-inline/alt_false_custom_argument_rules.json create mode 100644 verto/tests/assets/image-inline/alt_false_expected.html create mode 100644 verto/tests/assets/image-inline/alt_false_source_true.md create mode 100644 verto/tests/assets/image-inline/alt_false_source_true_custom_argument_rules.json create mode 100644 verto/tests/assets/image-inline/alt_false_source_true_expected.html create mode 100644 verto/tests/assets/image-inline/hover_true.md create mode 100644 verto/tests/assets/image-inline/hover_true_custom_argument_rules.json create mode 100644 verto/tests/assets/image-inline/hover_true_expected.html create mode 100644 verto/tests/assets/image-inline/hover_true_not_provided.md diff --git a/verto/tests/ImageInlineTest.py b/verto/tests/ImageInlineTest.py index 9e331179..5a6fa4ca 100644 --- a/verto/tests/ImageInlineTest.py +++ b/verto/tests/ImageInlineTest.py @@ -1,12 +1,16 @@ import markdown import re from unittest.mock import Mock -from collections import defaultdict +from collections import defaultdict, OrderedDict +import json +import pkg_resources + from verto.VertoExtension import VertoExtension from verto.processors.ImageInlinePattern import ImageInlinePattern from verto.errors.ArgumentMissingError import ArgumentMissingError from verto.tests.ProcessorTest import ProcessorTest + class ImageInlineTest(ProcessorTest): '''Tests to check the 'image-inline' pattern works as intended.''' @@ -39,7 +43,6 @@ def test_basic_usage(self): } self.assertSetEqual(expected_images, images) - def test_doc_example_override_html(self): '''Basic example showing how to override the html-template.''' test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') @@ -58,9 +61,9 @@ def test_doc_example_override_html(self): expected_images = set() self.assertSetEqual(expected_images, images) - #~ + # ~ # Image locations tests - #~ + # ~ def test_internal_image(self): '''Test to ensure that an internally reference image produces @@ -120,9 +123,9 @@ def test_multiple_internal_images(self): } self.assertSetEqual(expected_images, images) - #~ + # ~ # Argument tests - #~ + # ~ def test_missing_argument_alt(self): '''Test that ArgumentMissingError is thrown when alt argument is missing''' @@ -262,9 +265,9 @@ def test_image_width_value_external_image(self): expected_images = set() self.assertSetEqual(expected_images, images) - #~ + # ~ # Embed test. - #~ + # ~ def test_numbered_list(self): '''Test that image-inline functions within a numbered list.''' @@ -298,3 +301,95 @@ def test_table_embed(self): 'img/example2.png' } self.assertSetEqual(expected_images, images) + + # ~ + # custom arguments tests. + # ~ + + def test_custom_arguments_alt_false(self): + '''Tests to ensure that image tag is rendered correctly when alt tag is not required and expected images are updated. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-inline/alt_false_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'alt_false.md') + processor = ImageInlinePattern(self.ext, self.md.parser) + self.assertIsNotNone(re.search(processor.compiled_re, test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'alt_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = verto_extension_custom_rules.required_files['images'] + expected_images = { + 'img/example.png' + } + self.assertSetEqual(expected_images, images) + + def test_custom_arguments_hover_true(self): + '''Tests to ensure that image tag is rendered correctly when hover argument is required and expected images are updated. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-inline/hover_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'hover_true.md') + processor = ImageInlinePattern(self.ext, self.md.parser) + self.assertIsNotNone(re.search(processor.compiled_re, test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'hover_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = verto_extension_custom_rules.required_files['images'] + expected_images = { + 'img/example.png' + } + self.assertSetEqual(expected_images, images) + + def test_custom_arguments_alt_false_source_true(self): + '''Tests to ensure that image tag is rendered correctly when alt argument is not required and source argument is required and expected images are updated. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-inline/alt_false_source_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'alt_false_source_true.md') + processor = ImageInlinePattern(self.ext, self.md.parser) + self.assertIsNotNone(re.search(processor.compiled_re, test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'alt_false_source_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + images = verto_extension_custom_rules.required_files['images'] + expected_images = { + 'img/example.png' + } + self.assertSetEqual(expected_images, images) + + def test_custom_arguments_hover_true_not_provided(self): + '''Tests to ensure that correct error is raised when hover text is required and not provided. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/image-inline/hover_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'hover_true_not_provided.md') + processor = ImageInlinePattern(self.ext, self.md.parser) + self.assertIsNotNone(re.search(processor.compiled_re, test_string)) + + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) diff --git a/verto/tests/assets/image-inline/alt_false.md b/verto/tests/assets/image-inline/alt_false.md new file mode 100644 index 00000000..b026c2d8 --- /dev/null +++ b/verto/tests/assets/image-inline/alt_false.md @@ -0,0 +1 @@ +An inline image: {image-inline file-path="img/example.png"}. diff --git a/verto/tests/assets/image-inline/alt_false_custom_argument_rules.json b/verto/tests/assets/image-inline/alt_false_custom_argument_rules.json new file mode 100644 index 00000000..c838e868 --- /dev/null +++ b/verto/tests/assets/image-inline/alt_false_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "image-inline": { + "alt": false + } +} diff --git a/verto/tests/assets/image-inline/alt_false_expected.html b/verto/tests/assets/image-inline/alt_false_expected.html new file mode 100644 index 00000000..5889401f --- /dev/null +++ b/verto/tests/assets/image-inline/alt_false_expected.html @@ -0,0 +1,3 @@ +

    An inline image:

    + +
    .

    diff --git a/verto/tests/assets/image-inline/alt_false_source_true.md b/verto/tests/assets/image-inline/alt_false_source_true.md new file mode 100644 index 00000000..4cb2e33d --- /dev/null +++ b/verto/tests/assets/image-inline/alt_false_source_true.md @@ -0,0 +1 @@ +An inline image: {image-inline source="website.com" file-path="img/example.png"}. diff --git a/verto/tests/assets/image-inline/alt_false_source_true_custom_argument_rules.json b/verto/tests/assets/image-inline/alt_false_source_true_custom_argument_rules.json new file mode 100644 index 00000000..f16994a3 --- /dev/null +++ b/verto/tests/assets/image-inline/alt_false_source_true_custom_argument_rules.json @@ -0,0 +1,6 @@ +{ + "image-inline": { + "alt": false, + "source": true + } +} diff --git a/verto/tests/assets/image-inline/alt_false_source_true_expected.html b/verto/tests/assets/image-inline/alt_false_source_true_expected.html new file mode 100644 index 00000000..b7660e4c --- /dev/null +++ b/verto/tests/assets/image-inline/alt_false_source_true_expected.html @@ -0,0 +1,4 @@ +

    An inline image:

    + +

    Source

    +
    .

    diff --git a/verto/tests/assets/image-inline/hover_true.md b/verto/tests/assets/image-inline/hover_true.md new file mode 100644 index 00000000..c7a99482 --- /dev/null +++ b/verto/tests/assets/image-inline/hover_true.md @@ -0,0 +1 @@ +An inline image: {image-inline alt="alt text" hover-text="this is hover text" file-path="img/example.png"}. diff --git a/verto/tests/assets/image-inline/hover_true_custom_argument_rules.json b/verto/tests/assets/image-inline/hover_true_custom_argument_rules.json new file mode 100644 index 00000000..a40f1625 --- /dev/null +++ b/verto/tests/assets/image-inline/hover_true_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "image-inline": { + "hover-text": true + } +} diff --git a/verto/tests/assets/image-inline/hover_true_expected.html b/verto/tests/assets/image-inline/hover_true_expected.html new file mode 100644 index 00000000..3cd2f788 --- /dev/null +++ b/verto/tests/assets/image-inline/hover_true_expected.html @@ -0,0 +1,3 @@ +

    An inline image:

    +alt text +
    .

    diff --git a/verto/tests/assets/image-inline/hover_true_not_provided.md b/verto/tests/assets/image-inline/hover_true_not_provided.md new file mode 100644 index 00000000..568de38c --- /dev/null +++ b/verto/tests/assets/image-inline/hover_true_not_provided.md @@ -0,0 +1 @@ +An inline image: {image-inline alt="alt text" file-path="img/example.png"}. diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 9f5cfc9f..15800e42 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -92,7 +92,7 @@ def unit_suite(): # unittest.makeSuite(FrameTest), # unittest.makeSuite(GlossaryLinkTest), # unittest.makeSuite(HeadingTest), - # unittest.makeSuite(ImageInlineTest), + unittest.makeSuite(ImageInlineTest), unittest.makeSuite(ImageTagTest), unittest.makeSuite(ImageContainerTest), # unittest.makeSuite(InteractiveTest), From bb40b2d9a8b870a2f43c4b6f6ba931ce58b1c262 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 23 Jul 2018 17:48:23 +1200 Subject: [PATCH 43/73] Added test for custom arguments for boxed text --- verto/VertoExtension.py | 2 +- verto/tests/BoxedTextTest.py | 66 ++++++++++++++++--- .../assets/boxed-text/indentation_true.md | 5 ++ ...ndentation_true_custom_argument_rules.json | 5 ++ .../boxed-text/indentation_true_expected.html | 3 + .../indentation_true_not_provided.md | 5 ++ .../assets/boxed-text/indentation_value_no.md | 7 ++ .../indentation_value_no_expected.html | 4 ++ verto/tests/start_tests.py | 2 +- 9 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 verto/tests/assets/boxed-text/indentation_true.md create mode 100644 verto/tests/assets/boxed-text/indentation_true_custom_argument_rules.json create mode 100644 verto/tests/assets/boxed-text/indentation_true_expected.html create mode 100644 verto/tests/assets/boxed-text/indentation_true_not_provided.md create mode 100644 verto/tests/assets/boxed-text/indentation_value_no.md create mode 100644 verto/tests/assets/boxed-text/indentation_value_no_expected.html diff --git a/verto/VertoExtension.py b/verto/VertoExtension.py index d115cf20..b24a2eeb 100644 --- a/verto/VertoExtension.py +++ b/verto/VertoExtension.py @@ -246,7 +246,7 @@ def _set_heading_tree(self, tree): self.heading_tree = tree # refactor to modify_required_arguments - def modify_rules(self, json_data): + def modify_rules(self, json_data): # TODO what if gives argument that does not exist for processor, arguments_to_modify in self.custom_argument_rules.items(): for argument in arguments_to_modify.items(): new_required = argument[1] # .lower() diff --git a/verto/tests/BoxedTextTest.py b/verto/tests/BoxedTextTest.py index b59a16ca..d447574b 100644 --- a/verto/tests/BoxedTextTest.py +++ b/verto/tests/BoxedTextTest.py @@ -1,8 +1,12 @@ import markdown from unittest.mock import Mock +from collections import OrderedDict +import json +import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.GenericContainerBlockProcessor import GenericContainerBlockProcessor +from verto.errors.ArgumentMissingError import ArgumentMissingError from verto.tests.ProcessorTest import ProcessorTest @@ -75,9 +79,7 @@ def test_multiple_boxed_text(self): self.assertEqual(expected_string, converted_test_string) def test_recursive_boxed_text(self): - '''Tests that multiple different matches (that are - contained as content of eachother) are matched and - processed correctly. + '''Tests that multiple different matches (that are contained as content of eachother) are matched and processed correctly. ''' test_string = self.read_test_file(self.processor_name, 'recursive_boxed_text.md') blocks = self.to_blocks(test_string) @@ -88,9 +90,57 @@ def test_recursive_boxed_text(self): expected_string = self.read_test_file(self.processor_name, 'recursive_boxed_text_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - #~ + # def test_indentation_value_no(self): + # ''' + # ''' + # test_string = self.read_test_file(self.processor_name, 'indentation_value_no.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True, False, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'indentation_value_no_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_indented_true(self): + '''Tests to ensure that boxed text tag is rendered correctly when indented argument is required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/indentation_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'indentation_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [GenericContainerBlockProcessor(self.processor_name, self.ext, Mock()).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'indentation_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_indented_true_not_provided(self): + '''Tests to ensure that boxed text tag is rendered correctly when indented argument is required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/indentation_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'indentation_true_not_provided.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [GenericContainerBlockProcessor(self.processor_name, self.ext, Mock()).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) + + # ~ # Doc Tests - #~ + # ~ def test_doc_example_basic(self): '''Tests that the most generic case of a single match is found @@ -105,7 +155,7 @@ def test_doc_example_basic(self): expected_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - def test_doc_example_override_html(self): + def test_doc_example_override_html(self): # TODO check why verto_extension not used '''Tests and shows example of overriding the html of the processor. ''' @@ -116,7 +166,3 @@ def test_doc_example_override_html(self): html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) verto_extension = VertoExtension([self.processor_name], html_templates={self.processor_name: html_template}) - - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) diff --git a/verto/tests/assets/boxed-text/indentation_true.md b/verto/tests/assets/boxed-text/indentation_true.md new file mode 100644 index 00000000..cae9cb4a --- /dev/null +++ b/verto/tests/assets/boxed-text/indentation_true.md @@ -0,0 +1,5 @@ +{boxed-text indented="yes"} + +This text is displayed using a Bootstrap 4 card. + +{boxed-text end} diff --git a/verto/tests/assets/boxed-text/indentation_true_custom_argument_rules.json b/verto/tests/assets/boxed-text/indentation_true_custom_argument_rules.json new file mode 100644 index 00000000..d8e93e7f --- /dev/null +++ b/verto/tests/assets/boxed-text/indentation_true_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "boxed-text": { + "indented": true + } +} diff --git a/verto/tests/assets/boxed-text/indentation_true_expected.html b/verto/tests/assets/boxed-text/indentation_true_expected.html new file mode 100644 index 00000000..cd5443b5 --- /dev/null +++ b/verto/tests/assets/boxed-text/indentation_true_expected.html @@ -0,0 +1,3 @@ +
    +

    This text is displayed using a Bootstrap 4 card.

    +
    diff --git a/verto/tests/assets/boxed-text/indentation_true_not_provided.md b/verto/tests/assets/boxed-text/indentation_true_not_provided.md new file mode 100644 index 00000000..7f453656 --- /dev/null +++ b/verto/tests/assets/boxed-text/indentation_true_not_provided.md @@ -0,0 +1,5 @@ +{boxed-text} + +This text is displayed using a Bootstrap 4 card. + +{boxed-text end} diff --git a/verto/tests/assets/boxed-text/indentation_value_no.md b/verto/tests/assets/boxed-text/indentation_value_no.md new file mode 100644 index 00000000..1c7ed6d8 --- /dev/null +++ b/verto/tests/assets/boxed-text/indentation_value_no.md @@ -0,0 +1,7 @@ +{boxed-text indented="no"} + +This text is displayed using a Bootstrap 4 card. + +Where some more text might exist. + +{boxed-text end} diff --git a/verto/tests/assets/boxed-text/indentation_value_no_expected.html b/verto/tests/assets/boxed-text/indentation_value_no_expected.html new file mode 100644 index 00000000..a5ffb467 --- /dev/null +++ b/verto/tests/assets/boxed-text/indentation_value_no_expected.html @@ -0,0 +1,4 @@ +
    +

    This text is displayed using a Bootstrap 4 card.

    +

    Where some more text might exist.

    +
    diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 15800e42..f3aeed2f 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -85,7 +85,7 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - # unittest.makeSuite(BoxedTextTest), + unittest.makeSuite(BoxedTextTest), # unittest.makeSuite(ButtonLinkTest), # unittest.makeSuite(CommentTest), # unittest.makeSuite(ConditionalTest), From 5320fe7a1160784d4351558204aecb8d2edb55af Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 23 Jul 2018 18:16:14 +1200 Subject: [PATCH 44/73] Fixed incorrect output for boxed-text when indented = "no" Also added some missing lines to the doc example tests --- verto/html-templates/boxed-text.html | 2 +- verto/tests/BoxedTextTest.py | 39 ++++++++++++++-------------- verto/tests/start_tests.py | 6 ++--- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/verto/html-templates/boxed-text.html b/verto/html-templates/boxed-text.html index 12e4bb64..fe023a7b 100644 --- a/verto/html-templates/boxed-text.html +++ b/verto/html-templates/boxed-text.html @@ -1,4 +1,4 @@ -
    +
    {% autoescape false -%} {{ text }} {% endautoescape -%} diff --git a/verto/tests/BoxedTextTest.py b/verto/tests/BoxedTextTest.py index d447574b..91b7ea2e 100644 --- a/verto/tests/BoxedTextTest.py +++ b/verto/tests/BoxedTextTest.py @@ -28,8 +28,7 @@ def __init__(self, *args, **kwargs): self.block_processor = GenericContainerBlockProcessor(self.processor_name, self.ext, Mock()) def test_no_boxed_text(self): - '''Tests that the text containing the processor name is - not matched. + '''Tests that the text containing the processor name is not matched. ''' test_string = self.read_test_file(self.processor_name, 'no_boxed_text.md') blocks = self.to_blocks(test_string) @@ -41,8 +40,7 @@ def test_no_boxed_text(self): self.assertEqual(expected_string, converted_test_string) def test_single_boxed_text(self): - '''Tests that the most generic case of a single match is found - with generic content contained within. + '''Tests that the most generic case of a single match is found with generic content contained within. ''' test_string = self.read_test_file(self.processor_name, 'single_boxed_text.md') blocks = self.to_blocks(test_string) @@ -66,8 +64,7 @@ def test_indented_boxed_text(self): self.assertEqual(expected_string, converted_test_string) def test_multiple_boxed_text(self): - '''Tests that multiple different matches (that are not - within others) are matched and processed correctly. + '''Tests that multiple different matches (that are not within others) are matched and processed correctly. ''' test_string = self.read_test_file(self.processor_name, 'multiple_boxed_text.md') blocks = self.to_blocks(test_string) @@ -90,17 +87,17 @@ def test_recursive_boxed_text(self): expected_string = self.read_test_file(self.processor_name, 'recursive_boxed_text_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - # def test_indentation_value_no(self): - # ''' - # ''' - # test_string = self.read_test_file(self.processor_name, 'indentation_value_no.md') - # blocks = self.to_blocks(test_string) + def test_indentation_value_no(self): + '''Tests that indentation class not added if indent value is "no". + ''' + test_string = self.read_test_file(self.processor_name, 'indentation_value_no.md') + blocks = self.to_blocks(test_string) - # self.assertListEqual([True, False, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True, False, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'indentation_value_no_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'indentation_value_no_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) def test_custom_arguments_indented_true(self): '''Tests to ensure that boxed text tag is rendered correctly when indented argument is required. @@ -143,8 +140,7 @@ def test_custom_arguments_indented_true_not_provided(self): # ~ def test_doc_example_basic(self): - '''Tests that the most generic case of a single match is found - with generic content contained within. + '''Tests that the most generic case of a single match is found with generic content contained within. ''' test_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage.md') blocks = self.to_blocks(test_string) @@ -155,9 +151,8 @@ def test_doc_example_basic(self): expected_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - def test_doc_example_override_html(self): # TODO check why verto_extension not used - '''Tests and shows example of overriding the html of the - processor. + def test_doc_example_override_html(self): + '''Tests and shows example of overriding the html of the processor. ''' test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') blocks = self.to_blocks(test_string) @@ -166,3 +161,7 @@ def test_doc_example_override_html(self): # TODO check why verto_extension not html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) verto_extension = VertoExtension([self.processor_name], html_templates={self.processor_name: html_template}) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index f3aeed2f..fb02bbe3 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -92,9 +92,9 @@ def unit_suite(): # unittest.makeSuite(FrameTest), # unittest.makeSuite(GlossaryLinkTest), # unittest.makeSuite(HeadingTest), - unittest.makeSuite(ImageInlineTest), - unittest.makeSuite(ImageTagTest), - unittest.makeSuite(ImageContainerTest), + # unittest.makeSuite(ImageInlineTest), + # unittest.makeSuite(ImageTagTest), + # unittest.makeSuite(ImageContainerTest), # unittest.makeSuite(InteractiveTest), # unittest.makeSuite(JinjaTest), # unittest.makeSuite(PanelTest), From b01d12488372c8bc83e8e70544088f02dc3fda75 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Thu, 26 Jul 2018 17:04:02 +1200 Subject: [PATCH 45/73] Added tests for custom argument rules for type Refactored "indentation" -> "idented" for consistecy --- verto/tests/BoxedTextTest.py | 79 ++++++++++++++++--- .../boxed-text/indented_and_type_required.md | 5 ++ ...d_type_required_custom_argument_rules.json | 6 ++ .../indented_and_type_required_expected.html | 3 + ...ed_and_type_required_type_not_provided.md} | 0 .../assets/boxed-text/indented_required.md | 5 ++ ...ented_required_custom_argument_rules.json} | 0 ...d.html => indented_required_expected.html} | 0 ...d.md => indented_required_not_provided.md} | 0 ...ation_value_no.md => indented_value_no.md} | 0 ...d.html => indented_value_no_expected.html} | 0 .../tests/assets/boxed-text/type_required.md | 5 ++ .../type_required_custom_argument_rules.json | 5 ++ .../boxed-text/type_required_expected.html | 3 + 14 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 verto/tests/assets/boxed-text/indented_and_type_required.md create mode 100644 verto/tests/assets/boxed-text/indented_and_type_required_custom_argument_rules.json create mode 100644 verto/tests/assets/boxed-text/indented_and_type_required_expected.html rename verto/tests/assets/boxed-text/{indentation_true.md => indented_and_type_required_type_not_provided.md} (100%) create mode 100644 verto/tests/assets/boxed-text/indented_required.md rename verto/tests/assets/boxed-text/{indentation_true_custom_argument_rules.json => indented_required_custom_argument_rules.json} (100%) rename verto/tests/assets/boxed-text/{indentation_true_expected.html => indented_required_expected.html} (100%) rename verto/tests/assets/boxed-text/{indentation_true_not_provided.md => indented_required_not_provided.md} (100%) rename verto/tests/assets/boxed-text/{indentation_value_no.md => indented_value_no.md} (100%) rename verto/tests/assets/boxed-text/{indentation_value_no_expected.html => indented_value_no_expected.html} (100%) create mode 100644 verto/tests/assets/boxed-text/type_required.md create mode 100644 verto/tests/assets/boxed-text/type_required_custom_argument_rules.json create mode 100644 verto/tests/assets/boxed-text/type_required_expected.html diff --git a/verto/tests/BoxedTextTest.py b/verto/tests/BoxedTextTest.py index 506ed059..c7f33163 100644 --- a/verto/tests/BoxedTextTest.py +++ b/verto/tests/BoxedTextTest.py @@ -111,48 +111,103 @@ def test_recursive_boxed_text(self): expected_string = self.read_test_file(self.processor_name, 'recursive_boxed_text_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - def test_indentation_value_no(self): - '''Tests that indentation class not added if indent value is "no". + def test_indented_value_no(self): + '''Tests that indented class not added if indent value is "no". ''' - test_string = self.read_test_file(self.processor_name, 'indentation_value_no.md') + test_string = self.read_test_file(self.processor_name, 'indented_value_no.md') blocks = self.to_blocks(test_string) self.assertListEqual([True, False, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'indentation_value_no_expected.html', strip=True) + expected_string = self.read_test_file(self.processor_name, 'indented_value_no_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - def test_custom_arguments_indented_true(self): + def test_custom_arguments_indented_required(self): '''Tests to ensure that boxed text tag is rendered correctly when indented argument is required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/indentation_true_custom_argument_rules.json').decode('utf-8') + json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/indented_required_custom_argument_rules.json').decode('utf-8') custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules ) - test_string = self.read_test_file(self.processor_name, 'indentation_true.md') + test_string = self.read_test_file(self.processor_name, 'indented_required.md') blocks = self.to_blocks(test_string) self.assertListEqual([True, False, True], [GenericContainerBlockProcessor(self.processor_name, self.ext, Mock()).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) - expected_string = self.read_test_file(self.processor_name, 'indentation_true_expected.html', strip=True) + expected_string = self.read_test_file(self.processor_name, 'indented_required_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - def test_custom_arguments_indented_true_not_provided(self): - '''Tests to ensure that boxed text tag is rendered correctly when indented argument is required. + def test_custom_arguments_type_required(self): + '''Tests to ensure that boxed text tag is rendered correctly when type argument is required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/type_required_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'type_required.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [GenericContainerBlockProcessor(self.processor_name, self.ext, Mock()).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'type_required_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_indented_and_type_required(self): + '''Tests to ensure that boxed text tag is rendered correctly when both indented and type arguments are required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/indented_and_type_required_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'indented_and_type_required.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [GenericContainerBlockProcessor(self.processor_name, self.ext, Mock()).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'indented_and_type_required_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_indented_required_not_provided(self): + '''Tests to ensure that error is raised when indented argument is required and not given. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/indented_required_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'indented_required_not_provided.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [GenericContainerBlockProcessor(self.processor_name, self.ext, Mock()).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) + + def test_custom_arguments_indented_and_type_required_type_not_provided(self): + '''Tests to ensure that error is raised when indented and type arguments are required and type is not given. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/indentation_true_custom_argument_rules.json').decode('utf-8') + json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/indented_and_type_required_custom_argument_rules.json').decode('utf-8') custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules ) - test_string = self.read_test_file(self.processor_name, 'indentation_true_not_provided.md') + test_string = self.read_test_file(self.processor_name, 'indented_and_type_required_type_not_provided.md') blocks = self.to_blocks(test_string) self.assertListEqual([True, False, True], [GenericContainerBlockProcessor(self.processor_name, self.ext, Mock()).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) diff --git a/verto/tests/assets/boxed-text/indented_and_type_required.md b/verto/tests/assets/boxed-text/indented_and_type_required.md new file mode 100644 index 00000000..b2879294 --- /dev/null +++ b/verto/tests/assets/boxed-text/indented_and_type_required.md @@ -0,0 +1,5 @@ +{boxed-text indented="yes" type="quote"} + +This text is displayed using a Bootstrap 4 card. + +{boxed-text end} diff --git a/verto/tests/assets/boxed-text/indented_and_type_required_custom_argument_rules.json b/verto/tests/assets/boxed-text/indented_and_type_required_custom_argument_rules.json new file mode 100644 index 00000000..53f47286 --- /dev/null +++ b/verto/tests/assets/boxed-text/indented_and_type_required_custom_argument_rules.json @@ -0,0 +1,6 @@ +{ + "boxed-text": { + "indented": true, + "type": true + } +} diff --git a/verto/tests/assets/boxed-text/indented_and_type_required_expected.html b/verto/tests/assets/boxed-text/indented_and_type_required_expected.html new file mode 100644 index 00000000..5a1b1c3b --- /dev/null +++ b/verto/tests/assets/boxed-text/indented_and_type_required_expected.html @@ -0,0 +1,3 @@ +
    +

    This text is displayed using a Bootstrap 4 card.

    +
    diff --git a/verto/tests/assets/boxed-text/indentation_true.md b/verto/tests/assets/boxed-text/indented_and_type_required_type_not_provided.md similarity index 100% rename from verto/tests/assets/boxed-text/indentation_true.md rename to verto/tests/assets/boxed-text/indented_and_type_required_type_not_provided.md diff --git a/verto/tests/assets/boxed-text/indented_required.md b/verto/tests/assets/boxed-text/indented_required.md new file mode 100644 index 00000000..cae9cb4a --- /dev/null +++ b/verto/tests/assets/boxed-text/indented_required.md @@ -0,0 +1,5 @@ +{boxed-text indented="yes"} + +This text is displayed using a Bootstrap 4 card. + +{boxed-text end} diff --git a/verto/tests/assets/boxed-text/indentation_true_custom_argument_rules.json b/verto/tests/assets/boxed-text/indented_required_custom_argument_rules.json similarity index 100% rename from verto/tests/assets/boxed-text/indentation_true_custom_argument_rules.json rename to verto/tests/assets/boxed-text/indented_required_custom_argument_rules.json diff --git a/verto/tests/assets/boxed-text/indentation_true_expected.html b/verto/tests/assets/boxed-text/indented_required_expected.html similarity index 100% rename from verto/tests/assets/boxed-text/indentation_true_expected.html rename to verto/tests/assets/boxed-text/indented_required_expected.html diff --git a/verto/tests/assets/boxed-text/indentation_true_not_provided.md b/verto/tests/assets/boxed-text/indented_required_not_provided.md similarity index 100% rename from verto/tests/assets/boxed-text/indentation_true_not_provided.md rename to verto/tests/assets/boxed-text/indented_required_not_provided.md diff --git a/verto/tests/assets/boxed-text/indentation_value_no.md b/verto/tests/assets/boxed-text/indented_value_no.md similarity index 100% rename from verto/tests/assets/boxed-text/indentation_value_no.md rename to verto/tests/assets/boxed-text/indented_value_no.md diff --git a/verto/tests/assets/boxed-text/indentation_value_no_expected.html b/verto/tests/assets/boxed-text/indented_value_no_expected.html similarity index 100% rename from verto/tests/assets/boxed-text/indentation_value_no_expected.html rename to verto/tests/assets/boxed-text/indented_value_no_expected.html diff --git a/verto/tests/assets/boxed-text/type_required.md b/verto/tests/assets/boxed-text/type_required.md new file mode 100644 index 00000000..ccb26844 --- /dev/null +++ b/verto/tests/assets/boxed-text/type_required.md @@ -0,0 +1,5 @@ +{boxed-text type="quote"} + +This text is a quote. + +{boxed-text end} diff --git a/verto/tests/assets/boxed-text/type_required_custom_argument_rules.json b/verto/tests/assets/boxed-text/type_required_custom_argument_rules.json new file mode 100644 index 00000000..29e51f83 --- /dev/null +++ b/verto/tests/assets/boxed-text/type_required_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "boxed-text": { + "type": true + } +} diff --git a/verto/tests/assets/boxed-text/type_required_expected.html b/verto/tests/assets/boxed-text/type_required_expected.html new file mode 100644 index 00000000..a1df3c12 --- /dev/null +++ b/verto/tests/assets/boxed-text/type_required_expected.html @@ -0,0 +1,3 @@ +
    +

    This text is a quote.

    +
    From 7091d70a8e8d83e324d8ebdfe54a43ed8d020dce Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Thu, 26 Jul 2018 17:45:46 +1200 Subject: [PATCH 46/73] WIP adding tests for custom arguments to button link --- verto/tests/ButtonLinkTest.py | 105 +++++++++++++++++++++++++++++++++- verto/tests/start_tests.py | 2 +- 2 files changed, 103 insertions(+), 4 deletions(-) diff --git a/verto/tests/ButtonLinkTest.py b/verto/tests/ButtonLinkTest.py index 0cf0af8f..5ee60cdf 100644 --- a/verto/tests/ButtonLinkTest.py +++ b/verto/tests/ButtonLinkTest.py @@ -1,8 +1,12 @@ import markdown from unittest.mock import Mock +from collections import OrderedDict +import json +import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.GenericTagBlockProcessor import GenericTagBlockProcessor +from verto.errors.ArgumentMissingError import ArgumentMissingError from verto.tests.ProcessorTest import ProcessorTest @@ -66,7 +70,7 @@ def test_contains_multiple_buttons(self): test_string = self.read_test_file(self.processor_name, 'contains_multiple_buttons.md') blocks = self.to_blocks(test_string) - self.assertListEqual([False, True, False, False, True, False, False, True, False, False , True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, True, False, False, True, False, False, True, False, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) @@ -87,9 +91,104 @@ def test_contains_file_link_button(self): expected_string = self.read_test_file(self.processor_name, 'contains_file_link_button_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - #~ +# link text file + def test_custom_arguments_link_required(self): + ''' + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/link_required_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'link_required.md') + blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, False, False], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'link_required_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_text_required(self): + ''' + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/text_required_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'text_required.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'text_required_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_file_required(self): + ''' + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/file_required_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'file_required.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'file_required_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_file_and_link_required(self): + ''' + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/file_and_link_required_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'file_and_link_required.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'file_and_link_required_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_file_and_link_required_file_not_provided(self): + ''' + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/file_and_link_required_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'file_and_link_required_file_not_provided.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) + + # ~ # Doc Tests - #~ + # ~ def test_doc_example_basic(self): '''Tests that the most generic case of a single match is found diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index f3aeed2f..ed77e7c4 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -86,7 +86,7 @@ def unit_suite(): ''' return unittest.TestSuite(( unittest.makeSuite(BoxedTextTest), - # unittest.makeSuite(ButtonLinkTest), + unittest.makeSuite(ButtonLinkTest), # unittest.makeSuite(CommentTest), # unittest.makeSuite(ConditionalTest), # unittest.makeSuite(FrameTest), From a5bb01e4245ce6f3a9538d742c1938dc57a06003 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Fri, 27 Jul 2018 15:23:16 +1200 Subject: [PATCH 47/73] Completed custom argument rule tests for button link --- verto/tests/ButtonLinkTest.py | 71 +++++++++---------- verto/tests/assets/button-link/file_true.md | 7 ++ .../file_true_custom_argument_rules.json | 5 ++ .../button-link/file_true_expected.html | 4 ++ .../button-link/file_true_not_provided.md | 7 ++ verto/tests/assets/button-link/link_false.md | 3 + .../link_false_custom_argument_rules.json | 5 ++ .../button-link/link_false_expected.html | 2 + verto/tests/assets/button-link/text_false.md | 7 ++ .../text_false_custom_argument_rules.json | 5 ++ .../button-link/text_false_expected.html | 4 ++ .../button-link/text_false_file_true.md | 6 ++ ...false_file_true_custom_argument_rules.json | 6 ++ .../text_false_file_true_expected.html | 3 + 14 files changed, 97 insertions(+), 38 deletions(-) create mode 100644 verto/tests/assets/button-link/file_true.md create mode 100644 verto/tests/assets/button-link/file_true_custom_argument_rules.json create mode 100644 verto/tests/assets/button-link/file_true_expected.html create mode 100644 verto/tests/assets/button-link/file_true_not_provided.md create mode 100644 verto/tests/assets/button-link/link_false.md create mode 100644 verto/tests/assets/button-link/link_false_custom_argument_rules.json create mode 100644 verto/tests/assets/button-link/link_false_expected.html create mode 100644 verto/tests/assets/button-link/text_false.md create mode 100644 verto/tests/assets/button-link/text_false_custom_argument_rules.json create mode 100644 verto/tests/assets/button-link/text_false_expected.html create mode 100644 verto/tests/assets/button-link/text_false_file_true.md create mode 100644 verto/tests/assets/button-link/text_false_file_true_custom_argument_rules.json create mode 100644 verto/tests/assets/button-link/text_false_file_true_expected.html diff --git a/verto/tests/ButtonLinkTest.py b/verto/tests/ButtonLinkTest.py index 5ee60cdf..71e936ba 100644 --- a/verto/tests/ButtonLinkTest.py +++ b/verto/tests/ButtonLinkTest.py @@ -17,8 +17,7 @@ class ButtonLinkTest(ProcessorTest): ''' def __init__(self, *args, **kwargs): - '''Sets up a generic tag to test that the matches are - occuring appropriately. + '''Sets up a generic tag to test that the matches are occuring appropriately. ''' ProcessorTest.__init__(self, *args, **kwargs) self.processor_name = 'button-link' @@ -28,8 +27,7 @@ def __init__(self, *args, **kwargs): self.block_processor = GenericTagBlockProcessor(self.processor_name, self.ext, Mock()) def test_no_button(self): - '''Tests that the text containing the processor name is - not matched. + '''Tests that the text containing the processor name is not matched. ''' test_string = self.read_test_file(self.processor_name, 'no_button.md') blocks = self.to_blocks(test_string) @@ -40,8 +38,7 @@ def test_no_button(self): self.assertEqual(expected_string, converted_test_string) def test_contains_button(self): - '''Tests that the most generic case of a single match is found - with generic content contained within. + '''Tests that the most generic case of a single match is found with generic content contained within. ''' test_string = self.read_test_file(self.processor_name, 'contains_button.md') blocks = self.to_blocks(test_string) @@ -78,8 +75,7 @@ def test_contains_multiple_buttons(self): self.assertEqual(expected_string, converted_test_string) def test_contains_file_link_button(self): - '''Tests that the file argument works are expected, - internally linking to a file. + '''Tests that the file argument works are expected, internally linking to a file. ''' test_string = self.read_test_file(self.processor_name, 'contains_file_link_button.md') blocks = self.to_blocks(test_string) @@ -92,97 +88,96 @@ def test_contains_file_link_button(self): self.assertEqual(expected_string, converted_test_string) # link text file - def test_custom_arguments_link_required(self): - ''' + def test_custom_arguments_link_false(self): + '''Tests to ensure that button link tag is rendered correctly when link argument is required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/link_required_custom_argument_rules.json').decode('utf-8') + json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/link_false_custom_argument_rules.json').decode('utf-8') custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules ) - test_string = self.read_test_file(self.processor_name, 'link_required.md') + test_string = self.read_test_file(self.processor_name, 'link_false.md') blocks = self.to_blocks(test_string) - # self.assertListEqual([False, False, False], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - self.assertListEqual([True, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) - expected_string = self.read_test_file(self.processor_name, 'link_required_expected.html', strip=True) + expected_string = self.read_test_file(self.processor_name, 'link_false_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - def test_custom_arguments_text_required(self): + def test_custom_arguments_text_false(self): + '''Tests to ensure that button link tag is rendered correctly when text argument is false. ''' - ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/text_required_custom_argument_rules.json').decode('utf-8') + json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/text_false_custom_argument_rules.json').decode('utf-8') custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules ) - test_string = self.read_test_file(self.processor_name, 'text_required.md') + test_string = self.read_test_file(self.processor_name, 'text_false.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, True, False], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) - expected_string = self.read_test_file(self.processor_name, 'text_required_expected.html', strip=True) + expected_string = self.read_test_file(self.processor_name, 'text_false_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - def test_custom_arguments_file_required(self): - ''' + def test_custom_arguments_file_true(self): + '''Tests to ensure that button link tag is rendered correctly when file argument is true. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/file_required_custom_argument_rules.json').decode('utf-8') + json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/file_true_custom_argument_rules.json').decode('utf-8') custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules ) - test_string = self.read_test_file(self.processor_name, 'file_required.md') + test_string = self.read_test_file(self.processor_name, 'file_true.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, True, False], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) - expected_string = self.read_test_file(self.processor_name, 'file_required_expected.html', strip=True) + expected_string = self.read_test_file(self.processor_name, 'file_true_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - def test_custom_arguments_file_and_link_required(self): - ''' + def test_custom_arguments_text_false_file_true(self): + '''Tests to ensure that button link tag is rendered correctly when text argument is false and file argument is true. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/file_and_link_required_custom_argument_rules.json').decode('utf-8') + json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/text_false_file_true_custom_argument_rules.json').decode('utf-8') custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules ) - test_string = self.read_test_file(self.processor_name, 'file_and_link_required.md') + test_string = self.read_test_file(self.processor_name, 'text_false_file_true.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, True, False], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) - expected_string = self.read_test_file(self.processor_name, 'file_and_link_required_expected.html', strip=True) + expected_string = self.read_test_file(self.processor_name, 'text_false_file_true_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) - def test_custom_arguments_file_and_link_required_file_not_provided(self): + def test_custom_arguments_file_true_not_provided(self): + '''Tests to ensure that error is raised when file argument is required and not given. ''' - ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/file_and_link_required_custom_argument_rules.json').decode('utf-8') + json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/file_true_custom_argument_rules.json').decode('utf-8') custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules ) - test_string = self.read_test_file(self.processor_name, 'file_and_link_required_file_not_provided.md') + test_string = self.read_test_file(self.processor_name, 'file_true_not_provided.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, True, False], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) diff --git a/verto/tests/assets/button-link/file_true.md b/verto/tests/assets/button-link/file_true.md new file mode 100644 index 00000000..e58874d3 --- /dev/null +++ b/verto/tests/assets/button-link/file_true.md @@ -0,0 +1,7 @@ +The following interactive has a program that solves the problem for however many cities you want to select by trying out all possible routes, and recording the best so far. You can get a feel for what an intractable problem looks like by seeing how long the interactive takes to solve the problem for different size maps. +Try generating a map with about 5 cities, and press "Start" to solve the problem. + +{button-link link="files/python-example.py" text="Example Code", file="yes"} + +Now try it for 10 cities (twice as many). Does it take twice as long? How about twice as many again (20 cities)? What about 50 cities? Can you guess how long it would take? +You're starting to get a feel for what it means for a problem to be *intractable*. diff --git a/verto/tests/assets/button-link/file_true_custom_argument_rules.json b/verto/tests/assets/button-link/file_true_custom_argument_rules.json new file mode 100644 index 00000000..78238e78 --- /dev/null +++ b/verto/tests/assets/button-link/file_true_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "button-link": { + "file": true + } +} diff --git a/verto/tests/assets/button-link/file_true_expected.html b/verto/tests/assets/button-link/file_true_expected.html new file mode 100644 index 00000000..f7de3f7a --- /dev/null +++ b/verto/tests/assets/button-link/file_true_expected.html @@ -0,0 +1,4 @@ +

    The following interactive has a program that solves the problem for however many cities you want to select by trying out all possible routes, and recording the best so far. You can get a feel for what an intractable problem looks like by seeing how long the interactive takes to solve the problem for different size maps. +Try generating a map with about 5 cities, and press "Start" to solve the problem.

    +Example Code

    Now try it for 10 cities (twice as many). Does it take twice as long? How about twice as many again (20 cities)? What about 50 cities? Can you guess how long it would take? +You're starting to get a feel for what it means for a problem to be intractable.

    diff --git a/verto/tests/assets/button-link/file_true_not_provided.md b/verto/tests/assets/button-link/file_true_not_provided.md new file mode 100644 index 00000000..228328d4 --- /dev/null +++ b/verto/tests/assets/button-link/file_true_not_provided.md @@ -0,0 +1,7 @@ +The following interactive has a program that solves the problem for however many cities you want to select by trying out all possible routes, and recording the best so far. You can get a feel for what an intractable problem looks like by seeing how long the interactive takes to solve the problem for different size maps. +Try generating a map with about 5 cities, and press "Start" to solve the problem. + +{button-link link="http://www.csfieldguide.org.nz/releases/1.9.9/_static/widgets/tract-tsp-basic-v2.html" text="View city trip interactive"} + +Now try it for 10 cities (twice as many). Does it take twice as long? How about twice as many again (20 cities)? What about 50 cities? Can you guess how long it would take? +You're starting to get a feel for what it means for a problem to be *intractable*. diff --git a/verto/tests/assets/button-link/link_false.md b/verto/tests/assets/button-link/link_false.md new file mode 100644 index 00000000..82ede019 --- /dev/null +++ b/verto/tests/assets/button-link/link_false.md @@ -0,0 +1,3 @@ +You can try out this 3D matrix in the following interactive. + +{button-link text="Click for interactive: 3D transform matrix"} diff --git a/verto/tests/assets/button-link/link_false_custom_argument_rules.json b/verto/tests/assets/button-link/link_false_custom_argument_rules.json new file mode 100644 index 00000000..e0a55640 --- /dev/null +++ b/verto/tests/assets/button-link/link_false_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "button-link": { + "link": false + } +} diff --git a/verto/tests/assets/button-link/link_false_expected.html b/verto/tests/assets/button-link/link_false_expected.html new file mode 100644 index 00000000..d3fc1a8e --- /dev/null +++ b/verto/tests/assets/button-link/link_false_expected.html @@ -0,0 +1,2 @@ +

    You can try out this 3D matrix in the following interactive.

    +Click for interactive: 3D transform matrix diff --git a/verto/tests/assets/button-link/text_false.md b/verto/tests/assets/button-link/text_false.md new file mode 100644 index 00000000..83cfeeef --- /dev/null +++ b/verto/tests/assets/button-link/text_false.md @@ -0,0 +1,7 @@ +The following interactive has a program that solves the problem for however many cities you want to select by trying out all possible routes, and recording the best so far. You can get a feel for what an intractable problem looks like by seeing how long the interactive takes to solve the problem for different size maps. +Try generating a map with about 5 cities, and press "Start" to solve the problem. + +{button-link link="http://www.csfieldguide.org.nz/releases/1.9.9/_static/widgets/tract-tsp-basic-v2.html"} + +Now try it for 10 cities (twice as many). Does it take twice as long? How about twice as many again (20 cities)? What about 50 cities? Can you guess how long it would take? +You're starting to get a feel for what it means for a problem to be *intractable*. diff --git a/verto/tests/assets/button-link/text_false_custom_argument_rules.json b/verto/tests/assets/button-link/text_false_custom_argument_rules.json new file mode 100644 index 00000000..31410a7e --- /dev/null +++ b/verto/tests/assets/button-link/text_false_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "button-link": { + "text": false + } +} diff --git a/verto/tests/assets/button-link/text_false_expected.html b/verto/tests/assets/button-link/text_false_expected.html new file mode 100644 index 00000000..724289c8 --- /dev/null +++ b/verto/tests/assets/button-link/text_false_expected.html @@ -0,0 +1,4 @@ +

    The following interactive has a program that solves the problem for however many cities you want to select by trying out all possible routes, and recording the best so far. You can get a feel for what an intractable problem looks like by seeing how long the interactive takes to solve the problem for different size maps. +Try generating a map with about 5 cities, and press "Start" to solve the problem.

    +None

    Now try it for 10 cities (twice as many). Does it take twice as long? How about twice as many again (20 cities)? What about 50 cities? Can you guess how long it would take? +You're starting to get a feel for what it means for a problem to be intractable.

    diff --git a/verto/tests/assets/button-link/text_false_file_true.md b/verto/tests/assets/button-link/text_false_file_true.md new file mode 100644 index 00000000..9b0c6868 --- /dev/null +++ b/verto/tests/assets/button-link/text_false_file_true.md @@ -0,0 +1,6 @@ +The following interactive has a program that solves the problem for however many cities you want to select by trying out all possible routes, and recording the best so far. You can get a feel for what an intractable problem looks like by seeing how long the interactive takes to solve the problem for different size maps. +Try generating a map with about 5 cities, and press "Start" to solve the problem. + +{button-link link="link.html" file="yes"} + +Now try it for 10 cities (twice as many). Does it take twice as long? How about twice as many again (20 cities)? What about 50 cities? Can you guess how long it would take? diff --git a/verto/tests/assets/button-link/text_false_file_true_custom_argument_rules.json b/verto/tests/assets/button-link/text_false_file_true_custom_argument_rules.json new file mode 100644 index 00000000..936d4ba9 --- /dev/null +++ b/verto/tests/assets/button-link/text_false_file_true_custom_argument_rules.json @@ -0,0 +1,6 @@ +{ + "button-link": { + "file": true, + "text": false + } +} diff --git a/verto/tests/assets/button-link/text_false_file_true_expected.html b/verto/tests/assets/button-link/text_false_file_true_expected.html new file mode 100644 index 00000000..caf23058 --- /dev/null +++ b/verto/tests/assets/button-link/text_false_file_true_expected.html @@ -0,0 +1,3 @@ +

    The following interactive has a program that solves the problem for however many cities you want to select by trying out all possible routes, and recording the best so far. You can get a feel for what an intractable problem looks like by seeing how long the interactive takes to solve the problem for different size maps. +Try generating a map with about 5 cities, and press "Start" to solve the problem.

    +None

    Now try it for 10 cities (twice as many). Does it take twice as long? How about twice as many again (20 cities)? What about 50 cities? Can you guess how long it would take?

    From 8d841bb855b8a3fa1ef07c75e9f60039c2756ac5 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Fri, 27 Jul 2018 15:52:04 +1200 Subject: [PATCH 48/73] WIP adding tests for custom argument rules to glossary --- verto/tests/ConditionalTest.py | 5 ++ verto/tests/FrameTest.py | 5 ++ verto/tests/GlossaryLinkTest.py | 62 ++++++++++++++----- .../glossary-link/reference_text_true.md | 1 + .../reference_text_true_expected.html | 1 + verto/tests/start_tests.py | 8 +-- 6 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 verto/tests/assets/glossary-link/reference_text_true.md create mode 100644 verto/tests/assets/glossary-link/reference_text_true_expected.html diff --git a/verto/tests/ConditionalTest.py b/verto/tests/ConditionalTest.py index 36d491ea..598474d5 100644 --- a/verto/tests/ConditionalTest.py +++ b/verto/tests/ConditionalTest.py @@ -10,6 +10,11 @@ class ConditionalTest(ProcessorTest): '''Conditionals expect complex output and need to match many possible conditions. + + Note: + - No tests for custom argument rules because it doesn't + make sense to require one or more of these arguments + to be given. ''' def __init__(self, *args, **kwargs): diff --git a/verto/tests/FrameTest.py b/verto/tests/FrameTest.py index 79fefb0c..d0fbf56f 100644 --- a/verto/tests/FrameTest.py +++ b/verto/tests/FrameTest.py @@ -11,6 +11,11 @@ class FrameTest(ProcessorTest): '''The iframe processor inherits from the generic tag procesor. The tests contained here test that arguments and the output (html-template) work as expected. + + Note: + - No tests for custom argument rules because there is only + one argument and does not make sense to have a tag with no + arguments. ''' def __init__(self, *args, **kwargs): diff --git a/verto/tests/GlossaryLinkTest.py b/verto/tests/GlossaryLinkTest.py index c1a92672..ed723a4c 100644 --- a/verto/tests/GlossaryLinkTest.py +++ b/verto/tests/GlossaryLinkTest.py @@ -1,6 +1,10 @@ import markdown import re from unittest.mock import Mock +from collections import OrderedDict +import json +import pkg_resources + from verto.VertoExtension import VertoExtension from verto.processors.GlossaryLinkPattern import GlossaryLinkPattern from verto.tests.ProcessorTest import ProcessorTest @@ -22,8 +26,7 @@ def __init__(self, *args, **kwargs): self.ext.jinja_templates = {self.processor_name: ProcessorTest.loadJinjaTemplate(self, self.processor_name)} def test_single_word_term(self): - '''Tests that a single glossary link functions - as expected. + '''Tests that a single glossary link functions as expected. ''' test_string = self.read_test_file(self.processor_name, 'single_word_term.md') @@ -59,8 +62,7 @@ def test_multiple_word_term(self): self.assertDictEqual(expected_glossary_terms, glossary_terms) def test_reference_text_given(self): - '''Tests that the reference argument is processed - and that details are stored in the final result. + '''Tests that the reference argument is processed and that details are stored in the final result. ''' test_string = self.read_test_file(self.processor_name, 'reference_text_given.md') @@ -79,8 +81,7 @@ def test_reference_text_given(self): self.assertDictEqual(expected_glossary_terms, glossary_terms) def test_leading_inline_text(self): - '''Tests that glossary links are matched and processed - even when there is text before the tag. + '''Tests that glossary links are matched and processed even when there is text before the tag. ''' test_string = self.read_test_file(self.processor_name, 'leading_inline_text.md') @@ -98,8 +99,7 @@ def test_leading_inline_text(self): self.assertDictEqual(expected_glossary_terms, glossary_terms) def test_trailing_inline_text(self): - '''Tests that glossary links are matched and processed - even when there is text after the tag. + '''Tests that glossary links are matched and processed even when there is text after the tag. ''' test_string = self.read_test_file(self.processor_name, 'trailing_inline_text.md') @@ -117,8 +117,7 @@ def test_trailing_inline_text(self): self.assertDictEqual(expected_glossary_terms, glossary_terms) def test_leading_and_trailing_inline_text(self): - '''Tests that glossary links are matched and processed - even when there is text before and after the tag. + '''Tests that glossary links are matched and processed even when there is text before and after the tag. ''' test_string = self.read_test_file(self.processor_name, 'leading_and_trailing_inline_text.md') @@ -136,9 +135,7 @@ def test_leading_and_trailing_inline_text(self): self.assertDictEqual(expected_glossary_terms, glossary_terms) def test_multiple_terms(self): - '''Tests that multiple glossary tags are matched and - that tags with the reference argument store information - for the final result. + '''Tests that multiple glossary tags are matched and that tags with the reference argument store information for the final result. ''' test_string = self.read_test_file(self.processor_name, 'multiple_terms.md') @@ -159,9 +156,7 @@ def test_multiple_terms(self): self.assertDictEqual(expected_glossary_terms, glossary_terms) def test_multiple_reference_text(self): - '''Tests that when the reference argument is used in - multiple tags that all references are stored for the - final verto result. + '''Tests that when the reference argument is used in multiple tags that all references are stored for the final verto result. ''' test_string = self.read_test_file(self.processor_name, 'multiple_reference_text.md') @@ -183,6 +178,41 @@ def test_multiple_reference_text(self): } self.assertDictEqual(expected_glossary_terms, glossary_terms) + def test_custom_arguments_reference_text_true(self): + '''Tests that glossary tag is rendered correctly when reference text is required. + ''' + test_string = self.read_test_file(self.processor_name, 'reference_text_true.md') + + processor = GlossaryLinkPattern(self.ext, self.md.parser) + self.assertIsNotNone(re.search(processor.compiled_re, test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'reference_text_true_expected.html', strip=True).strip() + self.assertEqual(expected_string, converted_test_string) + + glossary_terms = self.verto_extension.glossary_terms + expected_glossary_terms = { + 'chomsky-hierarchy': + [('Formal languages', 'glossary-chomsky-hierarchy')] + } + self.assertDictEqual(expected_glossary_terms, glossary_terms) + + def test_custom_arguments_reference_text_true_not_provided(self): + '''Tests to ensure that correct error is raised when reference text is required and not provided. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/glossary-link/referencee_text_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'reference_text_true_not_provided.md') + processor = ImageInlinePattern(self.ext, self.md.parser) + self.assertIsNotNone(re.search(processor.compiled_re, test_string)) + + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) + #~ # Doc Tests #~ diff --git a/verto/tests/assets/glossary-link/reference_text_true.md b/verto/tests/assets/glossary-link/reference_text_true.md new file mode 100644 index 00000000..8c3c9ff5 --- /dev/null +++ b/verto/tests/assets/glossary-link/reference_text_true.md @@ -0,0 +1 @@ +{glossary-link term="chomsky-hierarchy" reference-text="Formal languages"}Chomsky Hierarchy{glossary-link end} diff --git a/verto/tests/assets/glossary-link/reference_text_true_expected.html b/verto/tests/assets/glossary-link/reference_text_true_expected.html new file mode 100644 index 00000000..94bb3629 --- /dev/null +++ b/verto/tests/assets/glossary-link/reference_text_true_expected.html @@ -0,0 +1 @@ +

    Chomsky Hierarchy

    diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index ed77e7c4..3d338b21 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -87,10 +87,10 @@ def unit_suite(): return unittest.TestSuite(( unittest.makeSuite(BoxedTextTest), unittest.makeSuite(ButtonLinkTest), - # unittest.makeSuite(CommentTest), - # unittest.makeSuite(ConditionalTest), - # unittest.makeSuite(FrameTest), - # unittest.makeSuite(GlossaryLinkTest), + unittest.makeSuite(CommentTest), + unittest.makeSuite(ConditionalTest), + unittest.makeSuite(FrameTest), + unittest.makeSuite(GlossaryLinkTest), # unittest.makeSuite(HeadingTest), unittest.makeSuite(ImageInlineTest), unittest.makeSuite(ImageTagTest), From 4c2552b36ce7ba0df23e0fc5b7c94afbba452068 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Sun, 29 Jul 2018 11:52:12 +1200 Subject: [PATCH 49/73] Completed tests for custom rules for glossary --- verto/tests/GlossaryLinkTest.py | 9 +++++---- .../reference_text_true_custom_argument_rules.json | 5 +++++ .../glossary-link/reference_text_true_not_provided.md | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 verto/tests/assets/glossary-link/reference_text_true_custom_argument_rules.json create mode 100644 verto/tests/assets/glossary-link/reference_text_true_not_provided.md diff --git a/verto/tests/GlossaryLinkTest.py b/verto/tests/GlossaryLinkTest.py index ed723a4c..cb56c7e7 100644 --- a/verto/tests/GlossaryLinkTest.py +++ b/verto/tests/GlossaryLinkTest.py @@ -7,6 +7,7 @@ from verto.VertoExtension import VertoExtension from verto.processors.GlossaryLinkPattern import GlossaryLinkPattern +from verto.errors.ArgumentMissingError import ArgumentMissingError from verto.tests.ProcessorTest import ProcessorTest @@ -200,7 +201,7 @@ def test_custom_arguments_reference_text_true(self): def test_custom_arguments_reference_text_true_not_provided(self): '''Tests to ensure that correct error is raised when reference text is required and not provided. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/glossary-link/referencee_text_true_custom_argument_rules.json').decode('utf-8') + json_data = pkg_resources.resource_string('verto', 'tests/assets/glossary-link/reference_text_true_custom_argument_rules.json').decode('utf-8') custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], @@ -208,14 +209,14 @@ def test_custom_arguments_reference_text_true_not_provided(self): ) test_string = self.read_test_file(self.processor_name, 'reference_text_true_not_provided.md') - processor = ImageInlinePattern(self.ext, self.md.parser) + processor = GlossaryLinkPattern(self.ext, self.md.parser) self.assertIsNotNone(re.search(processor.compiled_re, test_string)) self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) - #~ + # ~ # Doc Tests - #~ + # ~ def test_doc_example_basic(self): '''A basic example of common useage. diff --git a/verto/tests/assets/glossary-link/reference_text_true_custom_argument_rules.json b/verto/tests/assets/glossary-link/reference_text_true_custom_argument_rules.json new file mode 100644 index 00000000..580dc5de --- /dev/null +++ b/verto/tests/assets/glossary-link/reference_text_true_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "glossary-link": { + "reference-text": true + } +} diff --git a/verto/tests/assets/glossary-link/reference_text_true_not_provided.md b/verto/tests/assets/glossary-link/reference_text_true_not_provided.md new file mode 100644 index 00000000..e6b1ee8a --- /dev/null +++ b/verto/tests/assets/glossary-link/reference_text_true_not_provided.md @@ -0,0 +1 @@ +{glossary-link term="chomsky-hierarchy"}Chomsky Hierarchy{glossary-link end} From 49aa66e3f45cc7473409dbb24c475c670d2c0211 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Sun, 29 Jul 2018 11:53:00 +1200 Subject: [PATCH 50/73] Update sphinx_rtd_theme from 0.4.0 to 0.4.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 42b1452f..f381beb1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,4 @@ setuptools==39.2.0 # Required dependencies for building documentation sphinx==1.7.5 -sphinx_rtd_theme==0.4.0 +sphinx_rtd_theme==0.4.1 From 26840f8fbff67ae5841f3ffc29a23fa2d6935ad6 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Sun, 29 Jul 2018 13:08:49 +1200 Subject: [PATCH 51/73] WIP adding tests to interactives --- verto/tests/HeadingTest.py | 6 +- verto/tests/InteractiveTest.py | 141 +++++++++++++++++- .../assets/interactive/parameters_true.md | 1 + ...parameters_true_custom_argument_rules.json | 5 + .../interactive/parameters_true_expected.html | 6 + verto/tests/assets/interactive/slug_false.md | 1 + .../slug_false_custom_argument_rules.json | 5 + .../interactive/slug_false_expected.html | 6 + .../interactive/text_and_thumbnail_true.md | 1 + ..._thumbnail_true_custom_argument_rules.json | 6 + .../text_and_thumbnail_true_expected.html | 6 + verto/tests/assets/interactive/text_true.md | 1 + .../text_true_custom_argument_rules.json | 5 + .../interactive/text_true_expected.html | 6 + .../interactive/text_true_not_provided.md | 1 + .../assets/interactive/thumbnail_true.md | 1 + .../thumbnail_true_custom_argument_rules.json | 5 + .../interactive/thumbnail_true_expected.html | 6 + verto/tests/assets/interactive/type_false.md | 1 + .../type_false_custom_argument_rules.json | 5 + verto/tests/start_tests.py | 20 +-- 21 files changed, 219 insertions(+), 16 deletions(-) create mode 100644 verto/tests/assets/interactive/parameters_true.md create mode 100644 verto/tests/assets/interactive/parameters_true_custom_argument_rules.json create mode 100644 verto/tests/assets/interactive/parameters_true_expected.html create mode 100644 verto/tests/assets/interactive/slug_false.md create mode 100644 verto/tests/assets/interactive/slug_false_custom_argument_rules.json create mode 100644 verto/tests/assets/interactive/slug_false_expected.html create mode 100644 verto/tests/assets/interactive/text_and_thumbnail_true.md create mode 100644 verto/tests/assets/interactive/text_and_thumbnail_true_custom_argument_rules.json create mode 100644 verto/tests/assets/interactive/text_and_thumbnail_true_expected.html create mode 100644 verto/tests/assets/interactive/text_true.md create mode 100644 verto/tests/assets/interactive/text_true_custom_argument_rules.json create mode 100644 verto/tests/assets/interactive/text_true_expected.html create mode 100644 verto/tests/assets/interactive/text_true_not_provided.md create mode 100644 verto/tests/assets/interactive/thumbnail_true.md create mode 100644 verto/tests/assets/interactive/thumbnail_true_custom_argument_rules.json create mode 100644 verto/tests/assets/interactive/thumbnail_true_expected.html create mode 100644 verto/tests/assets/interactive/type_false.md create mode 100644 verto/tests/assets/interactive/type_false_custom_argument_rules.json diff --git a/verto/tests/HeadingTest.py b/verto/tests/HeadingTest.py index a77bcbbd..7bfcb5f6 100644 --- a/verto/tests/HeadingTest.py +++ b/verto/tests/HeadingTest.py @@ -1,4 +1,3 @@ -import unittest import markdown from unittest.mock import Mock @@ -7,6 +6,7 @@ from verto.tests.ProcessorTest import ProcessorTest from verto.utils.HeadingNode import HeadingNode + class HeadingTest(ProcessorTest): '''The heading processor is a unique processor that replaces the functionality of the default markdown (#) heading. We allow for @@ -157,9 +157,9 @@ def test_multiple_roots_zero_level(self): ) self.assertTupleEqual(tree, expected_tree) - #~ + # ~ # Doc Tests - #~ + # ~ def test_doc_example_basic(self): '''An example of simplistic usage. diff --git a/verto/tests/InteractiveTest.py b/verto/tests/InteractiveTest.py index ba00cd24..49387ad7 100644 --- a/verto/tests/InteractiveTest.py +++ b/verto/tests/InteractiveTest.py @@ -1,6 +1,8 @@ import markdown from unittest.mock import Mock -from collections import defaultdict +from collections import defaultdict, OrderedDict +import json +import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.InteractiveBlockProcessor import InteractiveBlockProcessor @@ -227,9 +229,142 @@ def test_multiple_interactives(self): } self.assertEqual(self.verto_extension.required_files, required_files) - #~ + def test_custom_arguments_slug_false(self): + '''Tests to ensure that interactive tag is rendered correctly when slug argument is not required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/slug_false_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'slug_false.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'slug_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_type_false(self): + '''Tests to ensure that interactive tag is rendered correctly when type argument is not required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/type_false_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'type_false.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'type_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_text_true(self): + '''Tests to ensure that interactive tag is rendered correctly when text argument is not required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/text_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'text_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'text_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_parameters_true(self): + '''Tests to ensure that interactive tag is rendered correctly when parameters argument is not required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/parameters_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'parameters_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'parameters_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_thumbnail_true(self): + '''Tests to ensure that interactive tag is rendered correctly when thumbnail argument is not required. + ''' + pass + json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/thumbnail_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'thumbnail_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'thumbnail_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_text_true_not_provided(self): + '''Tests to ensure that correct error is raised when text is required and not provided. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/text_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'text_true_not_provided.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) + + def test_custom_arguments_text_and_thumbnail_true(self): + '''Tests to ensure that interactive tag is rendered correctly when text and thumbnail arguments are required. + ''' + pass + json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/text_and_thumbnail_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'text_and_thumbnail_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'text_and_thumbnail_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + # ~ # Doc Tests - #~ + # ~ def test_doc_example_in_page(self): '''Example of an in-page interactive. diff --git a/verto/tests/assets/interactive/parameters_true.md b/verto/tests/assets/interactive/parameters_true.md new file mode 100644 index 00000000..aa820f2d --- /dev/null +++ b/verto/tests/assets/interactive/parameters_true.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive/parameters_true_custom_argument_rules.json b/verto/tests/assets/interactive/parameters_true_custom_argument_rules.json new file mode 100644 index 00000000..a7b8184b --- /dev/null +++ b/verto/tests/assets/interactive/parameters_true_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "interactive": { + "parameters": true + } +} diff --git a/verto/tests/assets/interactive/parameters_true_expected.html b/verto/tests/assets/interactive/parameters_true_expected.html new file mode 100644 index 00000000..fea9ee9c --- /dev/null +++ b/verto/tests/assets/interactive/parameters_true_expected.html @@ -0,0 +1,6 @@ + + +
    +Binary Cards Interactive +
    +
    diff --git a/verto/tests/assets/interactive/slug_false.md b/verto/tests/assets/interactive/slug_false.md new file mode 100644 index 00000000..25bb7b1e --- /dev/null +++ b/verto/tests/assets/interactive/slug_false.md @@ -0,0 +1 @@ +{interactive type="whole-page" text="cats" thumbnail="interactives/binary-cards/img/binarycards.png"} diff --git a/verto/tests/assets/interactive/slug_false_custom_argument_rules.json b/verto/tests/assets/interactive/slug_false_custom_argument_rules.json new file mode 100644 index 00000000..8511bdbd --- /dev/null +++ b/verto/tests/assets/interactive/slug_false_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "interactive": { + "slug": false + } +} diff --git a/verto/tests/assets/interactive/slug_false_expected.html b/verto/tests/assets/interactive/slug_false_expected.html new file mode 100644 index 00000000..fe1a17a5 --- /dev/null +++ b/verto/tests/assets/interactive/slug_false_expected.html @@ -0,0 +1,6 @@ + + +
    +cats +
    +
    diff --git a/verto/tests/assets/interactive/text_and_thumbnail_true.md b/verto/tests/assets/interactive/text_and_thumbnail_true.md new file mode 100644 index 00000000..e82bd8f7 --- /dev/null +++ b/verto/tests/assets/interactive/text_and_thumbnail_true.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" text="cats" thumbnail="interactives/binary-cards/img/binarycards.png"} diff --git a/verto/tests/assets/interactive/text_and_thumbnail_true_custom_argument_rules.json b/verto/tests/assets/interactive/text_and_thumbnail_true_custom_argument_rules.json new file mode 100644 index 00000000..3dcfbe1f --- /dev/null +++ b/verto/tests/assets/interactive/text_and_thumbnail_true_custom_argument_rules.json @@ -0,0 +1,6 @@ +{ + "interactive": { + "text": true, + "thumbnail": true + } +} diff --git a/verto/tests/assets/interactive/text_and_thumbnail_true_expected.html b/verto/tests/assets/interactive/text_and_thumbnail_true_expected.html new file mode 100644 index 00000000..fe1a17a5 --- /dev/null +++ b/verto/tests/assets/interactive/text_and_thumbnail_true_expected.html @@ -0,0 +1,6 @@ + + +
    +cats +
    +
    diff --git a/verto/tests/assets/interactive/text_true.md b/verto/tests/assets/interactive/text_true.md new file mode 100644 index 00000000..e82bd8f7 --- /dev/null +++ b/verto/tests/assets/interactive/text_true.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" text="cats" thumbnail="interactives/binary-cards/img/binarycards.png"} diff --git a/verto/tests/assets/interactive/text_true_custom_argument_rules.json b/verto/tests/assets/interactive/text_true_custom_argument_rules.json new file mode 100644 index 00000000..6c3ddb4b --- /dev/null +++ b/verto/tests/assets/interactive/text_true_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "interactive": { + "text": true + } +} diff --git a/verto/tests/assets/interactive/text_true_expected.html b/verto/tests/assets/interactive/text_true_expected.html new file mode 100644 index 00000000..fe1a17a5 --- /dev/null +++ b/verto/tests/assets/interactive/text_true_expected.html @@ -0,0 +1,6 @@ + + +
    +cats +
    +
    diff --git a/verto/tests/assets/interactive/text_true_not_provided.md b/verto/tests/assets/interactive/text_true_not_provided.md new file mode 100644 index 00000000..4625c3a2 --- /dev/null +++ b/verto/tests/assets/interactive/text_true_not_provided.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" thumbnail="interactives/binary-cards/img/binarycards.png"} diff --git a/verto/tests/assets/interactive/thumbnail_true.md b/verto/tests/assets/interactive/thumbnail_true.md new file mode 100644 index 00000000..4625c3a2 --- /dev/null +++ b/verto/tests/assets/interactive/thumbnail_true.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" thumbnail="interactives/binary-cards/img/binarycards.png"} diff --git a/verto/tests/assets/interactive/thumbnail_true_custom_argument_rules.json b/verto/tests/assets/interactive/thumbnail_true_custom_argument_rules.json new file mode 100644 index 00000000..1115c139 --- /dev/null +++ b/verto/tests/assets/interactive/thumbnail_true_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "interactive": { + "thumbnail": true + } +} diff --git a/verto/tests/assets/interactive/thumbnail_true_expected.html b/verto/tests/assets/interactive/thumbnail_true_expected.html new file mode 100644 index 00000000..9ec659d6 --- /dev/null +++ b/verto/tests/assets/interactive/thumbnail_true_expected.html @@ -0,0 +1,6 @@ + + +
    +Click to load binary-cards +
    +
    diff --git a/verto/tests/assets/interactive/type_false.md b/verto/tests/assets/interactive/type_false.md new file mode 100644 index 00000000..7efd0ef9 --- /dev/null +++ b/verto/tests/assets/interactive/type_false.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive/type_false_custom_argument_rules.json b/verto/tests/assets/interactive/type_false_custom_argument_rules.json new file mode 100644 index 00000000..6045695a --- /dev/null +++ b/verto/tests/assets/interactive/type_false_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "interactive": { + "type": false + } +} diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 3d338b21..cc78a259 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -85,17 +85,17 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - unittest.makeSuite(BoxedTextTest), - unittest.makeSuite(ButtonLinkTest), - unittest.makeSuite(CommentTest), - unittest.makeSuite(ConditionalTest), - unittest.makeSuite(FrameTest), - unittest.makeSuite(GlossaryLinkTest), + # unittest.makeSuite(BoxedTextTest), + # unittest.makeSuite(ButtonLinkTest), + # unittest.makeSuite(CommentTest), + # unittest.makeSuite(ConditionalTest), + # unittest.makeSuite(FrameTest), + # unittest.makeSuite(GlossaryLinkTest), # unittest.makeSuite(HeadingTest), - unittest.makeSuite(ImageInlineTest), - unittest.makeSuite(ImageTagTest), - unittest.makeSuite(ImageContainerTest), - # unittest.makeSuite(InteractiveTest), + # unittest.makeSuite(ImageInlineTest), + # unittest.makeSuite(ImageTagTest), + # unittest.makeSuite(ImageContainerTest), + unittest.makeSuite(InteractiveTest), # unittest.makeSuite(JinjaTest), # unittest.makeSuite(PanelTest), # unittest.makeSuite(SaveTitleTest), From 5356004c12b51bdce9ddf622ab524b438ca29f35 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 30 Jul 2018 11:21:18 +1200 Subject: [PATCH 52/73] Completed tests for interactives --- verto/tests/InteractiveTest.py | 41 ------------------- verto/tests/assets/interactive/slug_false.md | 1 - .../slug_false_custom_argument_rules.json | 5 --- .../interactive/slug_false_expected.html | 6 --- verto/tests/assets/interactive/type_false.md | 1 - .../type_false_custom_argument_rules.json | 5 --- 6 files changed, 59 deletions(-) delete mode 100644 verto/tests/assets/interactive/slug_false.md delete mode 100644 verto/tests/assets/interactive/slug_false_custom_argument_rules.json delete mode 100644 verto/tests/assets/interactive/slug_false_expected.html delete mode 100644 verto/tests/assets/interactive/type_false.md delete mode 100644 verto/tests/assets/interactive/type_false_custom_argument_rules.json diff --git a/verto/tests/InteractiveTest.py b/verto/tests/InteractiveTest.py index 49387ad7..19040510 100644 --- a/verto/tests/InteractiveTest.py +++ b/verto/tests/InteractiveTest.py @@ -124,7 +124,6 @@ def test_whole_page_thumbnail(self): } self.assertEqual(self.verto_extension.required_files, required_files) - def test_whole_page_thumbnail_parameters(self): '''Test whole page interactive with thumbnail and parameters is correctly parsed and thumbnail path is added to required files. ''' @@ -229,44 +228,6 @@ def test_multiple_interactives(self): } self.assertEqual(self.verto_extension.required_files, required_files) - def test_custom_arguments_slug_false(self): - '''Tests to ensure that interactive tag is rendered correctly when slug argument is not required. - ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/slug_false_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) - verto_extension_custom_rules = VertoExtension( - processors=[self.processor_name], - custom_argument_rules=custom_argument_rules - ) - - test_string = self.read_test_file(self.processor_name, 'slug_false.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) - expected_string = self.read_test_file(self.processor_name, 'slug_false_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - def test_custom_arguments_type_false(self): - '''Tests to ensure that interactive tag is rendered correctly when type argument is not required. - ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/type_false_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) - verto_extension_custom_rules = VertoExtension( - processors=[self.processor_name], - custom_argument_rules=custom_argument_rules - ) - - test_string = self.read_test_file(self.processor_name, 'type_false.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) - expected_string = self.read_test_file(self.processor_name, 'type_false_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - def test_custom_arguments_text_true(self): '''Tests to ensure that interactive tag is rendered correctly when text argument is not required. ''' @@ -308,7 +269,6 @@ def test_custom_arguments_parameters_true(self): def test_custom_arguments_thumbnail_true(self): '''Tests to ensure that interactive tag is rendered correctly when thumbnail argument is not required. ''' - pass json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/thumbnail_true_custom_argument_rules.json').decode('utf-8') custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) verto_extension_custom_rules = VertoExtension( @@ -345,7 +305,6 @@ def test_custom_arguments_text_true_not_provided(self): def test_custom_arguments_text_and_thumbnail_true(self): '''Tests to ensure that interactive tag is rendered correctly when text and thumbnail arguments are required. ''' - pass json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/text_and_thumbnail_true_custom_argument_rules.json').decode('utf-8') custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) verto_extension_custom_rules = VertoExtension( diff --git a/verto/tests/assets/interactive/slug_false.md b/verto/tests/assets/interactive/slug_false.md deleted file mode 100644 index 25bb7b1e..00000000 --- a/verto/tests/assets/interactive/slug_false.md +++ /dev/null @@ -1 +0,0 @@ -{interactive type="whole-page" text="cats" thumbnail="interactives/binary-cards/img/binarycards.png"} diff --git a/verto/tests/assets/interactive/slug_false_custom_argument_rules.json b/verto/tests/assets/interactive/slug_false_custom_argument_rules.json deleted file mode 100644 index 8511bdbd..00000000 --- a/verto/tests/assets/interactive/slug_false_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "interactive": { - "slug": false - } -} diff --git a/verto/tests/assets/interactive/slug_false_expected.html b/verto/tests/assets/interactive/slug_false_expected.html deleted file mode 100644 index fe1a17a5..00000000 --- a/verto/tests/assets/interactive/slug_false_expected.html +++ /dev/null @@ -1,6 +0,0 @@ - - -
    -cats -
    -
    diff --git a/verto/tests/assets/interactive/type_false.md b/verto/tests/assets/interactive/type_false.md deleted file mode 100644 index 7efd0ef9..00000000 --- a/verto/tests/assets/interactive/type_false.md +++ /dev/null @@ -1 +0,0 @@ -{interactive slug="binary-cards" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive/type_false_custom_argument_rules.json b/verto/tests/assets/interactive/type_false_custom_argument_rules.json deleted file mode 100644 index 6045695a..00000000 --- a/verto/tests/assets/interactive/type_false_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "interactive": { - "type": false - } -} From 435a0912e18b61b839cf65690942f271ad2df2ba Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 30 Jul 2018 12:38:47 +1200 Subject: [PATCH 53/73] Added tests to panel and video --- verto/tests/JinjaTest.py | 4 +- verto/tests/PanelTest.py | 80 +++++++++++++++++++ verto/tests/VideoTest.py | 23 ++++++ .../tests/assets/interactive/subtitle_true.md | 9 +++ verto/tests/assets/panel/expanded_true.md | 9 +++ .../expanded_true_custom_argument_rules.json | 5 ++ .../assets/panel/expanded_true_expected.html | 8 ++ verto/tests/assets/panel/subtitle_true.md | 9 +++ .../subtitle_true_custom_argument_rules.json | 5 ++ .../assets/panel/subtitle_true_expected.html | 8 ++ .../panel/subtitle_true_not_provided.md | 9 +++ verto/tests/assets/panel/type_false.md | 7 ++ .../type_false_custom_argument_rules.json | 5 ++ .../assets/panel/type_false_expected.html | 8 ++ verto/tests/assets/video/url_false.md | 5 ++ .../url_false_custom_argument_rules.json | 5 ++ .../assets/video/url_false_expected.html | 3 + verto/tests/start_tests.py | 48 +++++------ 18 files changed, 224 insertions(+), 26 deletions(-) create mode 100644 verto/tests/assets/interactive/subtitle_true.md create mode 100644 verto/tests/assets/panel/expanded_true.md create mode 100644 verto/tests/assets/panel/expanded_true_custom_argument_rules.json create mode 100644 verto/tests/assets/panel/expanded_true_expected.html create mode 100644 verto/tests/assets/panel/subtitle_true.md create mode 100644 verto/tests/assets/panel/subtitle_true_custom_argument_rules.json create mode 100644 verto/tests/assets/panel/subtitle_true_expected.html create mode 100644 verto/tests/assets/panel/subtitle_true_not_provided.md create mode 100644 verto/tests/assets/panel/type_false.md create mode 100644 verto/tests/assets/panel/type_false_custom_argument_rules.json create mode 100644 verto/tests/assets/panel/type_false_expected.html create mode 100644 verto/tests/assets/video/url_false.md create mode 100644 verto/tests/assets/video/url_false_custom_argument_rules.json create mode 100644 verto/tests/assets/video/url_false_expected.html diff --git a/verto/tests/JinjaTest.py b/verto/tests/JinjaTest.py index effce2e2..680bb64f 100644 --- a/verto/tests/JinjaTest.py +++ b/verto/tests/JinjaTest.py @@ -1,7 +1,7 @@ import markdown -from verto.VertoExtension import VertoExtension from verto.tests.ProcessorTest import ProcessorTest + class JinjaTest(ProcessorTest): '''Unescape special characters within Django blocks. ''' @@ -13,7 +13,7 @@ def __init__(self, *args, **kwargs): self.processor_name = 'jinja' def test_doc_example_basic(self): - '''Checks that basic usecase works as expected. + '''Checks that basic use case works as expected. ''' test_string = self.read_test_file(self.processor_name, 'doc_example_basic_usage.md') diff --git a/verto/tests/PanelTest.py b/verto/tests/PanelTest.py index 74134496..03fba06c 100644 --- a/verto/tests/PanelTest.py +++ b/verto/tests/PanelTest.py @@ -1,9 +1,13 @@ import markdown from unittest.mock import Mock +from collections import OrderedDict +import json +import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.PanelBlockProcessor import PanelBlockProcessor from verto.errors.TagNotMatchedError import TagNotMatchedError +from verto.errors.ArgumentMissingError import ArgumentMissingError from verto.errors.ArgumentValueError import ArgumentValueError from verto.errors.PanelMissingTitleError import PanelMissingTitleError from verto.errors.PanelMissingSubtitleError import PanelMissingSubtitleError @@ -367,6 +371,82 @@ def test_panel_block_missing_whitespace(self): self.assertRaises(StyleError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) +# type subtitle expanded + def test_custom_arguments_type_false(self): + '''Tests to ensure that panel tag is rendered correctly when type argument is not required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/panel/type_false_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'type_false.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'type_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_subtitle_true(self): + '''Tests to ensure that panel tag is rendered correctly when subtitle argument is required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/panel/subtitle_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'subtitle_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, False, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'subtitle_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_expanded_true(self): + '''Tests to ensure that panel tag is rendered correctly when expanded argument is required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/panel/expanded_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'expanded_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, False, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'expanded_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_subtitle_true_not_provided(self): + '''Tests to ensure that correct error is raised when subtitle is required and not provided. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/panel/subtitle_true_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'subtitle_true_not_provided.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, False, False, True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) + + # ~ # Doc Tests # ~ diff --git a/verto/tests/VideoTest.py b/verto/tests/VideoTest.py index 19ccffb2..3e51d437 100644 --- a/verto/tests/VideoTest.py +++ b/verto/tests/VideoTest.py @@ -1,8 +1,12 @@ import markdown from unittest.mock import Mock +from collections import OrderedDict +import json +import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.VideoBlockProcessor import VideoBlockProcessor +from verto.errors.ArgumentMissingError import ArgumentMissingError from verto.errors.NoVideoIdentifierError import NoVideoIdentifierError from verto.errors.UnsupportedVideoPlayerError import UnsupportedVideoPlayerError from verto.tests.ProcessorTest import ProcessorTest @@ -173,6 +177,25 @@ def test_contains_multiple_videos(self): expected_file_string = self.read_test_file(self.processor_name, 'contains_multiple_videos_expected.html', strip=True) self.assertEqual(converted_test_string, expected_file_string) + def test_url_false_custom_argument_rules(self): + '''Tests to ensure that video tag is rendered correctly when url argument is not required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/video/url_false_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'url_false.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, False, False], [VideoBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'url_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + # ~ # Doc Tests # ~ diff --git a/verto/tests/assets/interactive/subtitle_true.md b/verto/tests/assets/interactive/subtitle_true.md new file mode 100644 index 00000000..68119833 --- /dev/null +++ b/verto/tests/assets/interactive/subtitle_true.md @@ -0,0 +1,9 @@ +{panel type="note" subtitle="true"} + +# Heading + +## Subtitle + +This panel does have a subtitle! + +{panel end} diff --git a/verto/tests/assets/panel/expanded_true.md b/verto/tests/assets/panel/expanded_true.md new file mode 100644 index 00000000..6f56d7e9 --- /dev/null +++ b/verto/tests/assets/panel/expanded_true.md @@ -0,0 +1,9 @@ +{panel type="extra-for-experts" subtitle="true" expanded="always"} + +# Lorem ipsum + +## Nunc non accumsan + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc non accumsan libero, et suscipit velit. Phasellus quis lorem eget lacus rutrum lobortis. Integer tincidunt convallis arcu a porttitor. Ut urna sapien, egestas mollis lectus a, suscipit placerat ante. Vestibulum id congue tellus. Nullam dapibus felis eu ligula mattis, vel consectetur nibh aliquet. Maecenas nec elit orci. Curabitur ut massa maximus, ultrices diam at, porttitor erat. Praesent eu purus vitae ligula elementum iaculis in non eros. Quisque eu aliquet dolor, ut pharetra lacus. + +{panel end} diff --git a/verto/tests/assets/panel/expanded_true_custom_argument_rules.json b/verto/tests/assets/panel/expanded_true_custom_argument_rules.json new file mode 100644 index 00000000..7c10d5a7 --- /dev/null +++ b/verto/tests/assets/panel/expanded_true_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "panel": { + "expanded": true + } +} diff --git a/verto/tests/assets/panel/expanded_true_expected.html b/verto/tests/assets/panel/expanded_true_expected.html new file mode 100644 index 00000000..77d01a3b --- /dev/null +++ b/verto/tests/assets/panel/expanded_true_expected.html @@ -0,0 +1,8 @@ +
    +
    +Lorem ipsum: Nunc non accumsan +
    +
    +

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc non accumsan libero, et suscipit velit. Phasellus quis lorem eget lacus rutrum lobortis. Integer tincidunt convallis arcu a porttitor. Ut urna sapien, egestas mollis lectus a, suscipit placerat ante. Vestibulum id congue tellus. Nullam dapibus felis eu ligula mattis, vel consectetur nibh aliquet. Maecenas nec elit orci. Curabitur ut massa maximus, ultrices diam at, porttitor erat. Praesent eu purus vitae ligula elementum iaculis in non eros. Quisque eu aliquet dolor, ut pharetra lacus.

    +
    +
    diff --git a/verto/tests/assets/panel/subtitle_true.md b/verto/tests/assets/panel/subtitle_true.md new file mode 100644 index 00000000..68119833 --- /dev/null +++ b/verto/tests/assets/panel/subtitle_true.md @@ -0,0 +1,9 @@ +{panel type="note" subtitle="true"} + +# Heading + +## Subtitle + +This panel does have a subtitle! + +{panel end} diff --git a/verto/tests/assets/panel/subtitle_true_custom_argument_rules.json b/verto/tests/assets/panel/subtitle_true_custom_argument_rules.json new file mode 100644 index 00000000..e82b0819 --- /dev/null +++ b/verto/tests/assets/panel/subtitle_true_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "panel": { + "subtitle": true + } +} diff --git a/verto/tests/assets/panel/subtitle_true_expected.html b/verto/tests/assets/panel/subtitle_true_expected.html new file mode 100644 index 00000000..92b98a7b --- /dev/null +++ b/verto/tests/assets/panel/subtitle_true_expected.html @@ -0,0 +1,8 @@ +
    +
    +Heading: Subtitle +
    +
    +

    This panel does have a subtitle!

    +
    +
    diff --git a/verto/tests/assets/panel/subtitle_true_not_provided.md b/verto/tests/assets/panel/subtitle_true_not_provided.md new file mode 100644 index 00000000..d0f5cf56 --- /dev/null +++ b/verto/tests/assets/panel/subtitle_true_not_provided.md @@ -0,0 +1,9 @@ +{panel type="extra-for-experts" expanded="always"} + +# Lorem ipsum + +## Nunc non accumsan + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc non accumsan libero, et suscipit velit. Phasellus quis lorem eget lacus rutrum lobortis. Integer tincidunt convallis arcu a porttitor. Ut urna sapien, egestas mollis lectus a, suscipit placerat ante. Vestibulum id congue tellus. Nullam dapibus felis eu ligula mattis, vel consectetur nibh aliquet. Maecenas nec elit orci. Curabitur ut massa maximus, ultrices diam at, porttitor erat. Praesent eu purus vitae ligula elementum iaculis in non eros. Quisque eu aliquet dolor, ut pharetra lacus. + +{panel end} diff --git a/verto/tests/assets/panel/type_false.md b/verto/tests/assets/panel/type_false.md new file mode 100644 index 00000000..be6c53b6 --- /dev/null +++ b/verto/tests/assets/panel/type_false.md @@ -0,0 +1,7 @@ +{panel type="note" subtitle="false"} + +# Heading + +This panel does not have a subtitle + +{panel end} diff --git a/verto/tests/assets/panel/type_false_custom_argument_rules.json b/verto/tests/assets/panel/type_false_custom_argument_rules.json new file mode 100644 index 00000000..0d02f63f --- /dev/null +++ b/verto/tests/assets/panel/type_false_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "panel": { + "type": false + } +} diff --git a/verto/tests/assets/panel/type_false_expected.html b/verto/tests/assets/panel/type_false_expected.html new file mode 100644 index 00000000..fa59321c --- /dev/null +++ b/verto/tests/assets/panel/type_false_expected.html @@ -0,0 +1,8 @@ +
    +
    +Heading +
    +
    +

    This panel does not have a subtitle

    +
    +
    diff --git a/verto/tests/assets/video/url_false.md b/verto/tests/assets/video/url_false.md new file mode 100644 index 00000000..521f459e --- /dev/null +++ b/verto/tests/assets/video/url_false.md @@ -0,0 +1,5 @@ +Engineering Disasters 13: Software Flaws + +{video} + +is an excerpt from Engineering Disaster Episode 13 explaining software flaws in Ariane 5 and Patriot Missiles diff --git a/verto/tests/assets/video/url_false_custom_argument_rules.json b/verto/tests/assets/video/url_false_custom_argument_rules.json new file mode 100644 index 00000000..0264314a --- /dev/null +++ b/verto/tests/assets/video/url_false_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "video": { + "url": false + } +} diff --git a/verto/tests/assets/video/url_false_expected.html b/verto/tests/assets/video/url_false_expected.html new file mode 100644 index 00000000..c88e3d7d --- /dev/null +++ b/verto/tests/assets/video/url_false_expected.html @@ -0,0 +1,3 @@ +

    Engineering Disasters 13: Software Flaws

    +

    {video}

    +

    is an excerpt from Engineering Disaster Episode 13 explaining software flaws in Ariane 5 and Patriot Missiles

    diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index cc78a259..5cfc39b3 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -85,31 +85,31 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - # unittest.makeSuite(BoxedTextTest), - # unittest.makeSuite(ButtonLinkTest), - # unittest.makeSuite(CommentTest), - # unittest.makeSuite(ConditionalTest), - # unittest.makeSuite(FrameTest), - # unittest.makeSuite(GlossaryLinkTest), - # unittest.makeSuite(HeadingTest), - # unittest.makeSuite(ImageInlineTest), - # unittest.makeSuite(ImageTagTest), - # unittest.makeSuite(ImageContainerTest), + unittest.makeSuite(BoxedTextTest), + unittest.makeSuite(ButtonLinkTest), + unittest.makeSuite(CommentTest), + unittest.makeSuite(ConditionalTest), + unittest.makeSuite(FrameTest), + unittest.makeSuite(GlossaryLinkTest), + unittest.makeSuite(HeadingTest), + unittest.makeSuite(ImageInlineTest), + unittest.makeSuite(ImageTagTest), + unittest.makeSuite(ImageContainerTest), unittest.makeSuite(InteractiveTest), - # unittest.makeSuite(JinjaTest), - # unittest.makeSuite(PanelTest), - # unittest.makeSuite(SaveTitleTest), - # unittest.makeSuite(ScratchTest), - # unittest.makeSuite(ScratchInlineTest), - # unittest.makeSuite(StyleTest), - # unittest.makeSuite(RelativeLinkTest), - # unittest.makeSuite(RemoveTest), - # unittest.makeSuite(RemoveTitleTest), - # unittest.makeSuite(TableOfContentsTest), - # unittest.makeSuite(VideoTest), - - # unittest.makeSuite(HtmlParserTest), - # unittest.makeSuite(MarkdownOverrideTest), + unittest.makeSuite(JinjaTest), + unittest.makeSuite(PanelTest), + unittest.makeSuite(SaveTitleTest), + unittest.makeSuite(ScratchTest), + unittest.makeSuite(ScratchInlineTest), + unittest.makeSuite(StyleTest), + unittest.makeSuite(RelativeLinkTest), + unittest.makeSuite(RemoveTest), + unittest.makeSuite(RemoveTitleTest), + unittest.makeSuite(TableOfContentsTest), + unittest.makeSuite(VideoTest), + + unittest.makeSuite(HtmlParserTest), + unittest.makeSuite(MarkdownOverrideTest), )) From 81f448dfe3d074b88f577074dcb46af7a75f7a63 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 30 Jul 2018 12:53:01 +1200 Subject: [PATCH 54/73] Added tests for video and iframe --- verto/tests/FrameTest.py | 28 +++++++++++++++---- verto/tests/VideoTest.py | 1 - verto/tests/assets/iframe/link_false.md | 1 + .../link_false_custom_argument_rules.json | 5 ++++ .../assets/iframe/link_false_expected.html | 3 ++ 5 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 verto/tests/assets/iframe/link_false.md create mode 100644 verto/tests/assets/iframe/link_false_custom_argument_rules.json create mode 100644 verto/tests/assets/iframe/link_false_expected.html diff --git a/verto/tests/FrameTest.py b/verto/tests/FrameTest.py index d0fbf56f..256337fe 100644 --- a/verto/tests/FrameTest.py +++ b/verto/tests/FrameTest.py @@ -1,5 +1,8 @@ import markdown from unittest.mock import Mock +from collections import OrderedDict +import json +import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.GenericTagBlockProcessor import GenericTagBlockProcessor @@ -7,15 +10,11 @@ from verto.errors.ArgumentDefinitionError import ArgumentDefinitionError from verto.tests.ProcessorTest import ProcessorTest + class FrameTest(ProcessorTest): '''The iframe processor inherits from the generic tag procesor. The tests contained here test that arguments and the output (html-template) work as expected. - - Note: - - No tests for custom argument rules because there is only - one argument and does not make sense to have a tag with no - arguments. ''' def __init__(self, *args, **kwargs): @@ -52,6 +51,25 @@ def test_example_single_quote_argument_error(self): with self.assertRaises(ArgumentDefinitionError): converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + def test_custom_argument_rules_link_false(self): + '''Tests to ensure that iframe tag is rendered correctly when link argument is not required. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/iframe/link_false_custom_argument_rules.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + verto_extension_custom_rules = VertoExtension( + processors=[self.processor_name], + custom_argument_rules=custom_argument_rules + ) + + test_string = self.read_test_file(self.processor_name, 'link_false.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension_custom_rules]) + expected_string = self.read_test_file(self.processor_name, 'link_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + #~ # Doc Tests #~ diff --git a/verto/tests/VideoTest.py b/verto/tests/VideoTest.py index 3e51d437..955d1867 100644 --- a/verto/tests/VideoTest.py +++ b/verto/tests/VideoTest.py @@ -6,7 +6,6 @@ from verto.VertoExtension import VertoExtension from verto.processors.VideoBlockProcessor import VideoBlockProcessor -from verto.errors.ArgumentMissingError import ArgumentMissingError from verto.errors.NoVideoIdentifierError import NoVideoIdentifierError from verto.errors.UnsupportedVideoPlayerError import UnsupportedVideoPlayerError from verto.tests.ProcessorTest import ProcessorTest diff --git a/verto/tests/assets/iframe/link_false.md b/verto/tests/assets/iframe/link_false.md new file mode 100644 index 00000000..3eec868f --- /dev/null +++ b/verto/tests/assets/iframe/link_false.md @@ -0,0 +1 @@ +{iframe} diff --git a/verto/tests/assets/iframe/link_false_custom_argument_rules.json b/verto/tests/assets/iframe/link_false_custom_argument_rules.json new file mode 100644 index 00000000..16ffdd75 --- /dev/null +++ b/verto/tests/assets/iframe/link_false_custom_argument_rules.json @@ -0,0 +1,5 @@ +{ + "iframe": { + "link": false + } +} diff --git a/verto/tests/assets/iframe/link_false_expected.html b/verto/tests/assets/iframe/link_false_expected.html new file mode 100644 index 00000000..69f84f7e --- /dev/null +++ b/verto/tests/assets/iframe/link_false_expected.html @@ -0,0 +1,3 @@ + From 6ec4eaf4291472c28ea93be42a6649ffc5df66b8 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Wed, 1 Aug 2018 20:49:30 +1200 Subject: [PATCH 55/73] Adding configuration tests for custom rules for multiple tags --- verto/Verto.py | 9 +-- verto/VertoExtension.py | 10 +-- verto/processors/utils.py | 14 ++-- verto/tests/ConfigurationTest.py | 47 ++++++++++++++ verto/tests/ImageInlineTest.py | 17 +++++ verto/tests/PanelTest.py | 1 - .../custom_argument_rules_image_panel.json | 8 +++ ...stom_argument_rules_multiple_tags_error.md | 64 +++++++++++++++++++ 8 files changed, 150 insertions(+), 20 deletions(-) create mode 100644 verto/tests/assets/configuration/custom_argument_rules_image_panel.json create mode 100644 verto/tests/assets/configuration/custom_argument_rules_multiple_tags_error.md diff --git a/verto/Verto.py b/verto/Verto.py index 5ca5d87a..de360237 100644 --- a/verto/Verto.py +++ b/verto/Verto.py @@ -47,14 +47,7 @@ def __init__(self, processors=DEFAULT_PROCESSORS, html_templates={}, extensions= self.processors = set(processors) self.html_templates = dict(html_templates) self.extensions = list(extensions) - ### WIP - # Overwrite processor-info file with any rules given here - self.custom_argument_rules = { - 'image-container': { - 'alt': False - } - } - ### + self.custom_argument_rules = custom_argument_rules self.create_converter() def create_converter(self): diff --git a/verto/VertoExtension.py b/verto/VertoExtension.py index b24a2eeb..5006f6e9 100644 --- a/verto/VertoExtension.py +++ b/verto/VertoExtension.py @@ -145,9 +145,9 @@ def loadJinjaTemplates(self, custom_templates): ''' templates = {} env = Environment( - loader=PackageLoader('verto', 'html-templates'), - autoescape=select_autoescape(['html']) - ) + loader=PackageLoader('verto', 'html-templates'), + autoescape=select_autoescape(['html']) + ) for file in listdir(os.path.join(os.path.dirname(__file__), 'html-templates')): html_file = re.search(r'(.*?).html$', file) if html_file: @@ -245,8 +245,10 @@ def _set_heading_tree(self, tree): assert all(isinstance(child, HeadingNode) for child in tree) self.heading_tree = tree - # refactor to modify_required_arguments def modify_rules(self, json_data): # TODO what if gives argument that does not exist + ''' + # refactor to modify_required_arguments + ''' for processor, arguments_to_modify in self.custom_argument_rules.items(): for argument in arguments_to_modify.items(): new_required = argument[1] # .lower() diff --git a/verto/processors/utils.py b/verto/processors/utils.py index bb582d38..347c0341 100644 --- a/verto/processors/utils.py +++ b/verto/processors/utils.py @@ -34,15 +34,15 @@ def parse_argument(argument_key, arguments, default=None): def parse_flag(argument_key, arguments, default=False): - '''search for the given argument in a string of all arguments, + '''Search for the given argument in a string of all arguments, treating the argument as a flag only. - args: - argument_key: the name of the argument. - arguments: a string of the argument inputs. - default: the default value if not found. - returns: - true if argument is found, otherwise none. + Args: + argument_key: The name of the argument. + arguments: A string of the argument inputs. + default: The default value if not found. + Returns: + True if argument is found, otherwise None. ''' result = re.search(r'(^|\s+){}(.+?".*?")'.format(argument_key), arguments) if result: diff --git a/verto/tests/ConfigurationTest.py b/verto/tests/ConfigurationTest.py index 1c452a41..85a212ac 100644 --- a/verto/tests/ConfigurationTest.py +++ b/verto/tests/ConfigurationTest.py @@ -1,7 +1,14 @@ +import markdown +from collections import OrderedDict +import json +import pkg_resources + from verto.Verto import Verto, VertoResult +from verto.VertoExtension import VertoExtension from verto.processors.ScratchTreeprocessor import ScratchImageMetaData from verto.utils.HeadingNode import HeadingNode from verto.tests.BaseTest import BaseTest +from verto.errors.ArgumentMissingError import ArgumentMissingError class ConfigurationTest(BaseTest): @@ -360,3 +367,43 @@ def test_multiline_custom_templates(self): converted_test_string = verto.convert(test_string).html_string expected_string = self.read_test_file(self.test_name, 'multiline_templates_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) + + def test_custom_arguments_rules_on_creation(self): + '''Checks if tag arguments are updated. + ''' + custom_argument_rules = { + "image-tag": { + "alt": False + } + } + verto = Verto(custom_argument_rules=custom_argument_rules) + self.assertEqual(verto.verto_extension.custom_argument_rules, dict(custom_argument_rules)) + + def test_custom_argument_rules_for_multiple_tags(self): + '''Checks that md file is correctly parsed when multiple tags have custom argument rules. + ''' + custom_argument_rules = { + "image-tag": { + "alt": False + }, + "panel": { + "subtitle": True + } + } + verto = Verto(custom_argument_rules=custom_argument_rules) + self.assertEqual(verto.verto_extension.custom_argument_rules, dict(custom_argument_rules)) + test_string = self.read_test_file(self.test_name, 'all_processors.md') + converted_test_string = verto.convert(test_string).html_string + expected_string = self.read_test_file(self.test_name, 'all_processors_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + def test_custom_argument_rules_for_multiple_tags_error(self): + '''Checks that error is raised when a tag's custom argument rules are not followed. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/configuration/custom_argument_rules_image_panel.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + processors = {'image-tag', 'panel', 'comment'} + verto = VertoExtension(processors=processors, custom_argument_rules=custom_argument_rules) + + test_string = self.read_test_file(self.test_name, 'custom_argument_rules_multiple_tags_error.md') + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto]), test_string) diff --git a/verto/tests/ImageInlineTest.py b/verto/tests/ImageInlineTest.py index 5a6fa4ca..83306c2c 100644 --- a/verto/tests/ImageInlineTest.py +++ b/verto/tests/ImageInlineTest.py @@ -200,13 +200,17 @@ def test_image_width_value(self): '''Test image rendered correctly with width value. ''' test_string = self.read_test_file(self.processor_name, 'file_width_value.md') + processor = ImageInlinePattern(self.ext, self.md.parser) self.assertIsNotNone(re.search(processor.compiled_re, test_string)) + html_template = self.read_test_file(self.processor_name, 'file_width_value_html_template.html', strip=True) verto_extension = VertoExtension([self.processor_name], html_templates={self.processor_name: html_template}) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) expected_string = self.read_test_file(self.processor_name, 'file_width_value_expected.html', strip=True).strip() self.assertEqual(expected_string, converted_test_string) + images = verto_extension.required_files['images'] expected_images = {'path/to/image@500px.png'} self.assertSetEqual(expected_images, images) @@ -215,13 +219,17 @@ def test_image_width_value_no_units(self): '''Test image rendered correctly with width value with no units. ''' test_string = self.read_test_file(self.processor_name, 'file_width_value_no_units.md') + processor = ImageInlinePattern(self.ext, self.md.parser) self.assertIsNotNone(re.search(processor.compiled_re, test_string)) + html_template = self.read_test_file(self.processor_name, 'file_width_value_no_units_html_template.html', strip=True) verto_extension = VertoExtension([self.processor_name], html_templates={self.processor_name: html_template}) + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) expected_string = self.read_test_file(self.processor_name, 'file_width_value_no_units_expected.html', strip=True).strip() self.assertEqual(expected_string, converted_test_string) + images = verto_extension.required_files['images'] expected_images = {'path/to/image@900.png'} self.assertSetEqual(expected_images, images) @@ -230,11 +238,14 @@ def test_image_invalid_width_value_1(self): '''Test image rendered correctly with width value. ''' test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1.md') + processor = ImageInlinePattern(self.ext, self.md.parser) self.assertIsNotNone(re.search(processor.compiled_re, test_string)) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_1_expected.html', strip=True).strip() self.assertEqual(expected_string, converted_test_string) + images = self.verto_extension.required_files['images'] expected_images = {'path/to/image@.png'} self.assertSetEqual(expected_images, images) @@ -243,11 +254,14 @@ def test_image_invalid_width_value_2(self): '''Test image rendered correctly with width value. ''' test_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2.md') + processor = ImageInlinePattern(self.ext, self.md.parser) self.assertIsNotNone(re.search(processor.compiled_re, test_string)) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'file_invalid_width_value_2_expected.html', strip=True).strip() self.assertEqual(expected_string, converted_test_string) + images = self.verto_extension.required_files['images'] expected_images = {'path/to/image@em20.png'} self.assertSetEqual(expected_images, images) @@ -256,11 +270,14 @@ def test_image_width_value_external_image(self): '''Test image rendered correctly with width value. ''' test_string = self.read_test_file(self.processor_name, 'file_width_value_external_image.md') + processor = ImageInlinePattern(self.ext, self.md.parser) self.assertIsNotNone(re.search(processor.compiled_re, test_string)) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'file_width_value_external_image_expected.html', strip=True).strip() self.assertEqual(expected_string, converted_test_string) + images = self.verto_extension.required_files['images'] expected_images = set() self.assertSetEqual(expected_images, images) diff --git a/verto/tests/PanelTest.py b/verto/tests/PanelTest.py index 03fba06c..74126bda 100644 --- a/verto/tests/PanelTest.py +++ b/verto/tests/PanelTest.py @@ -371,7 +371,6 @@ def test_panel_block_missing_whitespace(self): self.assertRaises(StyleError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) -# type subtitle expanded def test_custom_arguments_type_false(self): '''Tests to ensure that panel tag is rendered correctly when type argument is not required. ''' diff --git a/verto/tests/assets/configuration/custom_argument_rules_image_panel.json b/verto/tests/assets/configuration/custom_argument_rules_image_panel.json new file mode 100644 index 00000000..ed177f2f --- /dev/null +++ b/verto/tests/assets/configuration/custom_argument_rules_image_panel.json @@ -0,0 +1,8 @@ +{ + "panel": { + "subtitle": true + }, + "image-tag": { + "alt": false + } +} diff --git a/verto/tests/assets/configuration/custom_argument_rules_multiple_tags_error.md b/verto/tests/assets/configuration/custom_argument_rules_multiple_tags_error.md new file mode 100644 index 00000000..b8d4d162 --- /dev/null +++ b/verto/tests/assets/configuration/custom_argument_rules_multiple_tags_error.md @@ -0,0 +1,64 @@ +# Example Title + +This is a sentence. + +# Example Title 2 + +{comment This is a comment for other authors to read} + +Check out this [resource](resource/134). + +{image file-path="http://placehold.it/350x150" caption="true" source="https://placehold.it/" hover-text="This is hover text" alignment="left"} + +{panel type="teacher-note"} + +# Teacher Note + +This text is the panel's contents. + +{panel end} + +Dancing with our hands tied. + +{image end} + +{image file-path="http://placehold.it/250x50" caption="false" source="https://placehold.it/" hover-text="This is hover text" alignment="left" alt="This is alt text"} + +{boxed-text} + +**Computer Science Report for 2.44** + +Put your introduction to what bits are here. + +{boxed-text end} + +{button-link link="http://www.google.com" text="Visit Google"} + +{conditional if condition="version == 'teacher'"} + +This is text that only teachers should see. + +{conditional end} + +It's worth considering which {glossary-link term="algorithm"}algorithms{glossary-link end} should be used. + +{iframe link="https://github.com/"} + +{interactive slug="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"} + + scratch + when flag clicked + clear + forever + pen down + if < and > then + switch costume to [button v] + else + add (x position) to [list v] + end + move (foo) steps + turn ccw (9) degrees + +{table-of-contents} + +{video url="https://www.youtube.com/watch?v=dQw4w9WgXcQ"} From 9b3a279c7b0ac27ac6efc5b6352a6671271ea43d Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Thu, 2 Aug 2018 17:31:25 +1200 Subject: [PATCH 56/73] Added tests to catch errors in custom argument rules file Also updated docs --- docs/source/usage.rst | 13 ++++++++++ verto/VertoExtension.py | 25 +++++++++++++++---- verto/errors/CustomArgumentRulesError.py | 17 +++++++++++++ verto/tests/ConfigurationTest.py | 19 ++++++++++++++ ...om_argument_rules_incorrect_processor.json | 8 ++++++ ...nt_rules_incorrect_processor_argument.json | 8 ++++++ 6 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 verto/errors/CustomArgumentRulesError.py create mode 100644 verto/tests/assets/configuration/custom_argument_rules_incorrect_processor.json create mode 100644 verto/tests/assets/configuration/custom_argument_rules_incorrect_processor_argument.json diff --git a/docs/source/usage.rst b/docs/source/usage.rst index d69f5d6f..6716053f 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -51,6 +51,19 @@ Once the module is imported, you can create a Verto converter creating an Verto - ``extensions`` - A list of extra Markdown extensions to run in the converter. Details on how to use this parameter can be found on the :doc:`extensions` page. +- ``custom_argument_rules`` - A json file to modify the default argument rules for each tag. The default rules can found by reading the documentation for each tag. + + - *For example:* By default, the ``image-inline`` tag requires alt text to be given, to change this, the following custom argument rules file would be used: + + .. code-block:: python + + { + "image-inline": { + "alt": false + } + } + + Step 3: Convert Markdown with converter ======================================= diff --git a/verto/VertoExtension.py b/verto/VertoExtension.py index 5006f6e9..ac016c25 100644 --- a/verto/VertoExtension.py +++ b/verto/VertoExtension.py @@ -30,6 +30,8 @@ from verto.utils.overrides import OListProcessor from verto.utils.overrides import UListProcessor +from verto.errors.CustomArgumentRulesError import CustomArgumentRulesError + from collections import defaultdict, OrderedDict from os import listdir import os.path @@ -61,9 +63,9 @@ def __init__(self, processors=[], html_templates={}, extensions=[], custom_argum ''' super().__init__(*args, **kwargs) self.jinja_templates = self.loadJinjaTemplates(html_templates) + self.processors = processors self.custom_argument_rules = custom_argument_rules self.processor_info = self.loadProcessorInfo() - self.processors = processors self.title = None self.heading_tree = None self.custom_slugify = UniqueSlugify() @@ -245,12 +247,25 @@ def _set_heading_tree(self, tree): assert all(isinstance(child, HeadingNode) for child in tree) self.heading_tree = tree - def modify_rules(self, json_data): # TODO what if gives argument that does not exist + def modify_rules(self, json_data): ''' - # refactor to modify_required_arguments + Modify the default tag argument rules using given custom rules. + + Args: + json_data: dictionary of rules for processors parsing tags + Return: + json_data: dictionary of rules for processors parsing tags, + with modified rules arcording to custom rules given. ''' for processor, arguments_to_modify in self.custom_argument_rules.items(): + if processor not in self.processors: + msg = '\'{}\' is not a valid processor.'.format(processor) + raise CustomArgumentRulesError(processor, msg) for argument in arguments_to_modify.items(): - new_required = argument[1] # .lower() - json_data[processor]['arguments'][argument[0]]['required'] = new_required + new_required = argument[1] + try: + json_data[processor]['arguments'][argument[0]]['required'] = new_required + except: + msg = '\'{}\' is not a valid argument for the \'{}\' processor.'.format(argument[0], processor) + raise CustomArgumentRulesError(argument[0], msg) return json_data diff --git a/verto/errors/CustomArgumentRulesError.py b/verto/errors/CustomArgumentRulesError.py new file mode 100644 index 00000000..70b46654 --- /dev/null +++ b/verto/errors/CustomArgumentRulesError.py @@ -0,0 +1,17 @@ +from verto.errors.Error import Error + + +class CustomArgumentRulesError(Error): + '''Exception raised when custom argument rules refer to a processors + that does not exist. + + Attributes: + tag: tag which was not matched + argument: the argument that was not found + value: the value that was not matched + message: explanation of why error was thrown + ''' + + def __init__(self, argument, message): + super().__init__(message) + self.argument = argument diff --git a/verto/tests/ConfigurationTest.py b/verto/tests/ConfigurationTest.py index 85a212ac..d3213f8e 100644 --- a/verto/tests/ConfigurationTest.py +++ b/verto/tests/ConfigurationTest.py @@ -9,6 +9,7 @@ from verto.utils.HeadingNode import HeadingNode from verto.tests.BaseTest import BaseTest from verto.errors.ArgumentMissingError import ArgumentMissingError +from verto.errors.CustomArgumentRulesError import CustomArgumentRulesError class ConfigurationTest(BaseTest): @@ -407,3 +408,21 @@ def test_custom_argument_rules_for_multiple_tags_error(self): test_string = self.read_test_file(self.test_name, 'custom_argument_rules_multiple_tags_error.md') self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto]), test_string) + + def test_custom_argument_rules_incorrect_processor_error(self): + '''Checks that error is raised when a processor given in custom argument rules does not exist. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/configuration/custom_argument_rules_incorrect_processor.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + processors = {'image-tag', 'panel', 'comment'} + + self.assertRaises(CustomArgumentRulesError, lambda: VertoExtension(processors=processors, custom_argument_rules=custom_argument_rules)) + + def test_custom_argument_rules_incorrect_processor_argument_error(self): + '''Checks that error is raised when a processor given in custom argument rules does not exist. + ''' + json_data = pkg_resources.resource_string('verto', 'tests/assets/configuration/custom_argument_rules_incorrect_processor_argument.json').decode('utf-8') + custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + processors = {'image-tag', 'panel', 'comment'} + + self.assertRaises(CustomArgumentRulesError, lambda: VertoExtension(processors=processors, custom_argument_rules=custom_argument_rules)) diff --git a/verto/tests/assets/configuration/custom_argument_rules_incorrect_processor.json b/verto/tests/assets/configuration/custom_argument_rules_incorrect_processor.json new file mode 100644 index 00000000..25f8ebc1 --- /dev/null +++ b/verto/tests/assets/configuration/custom_argument_rules_incorrect_processor.json @@ -0,0 +1,8 @@ +{ + "panl": { + "subtitle": true + }, + "image-tag": { + "alt": false + } +} diff --git a/verto/tests/assets/configuration/custom_argument_rules_incorrect_processor_argument.json b/verto/tests/assets/configuration/custom_argument_rules_incorrect_processor_argument.json new file mode 100644 index 00000000..23ded3bb --- /dev/null +++ b/verto/tests/assets/configuration/custom_argument_rules_incorrect_processor_argument.json @@ -0,0 +1,8 @@ +{ + "panel": { + "totallyrealargument": true + }, + "image-tag": { + "alt": false + } +} From 84b5d0a5114e089d7a94eedba4d5d9bb99507019 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Thu, 2 Aug 2018 17:40:06 +1200 Subject: [PATCH 57/73] fixed style error --- verto/VertoExtension.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/verto/VertoExtension.py b/verto/VertoExtension.py index ac016c25..c3c31407 100644 --- a/verto/VertoExtension.py +++ b/verto/VertoExtension.py @@ -265,7 +265,7 @@ def modify_rules(self, json_data): new_required = argument[1] try: json_data[processor]['arguments'][argument[0]]['required'] = new_required - except: + except KeyError: msg = '\'{}\' is not a valid argument for the \'{}\' processor.'.format(argument[0], processor) raise CustomArgumentRulesError(argument[0], msg) return json_data From e53220f16fdffb1397dfda05addf22979255db71 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Fri, 3 Aug 2018 13:04:15 +1200 Subject: [PATCH 58/73] WIP Refacotring existing interactive processor and adding a new one --- verto/Verto.py | 3 +- verto/VertoExtension.py | 12 +- verto/processor-info.json | 52 ++- .../GenericContainerBlockProcessor.py | 1 + .../InteractiveContainerBlockProcessor.py | 87 +++++ ...sor.py => InteractiveTagBlockProcessor.py} | 4 +- verto/tests/ImageTagTest.py | 4 +- verto/tests/InteractiveContainerTest.py | 329 ++++++++++++++++++ ...teractiveTest.py => InteractiveTagTest.py} | 34 +- .../doc_example_iframe_usage.md | 0 .../doc_example_iframe_usage_expected.html | 0 .../doc_example_in_page_usage.md | 0 .../doc_example_in_page_usage_expected.html | 0 .../doc_example_override_html.md | 0 .../doc_example_override_html_expected.html | 0 .../doc_example_override_html_template.html | 0 .../doc_example_override_thumbnail_html.md | 0 ...mple_override_thumbnail_html_expected.html | 0 ..._example_thumbnail_path_html_template.html | 0 .../doc_example_whole_page_usage.md | 0 ...doc_example_whole_page_usage_expected.html | 0 .../iframe_parameters.md | 0 .../iframe_parameters_expected.html | 0 .../in_page_missing_name.md | 0 .../in_page_missing_name_expected.html | 0 .../invalid_type.md | 0 .../missing_type.md | 0 .../multiple_interactives.md | 0 .../multiple_interactives_expected.html | 0 .../whole_page_external_thumbnail.md | 5 + ...hole_page_external_thumbnail_expected.html | 0 .../whole_page_parameters.md | 0 .../whole_page_parameters_expected.html | 0 .../whole_page_text.md | 0 .../whole_page_text_expected.html | 0 .../whole_page_thumbnail.md | 0 .../whole_page_thumbnail_expected.html | 0 .../whole_page_thumbnail_parameters.md | 0 ...le_page_thumbnail_parameters_expected.html | 0 .../doc_example_iframe_usage.md | 1 + .../doc_example_iframe_usage_expected.html | 3 + .../doc_example_in_page_usage.md | 1 + .../doc_example_in_page_usage_expected.html | 1 + .../doc_example_override_html.md | 1 + .../doc_example_override_html_expected.html | 5 + .../doc_example_override_html_template.html | 21 ++ .../doc_example_override_thumbnail_html.md | 1 + ...mple_override_thumbnail_html_expected.html | 6 + ..._example_thumbnail_path_html_template.html | 3 + .../doc_example_whole_page_usage.md | 1 + ...doc_example_whole_page_usage_expected.html | 6 + .../interactive-tag/iframe_parameters.md | 1 + .../iframe_parameters_expected.html | 3 + .../interactive-tag/in_page_missing_name.md | 1 + .../in_page_missing_name_expected.html | 1 + .../assets/interactive-tag/invalid_type.md | 1 + .../assets/interactive-tag/missing_type.md | 1 + .../interactive-tag/multiple_interactives.md | 13 + .../multiple_interactives_expected.html | 13 + .../whole_page_external_thumbnail.md | 0 ...hole_page_external_thumbnail_expected.html | 6 + .../interactive-tag/whole_page_parameters.md | 1 + .../whole_page_parameters_expected.html | 6 + .../assets/interactive-tag/whole_page_text.md | 1 + .../whole_page_text_expected.html | 6 + .../interactive-tag/whole_page_thumbnail.md | 1 + .../whole_page_thumbnail_expected.html | 6 + .../whole_page_thumbnail_parameters.md | 1 + ...le_page_thumbnail_parameters_expected.html | 6 + verto/tests/start_tests.py | 54 +-- 70 files changed, 648 insertions(+), 55 deletions(-) create mode 100644 verto/processors/InteractiveContainerBlockProcessor.py rename verto/processors/{InteractiveBlockProcessor.py => InteractiveTagBlockProcessor.py} (95%) create mode 100644 verto/tests/InteractiveContainerTest.py rename verto/tests/{InteractiveTest.py => InteractiveTagTest.py} (83%) rename verto/tests/assets/{interactive => interactive-container}/doc_example_iframe_usage.md (100%) rename verto/tests/assets/{interactive => interactive-container}/doc_example_iframe_usage_expected.html (100%) rename verto/tests/assets/{interactive => interactive-container}/doc_example_in_page_usage.md (100%) rename verto/tests/assets/{interactive => interactive-container}/doc_example_in_page_usage_expected.html (100%) rename verto/tests/assets/{interactive => interactive-container}/doc_example_override_html.md (100%) rename verto/tests/assets/{interactive => interactive-container}/doc_example_override_html_expected.html (100%) rename verto/tests/assets/{interactive => interactive-container}/doc_example_override_html_template.html (100%) rename verto/tests/assets/{interactive => interactive-container}/doc_example_override_thumbnail_html.md (100%) rename verto/tests/assets/{interactive => interactive-container}/doc_example_override_thumbnail_html_expected.html (100%) rename verto/tests/assets/{interactive => interactive-container}/doc_example_thumbnail_path_html_template.html (100%) rename verto/tests/assets/{interactive => interactive-container}/doc_example_whole_page_usage.md (100%) rename verto/tests/assets/{interactive => interactive-container}/doc_example_whole_page_usage_expected.html (100%) rename verto/tests/assets/{interactive => interactive-container}/iframe_parameters.md (100%) rename verto/tests/assets/{interactive => interactive-container}/iframe_parameters_expected.html (100%) rename verto/tests/assets/{interactive => interactive-container}/in_page_missing_name.md (100%) rename verto/tests/assets/{interactive => interactive-container}/in_page_missing_name_expected.html (100%) rename verto/tests/assets/{interactive => interactive-container}/invalid_type.md (100%) rename verto/tests/assets/{interactive => interactive-container}/missing_type.md (100%) rename verto/tests/assets/{interactive => interactive-container}/multiple_interactives.md (100%) rename verto/tests/assets/{interactive => interactive-container}/multiple_interactives_expected.html (100%) create mode 100644 verto/tests/assets/interactive-container/whole_page_external_thumbnail.md rename verto/tests/assets/{interactive => interactive-container}/whole_page_external_thumbnail_expected.html (100%) rename verto/tests/assets/{interactive => interactive-container}/whole_page_parameters.md (100%) rename verto/tests/assets/{interactive => interactive-container}/whole_page_parameters_expected.html (100%) rename verto/tests/assets/{interactive => interactive-container}/whole_page_text.md (100%) rename verto/tests/assets/{interactive => interactive-container}/whole_page_text_expected.html (100%) rename verto/tests/assets/{interactive => interactive-container}/whole_page_thumbnail.md (100%) rename verto/tests/assets/{interactive => interactive-container}/whole_page_thumbnail_expected.html (100%) rename verto/tests/assets/{interactive => interactive-container}/whole_page_thumbnail_parameters.md (100%) rename verto/tests/assets/{interactive => interactive-container}/whole_page_thumbnail_parameters_expected.html (100%) create mode 100644 verto/tests/assets/interactive-tag/doc_example_iframe_usage.md create mode 100644 verto/tests/assets/interactive-tag/doc_example_iframe_usage_expected.html create mode 100644 verto/tests/assets/interactive-tag/doc_example_in_page_usage.md create mode 100644 verto/tests/assets/interactive-tag/doc_example_in_page_usage_expected.html create mode 100644 verto/tests/assets/interactive-tag/doc_example_override_html.md create mode 100644 verto/tests/assets/interactive-tag/doc_example_override_html_expected.html create mode 100644 verto/tests/assets/interactive-tag/doc_example_override_html_template.html create mode 100644 verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html.md create mode 100644 verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html_expected.html create mode 100644 verto/tests/assets/interactive-tag/doc_example_thumbnail_path_html_template.html create mode 100644 verto/tests/assets/interactive-tag/doc_example_whole_page_usage.md create mode 100644 verto/tests/assets/interactive-tag/doc_example_whole_page_usage_expected.html create mode 100644 verto/tests/assets/interactive-tag/iframe_parameters.md create mode 100644 verto/tests/assets/interactive-tag/iframe_parameters_expected.html create mode 100644 verto/tests/assets/interactive-tag/in_page_missing_name.md create mode 100644 verto/tests/assets/interactive-tag/in_page_missing_name_expected.html create mode 100644 verto/tests/assets/interactive-tag/invalid_type.md create mode 100644 verto/tests/assets/interactive-tag/missing_type.md create mode 100644 verto/tests/assets/interactive-tag/multiple_interactives.md create mode 100644 verto/tests/assets/interactive-tag/multiple_interactives_expected.html rename verto/tests/assets/{interactive => interactive-tag}/whole_page_external_thumbnail.md (100%) create mode 100644 verto/tests/assets/interactive-tag/whole_page_external_thumbnail_expected.html create mode 100644 verto/tests/assets/interactive-tag/whole_page_parameters.md create mode 100644 verto/tests/assets/interactive-tag/whole_page_parameters_expected.html create mode 100644 verto/tests/assets/interactive-tag/whole_page_text.md create mode 100644 verto/tests/assets/interactive-tag/whole_page_text_expected.html create mode 100644 verto/tests/assets/interactive-tag/whole_page_thumbnail.md create mode 100644 verto/tests/assets/interactive-tag/whole_page_thumbnail_expected.html create mode 100644 verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters.md create mode 100644 verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters_expected.html diff --git a/verto/Verto.py b/verto/Verto.py index 1f572dec..157a794f 100644 --- a/verto/Verto.py +++ b/verto/Verto.py @@ -13,7 +13,8 @@ 'image-container', 'image-tag', 'image-inline', - 'interactive', + 'interactive-tag', + 'interactive-container', 'panel', 'relative-link', 'save-title', diff --git a/verto/VertoExtension.py b/verto/VertoExtension.py index 9241d422..22aa6f46 100644 --- a/verto/VertoExtension.py +++ b/verto/VertoExtension.py @@ -6,7 +6,8 @@ from verto.processors.ImageInlinePattern import ImageInlinePattern from verto.processors.ImageTagBlockProcessor import ImageTagBlockProcessor from verto.processors.ImageContainerBlockProcessor import ImageContainerBlockProcessor -from verto.processors.InteractiveBlockProcessor import InteractiveBlockProcessor +from verto.processors.InteractiveTagBlockProcessor import InteractiveTagBlockProcessor +from verto.processors.InteractiveContainerBlockProcessor import InteractiveContainerBlockProcessor from verto.processors.RelativeLinkPattern import RelativeLinkPattern from verto.processors.RemoveTitlePreprocessor import RemoveTitlePreprocessor from verto.processors.SaveTitlePreprocessor import SaveTitlePreprocessor @@ -144,9 +145,9 @@ def loadJinjaTemplates(self, custom_templates): ''' templates = {} env = Environment( - loader=PackageLoader('verto', 'html-templates'), - autoescape=select_autoescape(['html']) - ) + loader=PackageLoader('verto', 'html-templates'), + autoescape=select_autoescape(['html']) + ) for file in listdir(os.path.join(os.path.dirname(__file__), 'html-templates')): html_file = re.search(r'(.*?).html$', file) if html_file: @@ -174,7 +175,8 @@ def buildProcessors(self, md, md_globals): # Markdown overrides ['heading', HeadingBlockProcessor(self, md.parser), '[^\\}]*)?(?Ptext=\"true\")(?P[^\\}]*)?\\} *(\\n|$)", + "tag_argument": "interactive", + "template_name": "interactive", + "arguments": { + "slug": { + "required": true, + "dependencies": [] + }, + "type": { + "required": true, + "dependencies": [], + "values": ["in-page", "whole-page", "iframe"] + }, + "text": { + "required": true, + "dependencies": [], + "values": ["true", "false"] }, "parameters": { "required": false, diff --git a/verto/processors/GenericContainerBlockProcessor.py b/verto/processors/GenericContainerBlockProcessor.py index 25247898..95ab1834 100644 --- a/verto/processors/GenericContainerBlockProcessor.py +++ b/verto/processors/GenericContainerBlockProcessor.py @@ -69,6 +69,7 @@ def run(self, parent, blocks): blocks.insert(0, after) argument_values = parse_arguments(self.processor, start_tag.group('args'), self.arguments) + print(argument_values) content_blocks = [] the_rest = '' diff --git a/verto/processors/InteractiveContainerBlockProcessor.py b/verto/processors/InteractiveContainerBlockProcessor.py new file mode 100644 index 00000000..ef634f91 --- /dev/null +++ b/verto/processors/InteractiveContainerBlockProcessor.py @@ -0,0 +1,87 @@ +from verto.processors.GenericContainerBlockProcessor import GenericContainerBlockProcessor +# TODO implement the following errors +# from verto.errors.InteractiveTextContainsInteractiveError import InteractiveTextContainsInteractiveError +# from verto.errors.InteractiveMissingTextError import InteractiveMissingTextError + +import re + + +class InteractiveContainerBlockProcessor(GenericContainerBlockProcessor): + ''' Searches a Document for interactive tags e.g. + {interactive slug='example' type='in-page'}. + These are then replaced with the html template. + ''' + + def __init__(self, ext, *args, **kwargs): + ''' + Args: + ext: The parent node of the element tree that children will + reside in. + ''' + self.processor = 'interactive-container' + super().__init__(self.processor, ext, *args, **kwargs) + self.pattern = re.compile(ext.processor_info[self.processor]['pattern']) + + self.scripts = ext.required_files['page_scripts'] + self.required_interactives = ext.required_files['interactives'] + self.required_images = ext.required_files['images'] + + def test(self, parent, block): + ''' Tests a block to see if the run method should be applied. + + Args: + parent: The parent node of the element tree that children + will reside in. + block: The block to be tested. + + Returns: + True if there are any start or end tags within the block. + ''' + return self.pattern.search(block) is not None or self.p_end.search(block) is not None + + def custom_parsing(self, content_blocks, argument_values): + ''' + Extracts the text of an interactive block. + + Args: + content_blocks (list): List of strings to either be parsed or inserted as caption in template. + argument_values (dict): Dictionary of arguments and values provided in tag block. + Returns: + Tuple containing blocks (list) and extra_args (dict) to update the content_blocks list and + agument_values dict. + Raises: + + ''' + for block in content_blocks: + if self.p_start.search(block): + raise InteractiveTextContainsInteractiveError(self.processor) + + extra_args = {} + interactive_type = argument_values['type'] + slug = argument_values['slug'] + + # add to list of interactives + self.required_interactives.add(slug) + + if interactive_type == 'in-page': + self.scripts.add('interactive/{}/scripts.html'.format(slug)) + elif interactive_type == 'whole-page': + argument = 'thumbnail' + thumbnail_file_path = argument_values.get(argument, None) + + if thumbnail_file_path is not None: + del argument_values[argument] + else: + thumbnail_file_path = 'interactives/{}/img/thumbnail.png'.format(slug) + + external_path_match = re.search(r'^http', thumbnail_file_path) + if external_path_match is None: # internal image + thumbnail_file_relative = True + self.required_images.add(thumbnail_file_path) + else: + thumbnail_file_relative = False + + extra_args['thumbnail_file_path'] = thumbnail_file_path + extra_args['thumbnail_file_relative'] = thumbnail_file_relative + + return (content_blocks, extra_args) diff --git a/verto/processors/InteractiveBlockProcessor.py b/verto/processors/InteractiveTagBlockProcessor.py similarity index 95% rename from verto/processors/InteractiveBlockProcessor.py rename to verto/processors/InteractiveTagBlockProcessor.py index 793b4783..7cb0afb0 100644 --- a/verto/processors/InteractiveBlockProcessor.py +++ b/verto/processors/InteractiveTagBlockProcessor.py @@ -2,7 +2,7 @@ import re -class InteractiveBlockProcessor(GenericTagBlockProcessor): +class InteractiveTagBlockProcessor(GenericTagBlockProcessor): '''Searches a Document for interactive tags: e.g. {interactive slug='example' type='in-page'} These are then replaced with the html template. @@ -13,7 +13,7 @@ def __init__(self, ext, *args, **kwargs): Args: ext: An instance of the Verto Extension. ''' - self.processor = 'interactive' + self.processor = 'interactive-tag' super().__init__(self.processor, ext, *args, **kwargs) self.scripts = ext.required_files['page_scripts'] self.required_interactives = ext.required_files['interactives'] diff --git a/verto/tests/ImageTagTest.py b/verto/tests/ImageTagTest.py index 9c885cfb..66d245e4 100644 --- a/verto/tests/ImageTagTest.py +++ b/verto/tests/ImageTagTest.py @@ -378,9 +378,9 @@ def test_image_width_value_external_image(self): expected_images = set() self.assertSetEqual(expected_images, images) - #~ + # ~ # Doc Tests - #~ + # ~ def test_doc_example_basic(self): '''Basic example of common usage. diff --git a/verto/tests/InteractiveContainerTest.py b/verto/tests/InteractiveContainerTest.py new file mode 100644 index 00000000..a254f4c7 --- /dev/null +++ b/verto/tests/InteractiveContainerTest.py @@ -0,0 +1,329 @@ +import markdown +from unittest.mock import Mock +from collections import defaultdict + +from verto.VertoExtension import VertoExtension +from verto.processors.InteractiveContainerBlockProcessor import InteractiveContainerBlockProcessor +from verto.errors.ArgumentMissingError import ArgumentMissingError +from verto.errors.ArgumentValueError import ArgumentValueError +from verto.tests.ProcessorTest import ProcessorTest + + +class InteractiveContainerTest(ProcessorTest): + '''The interactive processor is a simple tag with a complex + output that relies on external systems. + When writing tests whether or not the thumbnail is externally + or internally linked will changed output. If the thumbnail is + internal then the required files must be modified to include + this image. + ''' + + def __init__(self, *args, **kwargs): + '''Set processor name in class for file names. + ''' + ProcessorTest.__init__(self, *args, **kwargs) + self.processor_name = 'interactive-container' + self.ext = Mock() + self.ext.processor_info = ProcessorTest.loadProcessorInfo(self) + self.ext.jinja_templates = {self.processor_name: ProcessorTest.loadJinjaTemplate(self, 'interactive')} + self.ext.required_files = defaultdict(set) + + def test_whole_page_external_thumbnail(self): + '''Test external image for image thumbnail. + ''' + test_string = self.read_test_file(self.processor_name, 'whole_page_external_thumbnail.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'whole_page_external_thumbnail_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + required_files = { + 'interactives': { + "binary-cards" + }, + 'images': set(), + 'page_scripts': set(), + 'scratch_images': set() + } + self.assertEqual(self.verto_extension.required_files, required_files) + + # def test_whole_page_text(self): + # '''Test whole page interactive with text is correctly parsed. + # ''' + # test_string = self.read_test_file(self.processor_name, 'whole_page_text.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'whole_page_text_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # required_files = { + # 'interactives': { + # "binary-cards" + # }, + # 'images': { + # 'interactives/binary-cards/img/thumbnail.png' + # }, + # 'page_scripts': set(), + # 'scratch_images': set() + # } + # self.assertEqual(self.verto_extension.required_files, required_files) + + # def test_whole_page_parameters(self): + # '''Test whole page interactive with parameters is correctly parsed. + # ''' + # test_string = self.read_test_file(self.processor_name, 'whole_page_parameters.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'whole_page_parameters_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # required_files = { + # 'interactives': { + # "binary-cards" + # }, + # 'images': { + # 'interactives/binary-cards/img/thumbnail.png' + # }, + # 'page_scripts': set(), + # 'scratch_images': set() + # } + # self.assertEqual(self.verto_extension.required_files, required_files) + + # def test_whole_page_thumbnail(self): + # '''Test whole page interactive with thumbnail is correctly parsed and thumbnail path is added to required files. + # ''' + # test_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # required_files = { + # 'interactives': { + # "binary-cards" + # }, + # 'images': { + # 'interactives/binary-cards/img/binarycards.png' + # }, + # 'page_scripts': set(), + # 'scratch_images': set() + # } + # self.assertEqual(self.verto_extension.required_files, required_files) + + + # def test_whole_page_thumbnail_parameters(self): + # '''Test whole page interactive with thumbnail and parameters is correctly parsed and thumbnail path is added to required files. + # ''' + # test_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_parameters.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_parameters_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # required_files = { + # 'interactives': { + # "binary-cards" + # }, + # 'images': { + # 'binarycards.png' + # }, + # 'page_scripts': set(), + # 'scratch_images': set() + # } + # self.assertEqual(self.verto_extension.required_files, required_files) + + # def test_iframe_parameters(self): + # '''Test iframe interactive with parameters is correctly parsed. + # ''' + # test_string = self.read_test_file(self.processor_name, 'iframe_parameters.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'iframe_parameters_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # required_files = { + # 'interactives': { + # "binary-cards" + # }, + # 'images': set(), + # 'page_scripts': set(), + # 'scratch_images': set() + # } + # self.assertEqual(self.verto_extension.required_files, required_files) + + # def test_in_page_missing_name(self): + # '''Test ArgumentMissingError is raised when interactive name is not given. + # ''' + # test_string = self.read_test_file(self.processor_name, 'in_page_missing_name.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + # def test_missing_type(self): + # '''Test ArgumentMissingError is raised when interactive type is not given. + # ''' + # test_string = self.read_test_file(self.processor_name, 'missing_type.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + # def test_invalid_type(self): + # '''Test ArgumentValueError is raised when interactive type is not valid. + # ''' + # test_string = self.read_test_file(self.processor_name, 'invalid_type.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + # def test_multiple_interactives(self): + # '''Test multiple interactives in one file are all correctly parsed. + # ''' + # test_string = self.read_test_file(self.processor_name, 'multiple_interactives.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([False, True, False, True, False, True, False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'multiple_interactives_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # required_files = { + # 'interactives': { + # 'binary-cards', + # 'arrows', + # 'flying-boxes' + # }, + # 'images': { + # 'binarycards.png' + # }, + # 'page_scripts': { + # 'interactive/flying-boxes/scripts.html' + # }, + # 'scratch_images': set() + # } + # self.assertEqual(self.verto_extension.required_files, required_files) + + # #~ + # # Doc Tests + # #~ + + # def test_doc_example_in_page(self): + # '''Example of an in-page interactive. + # ''' + # test_string = self.read_test_file(self.processor_name, 'doc_example_in_page_usage.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'doc_example_in_page_usage_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # required_files = { + # 'interactives': { + # 'binary-cards' + # }, + # 'images': set(), + # 'page_scripts': { + # 'interactive/binary-cards/scripts.html' + # }, + # 'scratch_images': set() + # } + # self.assertEqual(self.verto_extension.required_files, required_files) + + # def test_doc_example_whole_page(self): + # '''Example of a whole-page interactive. + # ''' + # test_string = self.read_test_file(self.processor_name, 'doc_example_whole_page_usage.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'doc_example_whole_page_usage_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # required_files = { + # 'interactives': { + # "binary-cards" + # }, + # 'images': { + # 'interactives/binary-cards/img/thumbnail.png' + # }, + # 'page_scripts': set(), + # 'scratch_images': set() + # } + # self.assertEqual(self.verto_extension.required_files, required_files) + + # def test_doc_example_iframe(self): + # '''Example of an iframe interactive. + # ''' + # test_string = self.read_test_file(self.processor_name, 'doc_example_iframe_usage.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'doc_example_iframe_usage_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # required_files = { + # 'interactives': { + # 'binary-cards' + # }, + # 'images': set(), + # 'page_scripts': set(), + # 'scratch_images': set() + # } + # self.assertEqual(self.verto_extension.required_files, required_files) + + # def test_doc_example_override_html(self): + # '''Example showing overriding the html-template. + # ''' + # test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') + # blocks = self.to_blocks(test_string) + + # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + # html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) + # verto_extension = VertoExtension([self.processor_name], html_templates={self.processor_name: html_template}) + + # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + # expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) + # self.assertEqual(expected_string, converted_test_string) + + # required_files = { + # 'interactives': { + # 'binary-cards' + # }, + # 'images': { + # 'binarycards.png' + # }, + # 'page_scripts': set(), + # 'scratch_images': set() + # } + # self.assertEqual(verto_extension.required_files, required_files) diff --git a/verto/tests/InteractiveTest.py b/verto/tests/InteractiveTagTest.py similarity index 83% rename from verto/tests/InteractiveTest.py rename to verto/tests/InteractiveTagTest.py index ba00cd24..b421a128 100644 --- a/verto/tests/InteractiveTest.py +++ b/verto/tests/InteractiveTagTest.py @@ -3,13 +3,13 @@ from collections import defaultdict from verto.VertoExtension import VertoExtension -from verto.processors.InteractiveBlockProcessor import InteractiveBlockProcessor +from verto.processors.InteractiveTagBlockProcessor import InteractiveTagBlockProcessor from verto.errors.ArgumentMissingError import ArgumentMissingError from verto.errors.ArgumentValueError import ArgumentValueError from verto.tests.ProcessorTest import ProcessorTest -class InteractiveTest(ProcessorTest): +class InteractiveTagTest(ProcessorTest): '''The interactive processor is a simple tag with a complex output that relies on external systems. When writing tests whether or not the thumbnail is externally @@ -22,7 +22,7 @@ def __init__(self, *args, **kwargs): '''Set processor name in class for file names. ''' ProcessorTest.__init__(self, *args, **kwargs) - self.processor_name = 'interactive' + self.processor_name = 'interactive-tag' self.ext = Mock() self.ext.processor_info = ProcessorTest.loadProcessorInfo(self) self.ext.jinja_templates = {self.processor_name: ProcessorTest.loadJinjaTemplate(self, self.processor_name)} @@ -34,7 +34,7 @@ def test_whole_page_external_thumbnail(self): test_string = self.read_test_file(self.processor_name, 'whole_page_external_thumbnail.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'whole_page_external_thumbnail_expected.html', strip=True) @@ -56,7 +56,7 @@ def test_whole_page_text(self): test_string = self.read_test_file(self.processor_name, 'whole_page_text.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'whole_page_text_expected.html', strip=True) @@ -80,7 +80,7 @@ def test_whole_page_parameters(self): test_string = self.read_test_file(self.processor_name, 'whole_page_parameters.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'whole_page_parameters_expected.html', strip=True) @@ -104,7 +104,7 @@ def test_whole_page_thumbnail(self): test_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_expected.html', strip=True) @@ -129,7 +129,7 @@ def test_whole_page_thumbnail_parameters(self): test_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_parameters.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_parameters_expected.html', strip=True) @@ -153,7 +153,7 @@ def test_iframe_parameters(self): test_string = self.read_test_file(self.processor_name, 'iframe_parameters.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'iframe_parameters_expected.html', strip=True) @@ -175,7 +175,7 @@ def test_in_page_missing_name(self): test_string = self.read_test_file(self.processor_name, 'in_page_missing_name.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) @@ -185,7 +185,7 @@ def test_missing_type(self): test_string = self.read_test_file(self.processor_name, 'missing_type.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) @@ -195,7 +195,7 @@ def test_invalid_type(self): test_string = self.read_test_file(self.processor_name, 'invalid_type.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) @@ -205,7 +205,7 @@ def test_multiple_interactives(self): test_string = self.read_test_file(self.processor_name, 'multiple_interactives.md') blocks = self.to_blocks(test_string) - self.assertListEqual([False, True, False, True, False, True, False], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, True, False, True, False, True, False], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'multiple_interactives_expected.html', strip=True) @@ -237,7 +237,7 @@ def test_doc_example_in_page(self): test_string = self.read_test_file(self.processor_name, 'doc_example_in_page_usage.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'doc_example_in_page_usage_expected.html', strip=True) @@ -261,7 +261,7 @@ def test_doc_example_whole_page(self): test_string = self.read_test_file(self.processor_name, 'doc_example_whole_page_usage.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'doc_example_whole_page_usage_expected.html', strip=True) @@ -285,7 +285,7 @@ def test_doc_example_iframe(self): test_string = self.read_test_file(self.processor_name, 'doc_example_iframe_usage.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'doc_example_iframe_usage_expected.html', strip=True) @@ -307,7 +307,7 @@ def test_doc_example_override_html(self): test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) verto_extension = VertoExtension([self.processor_name], html_templates={self.processor_name: html_template}) diff --git a/verto/tests/assets/interactive/doc_example_iframe_usage.md b/verto/tests/assets/interactive-container/doc_example_iframe_usage.md similarity index 100% rename from verto/tests/assets/interactive/doc_example_iframe_usage.md rename to verto/tests/assets/interactive-container/doc_example_iframe_usage.md diff --git a/verto/tests/assets/interactive/doc_example_iframe_usage_expected.html b/verto/tests/assets/interactive-container/doc_example_iframe_usage_expected.html similarity index 100% rename from verto/tests/assets/interactive/doc_example_iframe_usage_expected.html rename to verto/tests/assets/interactive-container/doc_example_iframe_usage_expected.html diff --git a/verto/tests/assets/interactive/doc_example_in_page_usage.md b/verto/tests/assets/interactive-container/doc_example_in_page_usage.md similarity index 100% rename from verto/tests/assets/interactive/doc_example_in_page_usage.md rename to verto/tests/assets/interactive-container/doc_example_in_page_usage.md diff --git a/verto/tests/assets/interactive/doc_example_in_page_usage_expected.html b/verto/tests/assets/interactive-container/doc_example_in_page_usage_expected.html similarity index 100% rename from verto/tests/assets/interactive/doc_example_in_page_usage_expected.html rename to verto/tests/assets/interactive-container/doc_example_in_page_usage_expected.html diff --git a/verto/tests/assets/interactive/doc_example_override_html.md b/verto/tests/assets/interactive-container/doc_example_override_html.md similarity index 100% rename from verto/tests/assets/interactive/doc_example_override_html.md rename to verto/tests/assets/interactive-container/doc_example_override_html.md diff --git a/verto/tests/assets/interactive/doc_example_override_html_expected.html b/verto/tests/assets/interactive-container/doc_example_override_html_expected.html similarity index 100% rename from verto/tests/assets/interactive/doc_example_override_html_expected.html rename to verto/tests/assets/interactive-container/doc_example_override_html_expected.html diff --git a/verto/tests/assets/interactive/doc_example_override_html_template.html b/verto/tests/assets/interactive-container/doc_example_override_html_template.html similarity index 100% rename from verto/tests/assets/interactive/doc_example_override_html_template.html rename to verto/tests/assets/interactive-container/doc_example_override_html_template.html diff --git a/verto/tests/assets/interactive/doc_example_override_thumbnail_html.md b/verto/tests/assets/interactive-container/doc_example_override_thumbnail_html.md similarity index 100% rename from verto/tests/assets/interactive/doc_example_override_thumbnail_html.md rename to verto/tests/assets/interactive-container/doc_example_override_thumbnail_html.md diff --git a/verto/tests/assets/interactive/doc_example_override_thumbnail_html_expected.html b/verto/tests/assets/interactive-container/doc_example_override_thumbnail_html_expected.html similarity index 100% rename from verto/tests/assets/interactive/doc_example_override_thumbnail_html_expected.html rename to verto/tests/assets/interactive-container/doc_example_override_thumbnail_html_expected.html diff --git a/verto/tests/assets/interactive/doc_example_thumbnail_path_html_template.html b/verto/tests/assets/interactive-container/doc_example_thumbnail_path_html_template.html similarity index 100% rename from verto/tests/assets/interactive/doc_example_thumbnail_path_html_template.html rename to verto/tests/assets/interactive-container/doc_example_thumbnail_path_html_template.html diff --git a/verto/tests/assets/interactive/doc_example_whole_page_usage.md b/verto/tests/assets/interactive-container/doc_example_whole_page_usage.md similarity index 100% rename from verto/tests/assets/interactive/doc_example_whole_page_usage.md rename to verto/tests/assets/interactive-container/doc_example_whole_page_usage.md diff --git a/verto/tests/assets/interactive/doc_example_whole_page_usage_expected.html b/verto/tests/assets/interactive-container/doc_example_whole_page_usage_expected.html similarity index 100% rename from verto/tests/assets/interactive/doc_example_whole_page_usage_expected.html rename to verto/tests/assets/interactive-container/doc_example_whole_page_usage_expected.html diff --git a/verto/tests/assets/interactive/iframe_parameters.md b/verto/tests/assets/interactive-container/iframe_parameters.md similarity index 100% rename from verto/tests/assets/interactive/iframe_parameters.md rename to verto/tests/assets/interactive-container/iframe_parameters.md diff --git a/verto/tests/assets/interactive/iframe_parameters_expected.html b/verto/tests/assets/interactive-container/iframe_parameters_expected.html similarity index 100% rename from verto/tests/assets/interactive/iframe_parameters_expected.html rename to verto/tests/assets/interactive-container/iframe_parameters_expected.html diff --git a/verto/tests/assets/interactive/in_page_missing_name.md b/verto/tests/assets/interactive-container/in_page_missing_name.md similarity index 100% rename from verto/tests/assets/interactive/in_page_missing_name.md rename to verto/tests/assets/interactive-container/in_page_missing_name.md diff --git a/verto/tests/assets/interactive/in_page_missing_name_expected.html b/verto/tests/assets/interactive-container/in_page_missing_name_expected.html similarity index 100% rename from verto/tests/assets/interactive/in_page_missing_name_expected.html rename to verto/tests/assets/interactive-container/in_page_missing_name_expected.html diff --git a/verto/tests/assets/interactive/invalid_type.md b/verto/tests/assets/interactive-container/invalid_type.md similarity index 100% rename from verto/tests/assets/interactive/invalid_type.md rename to verto/tests/assets/interactive-container/invalid_type.md diff --git a/verto/tests/assets/interactive/missing_type.md b/verto/tests/assets/interactive-container/missing_type.md similarity index 100% rename from verto/tests/assets/interactive/missing_type.md rename to verto/tests/assets/interactive-container/missing_type.md diff --git a/verto/tests/assets/interactive/multiple_interactives.md b/verto/tests/assets/interactive-container/multiple_interactives.md similarity index 100% rename from verto/tests/assets/interactive/multiple_interactives.md rename to verto/tests/assets/interactive-container/multiple_interactives.md diff --git a/verto/tests/assets/interactive/multiple_interactives_expected.html b/verto/tests/assets/interactive-container/multiple_interactives_expected.html similarity index 100% rename from verto/tests/assets/interactive/multiple_interactives_expected.html rename to verto/tests/assets/interactive-container/multiple_interactives_expected.html diff --git a/verto/tests/assets/interactive-container/whole_page_external_thumbnail.md b/verto/tests/assets/interactive-container/whole_page_external_thumbnail.md new file mode 100644 index 00000000..18747d6e --- /dev/null +++ b/verto/tests/assets/interactive-container/whole_page_external_thumbnail.md @@ -0,0 +1,5 @@ +{interactive text="true" slug="binary-cards" type="whole-page" thumbnail="http://totallylegit/filepath/foran/image.png"} + +Binary Cards + +{interactive end} diff --git a/verto/tests/assets/interactive/whole_page_external_thumbnail_expected.html b/verto/tests/assets/interactive-container/whole_page_external_thumbnail_expected.html similarity index 100% rename from verto/tests/assets/interactive/whole_page_external_thumbnail_expected.html rename to verto/tests/assets/interactive-container/whole_page_external_thumbnail_expected.html diff --git a/verto/tests/assets/interactive/whole_page_parameters.md b/verto/tests/assets/interactive-container/whole_page_parameters.md similarity index 100% rename from verto/tests/assets/interactive/whole_page_parameters.md rename to verto/tests/assets/interactive-container/whole_page_parameters.md diff --git a/verto/tests/assets/interactive/whole_page_parameters_expected.html b/verto/tests/assets/interactive-container/whole_page_parameters_expected.html similarity index 100% rename from verto/tests/assets/interactive/whole_page_parameters_expected.html rename to verto/tests/assets/interactive-container/whole_page_parameters_expected.html diff --git a/verto/tests/assets/interactive/whole_page_text.md b/verto/tests/assets/interactive-container/whole_page_text.md similarity index 100% rename from verto/tests/assets/interactive/whole_page_text.md rename to verto/tests/assets/interactive-container/whole_page_text.md diff --git a/verto/tests/assets/interactive/whole_page_text_expected.html b/verto/tests/assets/interactive-container/whole_page_text_expected.html similarity index 100% rename from verto/tests/assets/interactive/whole_page_text_expected.html rename to verto/tests/assets/interactive-container/whole_page_text_expected.html diff --git a/verto/tests/assets/interactive/whole_page_thumbnail.md b/verto/tests/assets/interactive-container/whole_page_thumbnail.md similarity index 100% rename from verto/tests/assets/interactive/whole_page_thumbnail.md rename to verto/tests/assets/interactive-container/whole_page_thumbnail.md diff --git a/verto/tests/assets/interactive/whole_page_thumbnail_expected.html b/verto/tests/assets/interactive-container/whole_page_thumbnail_expected.html similarity index 100% rename from verto/tests/assets/interactive/whole_page_thumbnail_expected.html rename to verto/tests/assets/interactive-container/whole_page_thumbnail_expected.html diff --git a/verto/tests/assets/interactive/whole_page_thumbnail_parameters.md b/verto/tests/assets/interactive-container/whole_page_thumbnail_parameters.md similarity index 100% rename from verto/tests/assets/interactive/whole_page_thumbnail_parameters.md rename to verto/tests/assets/interactive-container/whole_page_thumbnail_parameters.md diff --git a/verto/tests/assets/interactive/whole_page_thumbnail_parameters_expected.html b/verto/tests/assets/interactive-container/whole_page_thumbnail_parameters_expected.html similarity index 100% rename from verto/tests/assets/interactive/whole_page_thumbnail_parameters_expected.html rename to verto/tests/assets/interactive-container/whole_page_thumbnail_parameters_expected.html diff --git a/verto/tests/assets/interactive-tag/doc_example_iframe_usage.md b/verto/tests/assets/interactive-tag/doc_example_iframe_usage.md new file mode 100644 index 00000000..e06b0837 --- /dev/null +++ b/verto/tests/assets/interactive-tag/doc_example_iframe_usage.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"} diff --git a/verto/tests/assets/interactive-tag/doc_example_iframe_usage_expected.html b/verto/tests/assets/interactive-tag/doc_example_iframe_usage_expected.html new file mode 100644 index 00000000..25f235b0 --- /dev/null +++ b/verto/tests/assets/interactive-tag/doc_example_iframe_usage_expected.html @@ -0,0 +1,3 @@ + diff --git a/verto/tests/assets/interactive-tag/doc_example_in_page_usage.md b/verto/tests/assets/interactive-tag/doc_example_in_page_usage.md new file mode 100644 index 00000000..bc4f421a --- /dev/null +++ b/verto/tests/assets/interactive-tag/doc_example_in_page_usage.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="in-page"} diff --git a/verto/tests/assets/interactive-tag/doc_example_in_page_usage_expected.html b/verto/tests/assets/interactive-tag/doc_example_in_page_usage_expected.html new file mode 100644 index 00000000..3bc4a667 --- /dev/null +++ b/verto/tests/assets/interactive-tag/doc_example_in_page_usage_expected.html @@ -0,0 +1 @@ +{% include 'interactive/binary-cards/index.html' %} diff --git a/verto/tests/assets/interactive-tag/doc_example_override_html.md b/verto/tests/assets/interactive-tag/doc_example_override_html.md new file mode 100644 index 00000000..352b06ab --- /dev/null +++ b/verto/tests/assets/interactive-tag/doc_example_override_html.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive-tag/doc_example_override_html_expected.html b/verto/tests/assets/interactive-tag/doc_example_override_html_expected.html new file mode 100644 index 00000000..fb071360 --- /dev/null +++ b/verto/tests/assets/interactive-tag/doc_example_override_html_expected.html @@ -0,0 +1,5 @@ + +
    +Binary Cards Interactive +
    +
    diff --git a/verto/tests/assets/interactive-tag/doc_example_override_html_template.html b/verto/tests/assets/interactive-tag/doc_example_override_html_template.html new file mode 100644 index 00000000..701edf7e --- /dev/null +++ b/verto/tests/assets/interactive-tag/doc_example_override_html_template.html @@ -0,0 +1,21 @@ +{% if type == 'in-page' -%} +
    +{{ "{{% include 'interactive/" }}{{ slug }}{{ "/index.html' %}}" }} +
    +{% elif type == 'iframe' -%} + +{% elif type == 'whole-page' -%} + +
    +{% if text -%} +{{ text }} +{% else -%} +Click to load {{ slug }} +{% endif -%} +
    +
    +{%- endif -%} diff --git a/verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html.md b/verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html.md new file mode 100644 index 00000000..352b06ab --- /dev/null +++ b/verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html_expected.html b/verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html_expected.html new file mode 100644 index 00000000..3fe204ff --- /dev/null +++ b/verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html_expected.html @@ -0,0 +1,6 @@ + + +
    +Binary Cards Interactive +
    +
    diff --git a/verto/tests/assets/interactive-tag/doc_example_thumbnail_path_html_template.html b/verto/tests/assets/interactive-tag/doc_example_thumbnail_path_html_template.html new file mode 100644 index 00000000..56d4c58a --- /dev/null +++ b/verto/tests/assets/interactive-tag/doc_example_thumbnail_path_html_template.html @@ -0,0 +1,3 @@ +{% autoescape false -%} +{{ "{% static '" }}interactives/{{ slug }}/img/{{ file_path }}{{ "' %}" }} +{%- endautoescape %} diff --git a/verto/tests/assets/interactive-tag/doc_example_whole_page_usage.md b/verto/tests/assets/interactive-tag/doc_example_whole_page_usage.md new file mode 100644 index 00000000..aa820f2d --- /dev/null +++ b/verto/tests/assets/interactive-tag/doc_example_whole_page_usage.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive-tag/doc_example_whole_page_usage_expected.html b/verto/tests/assets/interactive-tag/doc_example_whole_page_usage_expected.html new file mode 100644 index 00000000..fea9ee9c --- /dev/null +++ b/verto/tests/assets/interactive-tag/doc_example_whole_page_usage_expected.html @@ -0,0 +1,6 @@ + + +
    +Binary Cards Interactive +
    +
    diff --git a/verto/tests/assets/interactive-tag/iframe_parameters.md b/verto/tests/assets/interactive-tag/iframe_parameters.md new file mode 100644 index 00000000..e06b0837 --- /dev/null +++ b/verto/tests/assets/interactive-tag/iframe_parameters.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"} diff --git a/verto/tests/assets/interactive-tag/iframe_parameters_expected.html b/verto/tests/assets/interactive-tag/iframe_parameters_expected.html new file mode 100644 index 00000000..25f235b0 --- /dev/null +++ b/verto/tests/assets/interactive-tag/iframe_parameters_expected.html @@ -0,0 +1,3 @@ + diff --git a/verto/tests/assets/interactive-tag/in_page_missing_name.md b/verto/tests/assets/interactive-tag/in_page_missing_name.md new file mode 100644 index 00000000..b7ddcbe1 --- /dev/null +++ b/verto/tests/assets/interactive-tag/in_page_missing_name.md @@ -0,0 +1 @@ +{interactive type="in-page"} diff --git a/verto/tests/assets/interactive-tag/in_page_missing_name_expected.html b/verto/tests/assets/interactive-tag/in_page_missing_name_expected.html new file mode 100644 index 00000000..3bc4a667 --- /dev/null +++ b/verto/tests/assets/interactive-tag/in_page_missing_name_expected.html @@ -0,0 +1 @@ +{% include 'interactive/binary-cards/index.html' %} diff --git a/verto/tests/assets/interactive-tag/invalid_type.md b/verto/tests/assets/interactive-tag/invalid_type.md new file mode 100644 index 00000000..62b2d6d2 --- /dev/null +++ b/verto/tests/assets/interactive-tag/invalid_type.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="not-a-real-type" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive-tag/missing_type.md b/verto/tests/assets/interactive-tag/missing_type.md new file mode 100644 index 00000000..7efd0ef9 --- /dev/null +++ b/verto/tests/assets/interactive-tag/missing_type.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive-tag/multiple_interactives.md b/verto/tests/assets/interactive-tag/multiple_interactives.md new file mode 100644 index 00000000..45d248a1 --- /dev/null +++ b/verto/tests/assets/interactive-tag/multiple_interactives.md @@ -0,0 +1,13 @@ +This is some text. + +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png"} + +This is some more text. + +{interactive slug="arrows" type="iframe" parameters="digits=5&start=BBBBB"} + +And some more text again. + +{interactive slug="flying-boxes" type="in-page"} + +Aaaaaaaaaaaaaaaannnnnd here's some more. diff --git a/verto/tests/assets/interactive-tag/multiple_interactives_expected.html b/verto/tests/assets/interactive-tag/multiple_interactives_expected.html new file mode 100644 index 00000000..fe8c70a2 --- /dev/null +++ b/verto/tests/assets/interactive-tag/multiple_interactives_expected.html @@ -0,0 +1,13 @@ +

    This is some text.

    + + +
    +Click to load binary-cards +
    +

    This is some more text.

    + +

    And some more text again.

    +{% include 'interactive/flying-boxes/index.html' %} +

    Aaaaaaaaaaaaaaaannnnnd here's some more.

    diff --git a/verto/tests/assets/interactive/whole_page_external_thumbnail.md b/verto/tests/assets/interactive-tag/whole_page_external_thumbnail.md similarity index 100% rename from verto/tests/assets/interactive/whole_page_external_thumbnail.md rename to verto/tests/assets/interactive-tag/whole_page_external_thumbnail.md diff --git a/verto/tests/assets/interactive-tag/whole_page_external_thumbnail_expected.html b/verto/tests/assets/interactive-tag/whole_page_external_thumbnail_expected.html new file mode 100644 index 00000000..cb1677dc --- /dev/null +++ b/verto/tests/assets/interactive-tag/whole_page_external_thumbnail_expected.html @@ -0,0 +1,6 @@ + + +
    +Click to load binary-cards +
    +
    diff --git a/verto/tests/assets/interactive-tag/whole_page_parameters.md b/verto/tests/assets/interactive-tag/whole_page_parameters.md new file mode 100644 index 00000000..aa820f2d --- /dev/null +++ b/verto/tests/assets/interactive-tag/whole_page_parameters.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive-tag/whole_page_parameters_expected.html b/verto/tests/assets/interactive-tag/whole_page_parameters_expected.html new file mode 100644 index 00000000..fea9ee9c --- /dev/null +++ b/verto/tests/assets/interactive-tag/whole_page_parameters_expected.html @@ -0,0 +1,6 @@ + + +
    +Binary Cards Interactive +
    +
    diff --git a/verto/tests/assets/interactive-tag/whole_page_text.md b/verto/tests/assets/interactive-tag/whole_page_text.md new file mode 100644 index 00000000..396f316e --- /dev/null +++ b/verto/tests/assets/interactive-tag/whole_page_text.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive-tag/whole_page_text_expected.html b/verto/tests/assets/interactive-tag/whole_page_text_expected.html new file mode 100644 index 00000000..a259a370 --- /dev/null +++ b/verto/tests/assets/interactive-tag/whole_page_text_expected.html @@ -0,0 +1,6 @@ + + +
    +Binary Cards Interactive +
    +
    diff --git a/verto/tests/assets/interactive-tag/whole_page_thumbnail.md b/verto/tests/assets/interactive-tag/whole_page_thumbnail.md new file mode 100644 index 00000000..4625c3a2 --- /dev/null +++ b/verto/tests/assets/interactive-tag/whole_page_thumbnail.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" thumbnail="interactives/binary-cards/img/binarycards.png"} diff --git a/verto/tests/assets/interactive-tag/whole_page_thumbnail_expected.html b/verto/tests/assets/interactive-tag/whole_page_thumbnail_expected.html new file mode 100644 index 00000000..9ec659d6 --- /dev/null +++ b/verto/tests/assets/interactive-tag/whole_page_thumbnail_expected.html @@ -0,0 +1,6 @@ + + +
    +Click to load binary-cards +
    +
    diff --git a/verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters.md b/verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters.md new file mode 100644 index 00000000..33681e40 --- /dev/null +++ b/verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png"} diff --git a/verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters_expected.html b/verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters_expected.html new file mode 100644 index 00000000..f1b49c5e --- /dev/null +++ b/verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters_expected.html @@ -0,0 +1,6 @@ + + +
    +Click to load binary-cards +
    +
    diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 5cfc39b3..972e94f6 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -14,7 +14,8 @@ from verto.tests.ImageTagTest import ImageTagTest from verto.tests.ImageContainerTest import ImageContainerTest from verto.tests.JinjaTest import JinjaTest -from verto.tests.InteractiveTest import InteractiveTest +from verto.tests.InteractiveTagTest import InteractiveTagTest +from verto.tests.InteractiveContainerTest import InteractiveContainerTest from verto.tests.PanelTest import PanelTest from verto.tests.RelativeLinkTest import RelativeLinkTest from verto.tests.RemoveTest import RemoveTest @@ -85,31 +86,32 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - unittest.makeSuite(BoxedTextTest), - unittest.makeSuite(ButtonLinkTest), - unittest.makeSuite(CommentTest), - unittest.makeSuite(ConditionalTest), - unittest.makeSuite(FrameTest), - unittest.makeSuite(GlossaryLinkTest), - unittest.makeSuite(HeadingTest), - unittest.makeSuite(ImageInlineTest), - unittest.makeSuite(ImageTagTest), - unittest.makeSuite(ImageContainerTest), - unittest.makeSuite(InteractiveTest), - unittest.makeSuite(JinjaTest), - unittest.makeSuite(PanelTest), - unittest.makeSuite(SaveTitleTest), - unittest.makeSuite(ScratchTest), - unittest.makeSuite(ScratchInlineTest), - unittest.makeSuite(StyleTest), - unittest.makeSuite(RelativeLinkTest), - unittest.makeSuite(RemoveTest), - unittest.makeSuite(RemoveTitleTest), - unittest.makeSuite(TableOfContentsTest), - unittest.makeSuite(VideoTest), - - unittest.makeSuite(HtmlParserTest), - unittest.makeSuite(MarkdownOverrideTest), + # unittest.makeSuite(BoxedTextTest), + # unittest.makeSuite(ButtonLinkTest), + # unittest.makeSuite(CommentTest), + # unittest.makeSuite(ConditionalTest), + # unittest.makeSuite(FrameTest), + # unittest.makeSuite(GlossaryLinkTest), + # unittest.makeSuite(HeadingTest), + # unittest.makeSuite(ImageInlineTest), + # unittest.makeSuite(ImageTagTest), + # unittest.makeSuite(ImageContainerTest), + # unittest.makeSuite(InteractiveTagTest), + unittest.makeSuite(InteractiveContainerTest), + # unittest.makeSuite(JinjaTest), + # unittest.makeSuite(PanelTest), + # unittest.makeSuite(SaveTitleTest), + # unittest.makeSuite(ScratchTest), + # unittest.makeSuite(ScratchInlineTest), + # unittest.makeSuite(StyleTest), + # unittest.makeSuite(RelativeLinkTest), + # unittest.makeSuite(RemoveTest), + # unittest.makeSuite(RemoveTitleTest), + # unittest.makeSuite(TableOfContentsTest), + # unittest.makeSuite(VideoTest), + + # unittest.makeSuite(HtmlParserTest), + # unittest.makeSuite(MarkdownOverrideTest), )) From 8138c7fabf3a83c4b619fc97f6df40ac0119ba1d Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Sun, 5 Aug 2018 22:44:13 +1200 Subject: [PATCH 59/73] WIP adding tests for new interactive processor --- verto/errors/InteractiveMissingTextError.py | 16 ++ ...InteractiveTextContainsInteractiveError.py | 14 ++ .../InteractiveContainerBlockProcessor.py | 11 +- verto/tests/InteractiveContainerTest.py | 137 +++++++++++------- .../multiple_interactives.md | 13 -- .../multiple_interactives_some_text.md | 23 +++ ...tiple_interactives_some_text_expected.html | 14 ++ .../multiple_interactives_text_true.md | 25 ++++ ...iple_interactives_text_true_expected.html} | 10 +- .../text_true_missing_end_tag.md | 7 + .../text_true_not_provided.md | 7 + ...hole_page_external_thumbnail_expected.html | 2 +- 12 files changed, 208 insertions(+), 71 deletions(-) create mode 100644 verto/errors/InteractiveMissingTextError.py create mode 100644 verto/errors/InteractiveTextContainsInteractiveError.py delete mode 100644 verto/tests/assets/interactive-container/multiple_interactives.md create mode 100644 verto/tests/assets/interactive-container/multiple_interactives_some_text.md create mode 100644 verto/tests/assets/interactive-container/multiple_interactives_some_text_expected.html create mode 100644 verto/tests/assets/interactive-container/multiple_interactives_text_true.md rename verto/tests/assets/interactive-container/{multiple_interactives_expected.html => multiple_interactives_text_true_expected.html} (67%) create mode 100644 verto/tests/assets/interactive-container/text_true_missing_end_tag.md create mode 100644 verto/tests/assets/interactive-container/text_true_not_provided.md diff --git a/verto/errors/InteractiveMissingTextError.py b/verto/errors/InteractiveMissingTextError.py new file mode 100644 index 00000000..6cd0067e --- /dev/null +++ b/verto/errors/InteractiveMissingTextError.py @@ -0,0 +1,16 @@ +from verto.errors.Error import Error + + +class InteractiveMissingTextError(Error): + '''Exception raised when an interactve is missing text. + + Attributes: + tag: tag which was not matched + argument: the argument that was not found + ''' + + def __init__(self, tag, argument): + self.tag = tag + self.argument = argument + self.message = '\'text\' is \'true\' but not supplied.' + super().__init__(self.message) diff --git a/verto/errors/InteractiveTextContainsInteractiveError.py b/verto/errors/InteractiveTextContainsInteractiveError.py new file mode 100644 index 00000000..a407d1a0 --- /dev/null +++ b/verto/errors/InteractiveTextContainsInteractiveError.py @@ -0,0 +1,14 @@ +from verto.errors.Error import Error + + +class InteractiveTextContainsInteractiveError(Error): + '''Exception raised when a text includes an interactive block. + + Attributes: + tag: tag which was not matched + ''' + + def __init__(self, tag): + self.tag = tag + self.message = 'Interactive text cannot contain another interactive.' + super().__init__(self.message) diff --git a/verto/processors/InteractiveContainerBlockProcessor.py b/verto/processors/InteractiveContainerBlockProcessor.py index ef634f91..98d0563f 100644 --- a/verto/processors/InteractiveContainerBlockProcessor.py +++ b/verto/processors/InteractiveContainerBlockProcessor.py @@ -1,7 +1,6 @@ from verto.processors.GenericContainerBlockProcessor import GenericContainerBlockProcessor -# TODO implement the following errors -# from verto.errors.InteractiveTextContainsInteractiveError import InteractiveTextContainsInteractiveError -# from verto.errors.InteractiveMissingTextError import InteractiveMissingTextError +from verto.errors.InteractiveTextContainsInteractiveError import InteractiveTextContainsInteractiveError +from verto.errors.InteractiveMissingTextError import InteractiveMissingTextError import re @@ -57,6 +56,12 @@ def custom_parsing(self, content_blocks, argument_values): raise InteractiveTextContainsInteractiveError(self.processor) extra_args = {} + + argument = 'text' + if len(content_blocks) == 0 or content_blocks[0] == '': + raise InteractiveMissingTextError(self.processor, argument) + extra_args[argument] = content_blocks[0] + interactive_type = argument_values['type'] slug = argument_values['slug'] diff --git a/verto/tests/InteractiveContainerTest.py b/verto/tests/InteractiveContainerTest.py index a254f4c7..02e8785c 100644 --- a/verto/tests/InteractiveContainerTest.py +++ b/verto/tests/InteractiveContainerTest.py @@ -6,6 +6,9 @@ from verto.processors.InteractiveContainerBlockProcessor import InteractiveContainerBlockProcessor from verto.errors.ArgumentMissingError import ArgumentMissingError from verto.errors.ArgumentValueError import ArgumentValueError +from verto.errors.TagNotMatchedError import TagNotMatchedError +from verto.errors.InteractiveTextContainsInteractiveError import InteractiveTextContainsInteractiveError +from verto.errors.InteractiveMissingTextError import InteractiveMissingTextError from verto.tests.ProcessorTest import ProcessorTest @@ -23,9 +26,10 @@ def __init__(self, *args, **kwargs): ''' ProcessorTest.__init__(self, *args, **kwargs) self.processor_name = 'interactive-container' + self.tag_argument = 'interactive' self.ext = Mock() + self.ext.jinja_templates = {'interactive': ProcessorTest.loadJinjaTemplate(self, 'interactive')} self.ext.processor_info = ProcessorTest.loadProcessorInfo(self) - self.ext.jinja_templates = {self.processor_name: ProcessorTest.loadJinjaTemplate(self, 'interactive')} self.ext.required_files = defaultdict(set) def test_whole_page_external_thumbnail(self): @@ -34,7 +38,7 @@ def test_whole_page_external_thumbnail(self): test_string = self.read_test_file(self.processor_name, 'whole_page_external_thumbnail.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True, False, True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'whole_page_external_thumbnail_expected.html', strip=True) @@ -50,29 +54,92 @@ def test_whole_page_external_thumbnail(self): } self.assertEqual(self.verto_extension.required_files, required_files) - # def test_whole_page_text(self): - # '''Test whole page interactive with text is correctly parsed. + def test_text_true_not_provided(self): + '''Tests that InteractiveMissingTextError is thrown when text argument is true but not provided. + ''' + test_string = self.read_test_file(self.processor_name, 'text_true_not_provided.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, True, False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(InteractiveMissingTextError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + def test_text_true_missing_end_tag(self): + '''Tests that TagNotMatchedError is thrown when interactive tag is missing end tag. + ''' + test_string = self.read_test_file(self.processor_name, 'text_true_missing_end_tag.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False, False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(TagNotMatchedError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + def test_multiple_interactives_text_true(self): + '''Test multiple interactives in one file are all correctly parsed. + ''' + test_string = self.read_test_file(self.processor_name, 'multiple_interactives_text_true.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([False, True, False, True, False, True, False, True, False, True, False, True, False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'multiple_interactives_text_true_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + required_files = { + 'interactives': { + 'binary-cards', + 'arrows', + 'flying-boxes' + }, + 'images': { + 'binarycards.png' + }, + 'page_scripts': { + 'interactive/flying-boxes/scripts.html' + }, + 'scratch_images': set() + } + self.assertEqual(self.verto_extension.required_files, required_files) + + def test_contains_multiple_interactives_some_text(self): + '''Test multiple interactives in one file are all correctly parsed, and ignores those without text. # ''' - # test_string = self.read_test_file(self.processor_name, 'whole_page_text.md') - # blocks = self.to_blocks(test_string) + test_string = self.read_test_file(self.processor_name, 'multiple_interactives_some_text.md') + blocks = self.to_blocks(test_string) - # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, True, False, True, False, False, False, False, False, False, False, False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'whole_page_text_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'multiple_interactives_some_text_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # required_files = { - # 'interactives': { - # "binary-cards" - # }, - # 'images': { - # 'interactives/binary-cards/img/thumbnail.png' - # }, - # 'page_scripts': set(), - # 'scratch_images': set() - # } - # self.assertEqual(self.verto_extension.required_files, required_files) + required_files = { + 'interactives': { + 'binary-cards', + }, + 'images': { + 'binarycards.png' + }, + 'page_scripts': set(), + 'scratch_images': set() + } + self.assertEqual(self.verto_extension.required_files, required_files) + + # def test_text_false(self): + # '''Tests processor does not match interactive tag when text argument is not included. + # ''' + # pass + + # def test_no_text(self): + # '''Tests processor does not match interactive tag when text argument is not included. + # ''' + # pass + + # def test_interactive_in_interactive_tag(self): + # '''Test that InteractiveTextContainsInteractiveError is raised when the first line in an interactive container block is another interactive container block. + # ''' + # pass # def test_whole_page_parameters(self): # '''Test whole page interactive with parameters is correctly parsed. @@ -199,34 +266,6 @@ def test_whole_page_external_thumbnail(self): # self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - # def test_multiple_interactives(self): - # '''Test multiple interactives in one file are all correctly parsed. - # ''' - # test_string = self.read_test_file(self.processor_name, 'multiple_interactives.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([False, True, False, True, False, True, False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'multiple_interactives_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # required_files = { - # 'interactives': { - # 'binary-cards', - # 'arrows', - # 'flying-boxes' - # }, - # 'images': { - # 'binarycards.png' - # }, - # 'page_scripts': { - # 'interactive/flying-boxes/scripts.html' - # }, - # 'scratch_images': set() - # } - # self.assertEqual(self.verto_extension.required_files, required_files) - # #~ # # Doc Tests # #~ diff --git a/verto/tests/assets/interactive-container/multiple_interactives.md b/verto/tests/assets/interactive-container/multiple_interactives.md deleted file mode 100644 index 45d248a1..00000000 --- a/verto/tests/assets/interactive-container/multiple_interactives.md +++ /dev/null @@ -1,13 +0,0 @@ -This is some text. - -{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png"} - -This is some more text. - -{interactive slug="arrows" type="iframe" parameters="digits=5&start=BBBBB"} - -And some more text again. - -{interactive slug="flying-boxes" type="in-page"} - -Aaaaaaaaaaaaaaaannnnnd here's some more. diff --git a/verto/tests/assets/interactive-container/multiple_interactives_some_text.md b/verto/tests/assets/interactive-container/multiple_interactives_some_text.md new file mode 100644 index 00000000..c6d3cd9c --- /dev/null +++ b/verto/tests/assets/interactive-container/multiple_interactives_some_text.md @@ -0,0 +1,23 @@ +I'd kiss you as the lights went out + +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="true"} + +Swaying as the room burned down + +{interactive end} + +I'd hold you as the water rushes in + +{interactive slug="arrows" text="false" type="iframe" parameters="digits=5&start=BBBBB"} + +I'd kiss you as the lights went out + +{interactive slug="flying-boxes" type="in-page"} + +I'd hold you as the water rushes in + +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png"} + +I'd kiss you as the lights went out + +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="false"} diff --git a/verto/tests/assets/interactive-container/multiple_interactives_some_text_expected.html b/verto/tests/assets/interactive-container/multiple_interactives_some_text_expected.html new file mode 100644 index 00000000..50a37315 --- /dev/null +++ b/verto/tests/assets/interactive-container/multiple_interactives_some_text_expected.html @@ -0,0 +1,14 @@ +

    I'd kiss you as the lights went out

    + + +
    +Swaying as the room burned down +
    +

    I'd hold you as the water rushes in

    +

    {interactive slug="arrows" text="false" type="iframe" parameters="digits=5&start=BBBBB"}

    +

    I'd kiss you as the lights went out

    +

    {interactive slug="flying-boxes" type="in-page"}

    +

    I'd hold you as the water rushes in

    +

    {interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png"}

    +

    I'd kiss you as the lights went out

    +

    {interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="false"}

    diff --git a/verto/tests/assets/interactive-container/multiple_interactives_text_true.md b/verto/tests/assets/interactive-container/multiple_interactives_text_true.md new file mode 100644 index 00000000..4d7e8d8c --- /dev/null +++ b/verto/tests/assets/interactive-container/multiple_interactives_text_true.md @@ -0,0 +1,25 @@ +I'd kiss you as the lights went out + +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="true"} + +Swaying as the room burned down + +{interactive end} + +I'd hold you as the water rushes in + +{interactive slug="arrows" text="true" type="iframe" parameters="digits=5&start=BBBBB"} + +If I could dance with you again + +{interactive end} + +I'd kiss you as the lights went out + +{interactive text="true" slug="flying-boxes" type="in-page"} + +Swaying as the room burned down + +{interactive end} + +I'd hold you as the water rushes in diff --git a/verto/tests/assets/interactive-container/multiple_interactives_expected.html b/verto/tests/assets/interactive-container/multiple_interactives_text_true_expected.html similarity index 67% rename from verto/tests/assets/interactive-container/multiple_interactives_expected.html rename to verto/tests/assets/interactive-container/multiple_interactives_text_true_expected.html index fe8c70a2..97d9eb1b 100644 --- a/verto/tests/assets/interactive-container/multiple_interactives_expected.html +++ b/verto/tests/assets/interactive-container/multiple_interactives_text_true_expected.html @@ -1,13 +1,13 @@ -

    This is some text.

    +

    I'd kiss you as the lights went out

    -Click to load binary-cards +Swaying as the room burned down
    -

    This is some more text.

    +

    I'd hold you as the water rushes in

    -

    And some more text again.

    +

    I'd kiss you as the lights went out

    {% include 'interactive/flying-boxes/index.html' %} -

    Aaaaaaaaaaaaaaaannnnnd here's some more.

    +

    I'd hold you as the water rushes in

    diff --git a/verto/tests/assets/interactive-container/text_true_missing_end_tag.md b/verto/tests/assets/interactive-container/text_true_missing_end_tag.md new file mode 100644 index 00000000..f89d928b --- /dev/null +++ b/verto/tests/assets/interactive-container/text_true_missing_end_tag.md @@ -0,0 +1,7 @@ +you said there was nothing in the world that could stop it + +{interactive slug="binary-cards" type="whole-page" text="true" thumbnail="interactives/binary-cards/img/binarycards.png"} + +I had a bad feeling + +And darling... diff --git a/verto/tests/assets/interactive-container/text_true_not_provided.md b/verto/tests/assets/interactive-container/text_true_not_provided.md new file mode 100644 index 00000000..3a8107c3 --- /dev/null +++ b/verto/tests/assets/interactive-container/text_true_not_provided.md @@ -0,0 +1,7 @@ +I, I loved you in secret. + +{interactive slug="binary-cards" type="whole-page" text="true" thumbnail="interactives/binary-cards/img/binarycards.png"} + +{interactive end} + +First sight, yea, we love without reason. diff --git a/verto/tests/assets/interactive-container/whole_page_external_thumbnail_expected.html b/verto/tests/assets/interactive-container/whole_page_external_thumbnail_expected.html index cb1677dc..87326cdd 100644 --- a/verto/tests/assets/interactive-container/whole_page_external_thumbnail_expected.html +++ b/verto/tests/assets/interactive-container/whole_page_external_thumbnail_expected.html @@ -1,6 +1,6 @@
    -Click to load binary-cards +Binary Cards
    From 5c66d8c73b4d304925e92a478da2b767a6c80d5b Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 6 Aug 2018 11:48:26 +1200 Subject: [PATCH 60/73] Adding more tests for new interactive processor --- verto/tests/InteractiveContainerTest.py | 180 +++++++++++------- .../interactive_in_interactive_tag.md | 9 + .../assets/interactive-container/no_text.md | 5 + .../no_text_expected.html | 3 + .../interactive-container/text_false.md | 1 + .../text_false_expected.html | 1 + .../whole_page_parameters.md | 6 +- .../whole_page_thumbnail.md | 6 +- .../whole_page_thumbnail_expected.html | 2 +- .../whole_page_thumbnail_parameters.md | 8 +- ...le_page_thumbnail_parameters_expected.html | 4 +- 11 files changed, 146 insertions(+), 79 deletions(-) create mode 100644 verto/tests/assets/interactive-container/interactive_in_interactive_tag.md create mode 100644 verto/tests/assets/interactive-container/no_text.md create mode 100644 verto/tests/assets/interactive-container/no_text_expected.html create mode 100644 verto/tests/assets/interactive-container/text_false.md create mode 100644 verto/tests/assets/interactive-container/text_false_expected.html diff --git a/verto/tests/InteractiveContainerTest.py b/verto/tests/InteractiveContainerTest.py index 02e8785c..e32303ec 100644 --- a/verto/tests/InteractiveContainerTest.py +++ b/verto/tests/InteractiveContainerTest.py @@ -104,7 +104,7 @@ def test_multiple_interactives_text_true(self): def test_contains_multiple_interactives_some_text(self): '''Test multiple interactives in one file are all correctly parsed, and ignores those without text. - # ''' + ''' test_string = self.read_test_file(self.processor_name, 'multiple_interactives_some_text.md') blocks = self.to_blocks(test_string) @@ -126,93 +126,127 @@ def test_contains_multiple_interactives_some_text(self): } self.assertEqual(self.verto_extension.required_files, required_files) - # def test_text_false(self): - # '''Tests processor does not match interactive tag when text argument is not included. - # ''' - # pass + def test_text_false(self): + '''Tests processor does not match interactive tag when text argument is false. + ''' + test_string = self.read_test_file(self.processor_name, 'text_false.md') + blocks = self.to_blocks(test_string) - # def test_no_text(self): - # '''Tests processor does not match interactive tag when text argument is not included. - # ''' - # pass + self.assertListEqual([False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # def test_interactive_in_interactive_tag(self): - # '''Test that InteractiveTextContainsInteractiveError is raised when the first line in an interactive container block is another interactive container block. - # ''' - # pass + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'text_false_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_whole_page_parameters(self): - # '''Test whole page interactive with parameters is correctly parsed. - # ''' - # test_string = self.read_test_file(self.processor_name, 'whole_page_parameters.md') - # blocks = self.to_blocks(test_string) + required_files = { + 'interactives': set(), + 'images': set(), + 'page_scripts': set(), + 'scratch_images': set() + } + self.assertEqual(self.verto_extension.required_files, required_files) - # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + def test_no_text(self): + '''Tests processor does not match interactive tag when text argument is not included. + ''' + test_string = self.read_test_file(self.processor_name, 'no_text.md') + blocks = self.to_blocks(test_string) - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'whole_page_parameters_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + self.assertListEqual([False, False, False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # required_files = { - # 'interactives': { - # "binary-cards" - # }, - # 'images': { - # 'interactives/binary-cards/img/thumbnail.png' - # }, - # 'page_scripts': set(), - # 'scratch_images': set() - # } - # self.assertEqual(self.verto_extension.required_files, required_files) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'no_text_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # def test_whole_page_thumbnail(self): - # '''Test whole page interactive with thumbnail is correctly parsed and thumbnail path is added to required files. - # ''' - # test_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail.md') - # blocks = self.to_blocks(test_string) + required_files = { + 'interactives': set(), + 'images': set(), + 'page_scripts': set(), + 'scratch_images': set() + } + self.assertEqual(self.verto_extension.required_files, required_files) - # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + def test_interactive_in_interactive_tag(self): + '''Test that InteractiveTextContainsInteractiveError is raised when the first line in an interactive container block is another interactive container block. + ''' + test_string = self.read_test_file(self.processor_name, 'interactive_in_interactive_tag.md') + blocks = self.to_blocks(test_string) - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + self.assertListEqual([False, True, False, True, False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # required_files = { - # 'interactives': { - # "binary-cards" - # }, - # 'images': { - # 'interactives/binary-cards/img/binarycards.png' - # }, - # 'page_scripts': set(), - # 'scratch_images': set() - # } - # self.assertEqual(self.verto_extension.required_files, required_files) + self.assertRaises(InteractiveTextContainsInteractiveError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + def test_whole_page_parameters(self): + '''Test whole page interactive with parameters is correctly parsed. + ''' + test_string = self.read_test_file(self.processor_name, 'whole_page_parameters.md') + blocks = self.to_blocks(test_string) - # def test_whole_page_thumbnail_parameters(self): - # '''Test whole page interactive with thumbnail and parameters is correctly parsed and thumbnail path is added to required files. - # ''' - # test_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_parameters.md') - # blocks = self.to_blocks(test_string) + self.assertListEqual([True, False, True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'whole_page_parameters_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_parameters_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) + required_files = { + 'interactives': { + "binary-cards" + }, + 'images': { + 'interactives/binary-cards/img/thumbnail.png' + }, + 'page_scripts': set(), + 'scratch_images': set() + } + self.assertEqual(self.verto_extension.required_files, required_files) - # required_files = { - # 'interactives': { - # "binary-cards" - # }, - # 'images': { - # 'binarycards.png' - # }, - # 'page_scripts': set(), - # 'scratch_images': set() - # } - # self.assertEqual(self.verto_extension.required_files, required_files) + def test_whole_page_thumbnail(self): + '''Test whole page interactive with thumbnail is correctly parsed and thumbnail path is added to required files. + ''' + test_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + required_files = { + 'interactives': { + "binary-cards" + }, + 'images': { + 'interactives/binary-cards/img/binarycards.png' + }, + 'page_scripts': set(), + 'scratch_images': set() + } + self.assertEqual(self.verto_extension.required_files, required_files) + + def test_whole_page_thumbnail_parameters(self): + '''Test whole page interactive with thumbnail and parameters is correctly parsed and thumbnail path is added to required files. + ''' + test_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_parameters.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True, False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_parameters_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + required_files = { + 'interactives': { + "binary-cards" + }, + 'images': { + 'binarycards.png' + }, + 'page_scripts': set(), + 'scratch_images': set() + } + self.assertEqual(self.verto_extension.required_files, required_files) # def test_iframe_parameters(self): # '''Test iframe interactive with parameters is correctly parsed. diff --git a/verto/tests/assets/interactive-container/interactive_in_interactive_tag.md b/verto/tests/assets/interactive-container/interactive_in_interactive_tag.md new file mode 100644 index 00000000..5340594c --- /dev/null +++ b/verto/tests/assets/interactive-container/interactive_in_interactive_tag.md @@ -0,0 +1,9 @@ +Is it cool that I said all that + +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="true"} + +{interactive slug="arrows" text="false" type="iframe" parameters="digits=5&start=BBBBB"} + +{interactive end} + +Is it too soon to do this yet diff --git a/verto/tests/assets/interactive-container/no_text.md b/verto/tests/assets/interactive-container/no_text.md new file mode 100644 index 00000000..a11a41da --- /dev/null +++ b/verto/tests/assets/interactive-container/no_text.md @@ -0,0 +1,5 @@ +See you in the dark + +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB"} + +All eyes on you my magician diff --git a/verto/tests/assets/interactive-container/no_text_expected.html b/verto/tests/assets/interactive-container/no_text_expected.html new file mode 100644 index 00000000..6696871a --- /dev/null +++ b/verto/tests/assets/interactive-container/no_text_expected.html @@ -0,0 +1,3 @@ +

    See you in the dark

    +

    {interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB"}

    +

    All eyes on you my magician

    diff --git a/verto/tests/assets/interactive-container/text_false.md b/verto/tests/assets/interactive-container/text_false.md new file mode 100644 index 00000000..f9bfcf2d --- /dev/null +++ b/verto/tests/assets/interactive-container/text_false.md @@ -0,0 +1 @@ +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="false"} diff --git a/verto/tests/assets/interactive-container/text_false_expected.html b/verto/tests/assets/interactive-container/text_false_expected.html new file mode 100644 index 00000000..1e50edeb --- /dev/null +++ b/verto/tests/assets/interactive-container/text_false_expected.html @@ -0,0 +1 @@ +

    {interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="false"}

    diff --git a/verto/tests/assets/interactive-container/whole_page_parameters.md b/verto/tests/assets/interactive-container/whole_page_parameters.md index aa820f2d..af3e23c7 100644 --- a/verto/tests/assets/interactive-container/whole_page_parameters.md +++ b/verto/tests/assets/interactive-container/whole_page_parameters.md @@ -1 +1,5 @@ -{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="true"} + +Binary Cards Interactive + +{interactive end} diff --git a/verto/tests/assets/interactive-container/whole_page_thumbnail.md b/verto/tests/assets/interactive-container/whole_page_thumbnail.md index 4625c3a2..ab3f74a1 100644 --- a/verto/tests/assets/interactive-container/whole_page_thumbnail.md +++ b/verto/tests/assets/interactive-container/whole_page_thumbnail.md @@ -1 +1,5 @@ -{interactive slug="binary-cards" type="whole-page" thumbnail="interactives/binary-cards/img/binarycards.png"} +{interactive slug="binary-cards" type="whole-page" thumbnail="interactives/binary-cards/img/binarycards.png" text="true"} + +There is an indentation in the shape of you + +{interactive end} diff --git a/verto/tests/assets/interactive-container/whole_page_thumbnail_expected.html b/verto/tests/assets/interactive-container/whole_page_thumbnail_expected.html index 9ec659d6..263dd49c 100644 --- a/verto/tests/assets/interactive-container/whole_page_thumbnail_expected.html +++ b/verto/tests/assets/interactive-container/whole_page_thumbnail_expected.html @@ -1,6 +1,6 @@
    -Click to load binary-cards +There is an indentation in the shape of you
    diff --git a/verto/tests/assets/interactive-container/whole_page_thumbnail_parameters.md b/verto/tests/assets/interactive-container/whole_page_thumbnail_parameters.md index 33681e40..da9c0472 100644 --- a/verto/tests/assets/interactive-container/whole_page_thumbnail_parameters.md +++ b/verto/tests/assets/interactive-container/whole_page_thumbnail_parameters.md @@ -1 +1,7 @@ -{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png"} +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="true"} + +All of this silence and patience, pining and desperately waiting + +{interactive end} + +My hands are shaking from holding back from all this diff --git a/verto/tests/assets/interactive-container/whole_page_thumbnail_parameters_expected.html b/verto/tests/assets/interactive-container/whole_page_thumbnail_parameters_expected.html index f1b49c5e..e67a8d55 100644 --- a/verto/tests/assets/interactive-container/whole_page_thumbnail_parameters_expected.html +++ b/verto/tests/assets/interactive-container/whole_page_thumbnail_parameters_expected.html @@ -1,6 +1,6 @@
    -Click to load binary-cards +All of this silence and patience, pining and desperately waiting
    -
    +

    My hands are shaking from holding back from all this

    From 1ca8190122c612c6736211845160e5fcfd4c5be1 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 6 Aug 2018 12:24:21 +1200 Subject: [PATCH 61/73] more tests! --- verto/processor-info.json | 2 +- .../InteractiveContainerBlockProcessor.py | 4 +- verto/tests/InteractiveContainerTest.py | 67 ++++++++----------- .../{iframe_parameters.md => iframe.md} | 0 .../iframe_expected.html | 1 + .../iframe_parameters_expected.html | 3 - .../in_page_missing_name.md | 1 - .../in_page_missing_name_expected.html | 1 - .../multiple_interactives_text_true.md | 4 +- ...tiple_interactives_text_true_expected.html | 18 +++-- 10 files changed, 45 insertions(+), 56 deletions(-) rename verto/tests/assets/interactive-container/{iframe_parameters.md => iframe.md} (100%) create mode 100644 verto/tests/assets/interactive-container/iframe_expected.html delete mode 100644 verto/tests/assets/interactive-container/iframe_parameters_expected.html delete mode 100644 verto/tests/assets/interactive-container/in_page_missing_name.md delete mode 100644 verto/tests/assets/interactive-container/in_page_missing_name_expected.html diff --git a/verto/processor-info.json b/verto/processor-info.json index efa5f1e7..b40a72ec 100644 --- a/verto/processor-info.json +++ b/verto/processor-info.json @@ -367,7 +367,7 @@ "type": { "required": true, "dependencies": [], - "values": ["in-page", "whole-page", "iframe"] + "values": ["whole-page"] }, "text": { "required": true, diff --git a/verto/processors/InteractiveContainerBlockProcessor.py b/verto/processors/InteractiveContainerBlockProcessor.py index 98d0563f..2451f4f8 100644 --- a/verto/processors/InteractiveContainerBlockProcessor.py +++ b/verto/processors/InteractiveContainerBlockProcessor.py @@ -68,9 +68,7 @@ def custom_parsing(self, content_blocks, argument_values): # add to list of interactives self.required_interactives.add(slug) - if interactive_type == 'in-page': - self.scripts.add('interactive/{}/scripts.html'.format(slug)) - elif interactive_type == 'whole-page': + if interactive_type == 'whole-page': argument = 'thumbnail' thumbnail_file_path = argument_values.get(argument, None) diff --git a/verto/tests/InteractiveContainerTest.py b/verto/tests/InteractiveContainerTest.py index e32303ec..1ea5f1b7 100644 --- a/verto/tests/InteractiveContainerTest.py +++ b/verto/tests/InteractiveContainerTest.py @@ -93,13 +93,14 @@ def test_multiple_interactives_text_true(self): 'flying-boxes' }, 'images': { - 'binarycards.png' - }, - 'page_scripts': { - 'interactive/flying-boxes/scripts.html' + 'binarycards.png', + 'interactives/arrows/img/thumbnail.png', + 'interactives/flying-boxes/img/thumbnail.png' }, + 'page_scripts': set(), 'scratch_images': set() } + self.assertEqual(self.verto_extension.required_files, required_files) def test_contains_multiple_interactives_some_text(self): @@ -248,47 +249,35 @@ def test_whole_page_thumbnail_parameters(self): } self.assertEqual(self.verto_extension.required_files, required_files) - # def test_iframe_parameters(self): - # '''Test iframe interactive with parameters is correctly parsed. - # ''' - # test_string = self.read_test_file(self.processor_name, 'iframe_parameters.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'iframe_parameters_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # required_files = { - # 'interactives': { - # "binary-cards" - # }, - # 'images': set(), - # 'page_scripts': set(), - # 'scratch_images': set() - # } - # self.assertEqual(self.verto_extension.required_files, required_files) + def test_iframe_parameters(self): + '''Test iframe interactive is ignored. + ''' + test_string = self.read_test_file(self.processor_name, 'iframe.md') + blocks = self.to_blocks(test_string) - # def test_in_page_missing_name(self): - # '''Test ArgumentMissingError is raised when interactive name is not given. - # ''' - # test_string = self.read_test_file(self.processor_name, 'in_page_missing_name.md') - # blocks = self.to_blocks(test_string) + self.assertListEqual([False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'iframe_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) - # self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + required_files = { + 'interactives': set(), + 'images': set(), + 'page_scripts': set(), + 'scratch_images': set() + } + self.assertEqual(self.verto_extension.required_files, required_files) - # def test_missing_type(self): - # '''Test ArgumentMissingError is raised when interactive type is not given. - # ''' - # test_string = self.read_test_file(self.processor_name, 'missing_type.md') - # blocks = self.to_blocks(test_string) + def test_missing_type(self): + '''Test ArgumentMissingError is raised when interactive type is not given. + ''' + test_string = self.read_test_file(self.processor_name, 'missing_type.md') + blocks = self.to_blocks(test_string) - # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - # self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) # def test_invalid_type(self): # '''Test ArgumentValueError is raised when interactive type is not valid. diff --git a/verto/tests/assets/interactive-container/iframe_parameters.md b/verto/tests/assets/interactive-container/iframe.md similarity index 100% rename from verto/tests/assets/interactive-container/iframe_parameters.md rename to verto/tests/assets/interactive-container/iframe.md diff --git a/verto/tests/assets/interactive-container/iframe_expected.html b/verto/tests/assets/interactive-container/iframe_expected.html new file mode 100644 index 00000000..2647dcc9 --- /dev/null +++ b/verto/tests/assets/interactive-container/iframe_expected.html @@ -0,0 +1 @@ +

    {interactive slug="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"}

    diff --git a/verto/tests/assets/interactive-container/iframe_parameters_expected.html b/verto/tests/assets/interactive-container/iframe_parameters_expected.html deleted file mode 100644 index 25f235b0..00000000 --- a/verto/tests/assets/interactive-container/iframe_parameters_expected.html +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/verto/tests/assets/interactive-container/in_page_missing_name.md b/verto/tests/assets/interactive-container/in_page_missing_name.md deleted file mode 100644 index b7ddcbe1..00000000 --- a/verto/tests/assets/interactive-container/in_page_missing_name.md +++ /dev/null @@ -1 +0,0 @@ -{interactive type="in-page"} diff --git a/verto/tests/assets/interactive-container/in_page_missing_name_expected.html b/verto/tests/assets/interactive-container/in_page_missing_name_expected.html deleted file mode 100644 index 3bc4a667..00000000 --- a/verto/tests/assets/interactive-container/in_page_missing_name_expected.html +++ /dev/null @@ -1 +0,0 @@ -{% include 'interactive/binary-cards/index.html' %} diff --git a/verto/tests/assets/interactive-container/multiple_interactives_text_true.md b/verto/tests/assets/interactive-container/multiple_interactives_text_true.md index 4d7e8d8c..85b4e749 100644 --- a/verto/tests/assets/interactive-container/multiple_interactives_text_true.md +++ b/verto/tests/assets/interactive-container/multiple_interactives_text_true.md @@ -8,7 +8,7 @@ Swaying as the room burned down I'd hold you as the water rushes in -{interactive slug="arrows" text="true" type="iframe" parameters="digits=5&start=BBBBB"} +{interactive slug="arrows" text="true" type="whole-page" parameters="digits=5&start=BBBBB"} If I could dance with you again @@ -16,7 +16,7 @@ If I could dance with you again I'd kiss you as the lights went out -{interactive text="true" slug="flying-boxes" type="in-page"} +{interactive text="true" slug="flying-boxes" type="whole-page"} Swaying as the room burned down diff --git a/verto/tests/assets/interactive-container/multiple_interactives_text_true_expected.html b/verto/tests/assets/interactive-container/multiple_interactives_text_true_expected.html index 97d9eb1b..4f403584 100644 --- a/verto/tests/assets/interactive-container/multiple_interactives_text_true_expected.html +++ b/verto/tests/assets/interactive-container/multiple_interactives_text_true_expected.html @@ -5,9 +5,15 @@ Swaying as the room burned down

    I'd hold you as the water rushes in

    - -

    I'd kiss you as the lights went out

    -{% include 'interactive/flying-boxes/index.html' %} -

    I'd hold you as the water rushes in

    + + +
    +If I could dance with you again +
    +

    I'd kiss you as the lights went out

    + + +
    +Swaying as the room burned down +
    +

    I'd hold you as the water rushes in

    From 0a837b5b00234928a6df4e4db7c62f622f849cbc Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 7 Aug 2018 13:17:23 +1200 Subject: [PATCH 62/73] Completed tests for new interactive processor --- verto/processor-info.json | 1 + .../GenericContainerBlockProcessor.py | 1 - .../InteractiveTagBlockProcessor.py | 14 ++ verto/tests/ImageContainerTest.py | 1 - verto/tests/InteractiveContainerTest.py | 179 +++++++----------- verto/tests/InteractiveTagTest.py | 140 +------------- .../doc_example_iframe_usage.md | 1 - .../doc_example_iframe_usage_expected.html | 3 - .../doc_example_in_page_usage.md | 1 - .../doc_example_in_page_usage_expected.html | 1 - .../doc_example_override_html.md | 6 +- .../doc_example_override_thumbnail_html.md | 1 - ...mple_override_thumbnail_html_expected.html | 6 - ..._example_thumbnail_path_html_template.html | 3 - .../doc_example_whole_page_usage.md | 6 +- .../iframe_expected.html | 2 +- .../interactive-container/invalid_type.md | 6 +- .../interactive-container/missing_type.md | 6 +- .../doc_example_override_html.md | 2 +- .../doc_example_override_html_expected.html | 2 +- .../doc_example_override_html_template.html | 2 +- .../doc_example_whole_page_usage.md | 1 - ...doc_example_whole_page_usage_expected.html | 6 - .../whole_page_external_thumbnail.md | 1 - ...hole_page_external_thumbnail_expected.html | 6 - .../interactive-tag/whole_page_parameters.md | 1 - .../whole_page_parameters_expected.html | 6 - .../assets/interactive-tag/whole_page_text.md | 6 +- .../whole_page_text_expected.html | 9 +- .../interactive-tag/whole_page_thumbnail.md | 1 - .../whole_page_thumbnail_expected.html | 6 - .../whole_page_thumbnail_parameters.md | 1 - ...le_page_thumbnail_parameters_expected.html | 6 - verto/tests/start_tests.py | 50 ++--- 34 files changed, 148 insertions(+), 336 deletions(-) delete mode 100644 verto/tests/assets/interactive-container/doc_example_iframe_usage.md delete mode 100644 verto/tests/assets/interactive-container/doc_example_iframe_usage_expected.html delete mode 100644 verto/tests/assets/interactive-container/doc_example_in_page_usage.md delete mode 100644 verto/tests/assets/interactive-container/doc_example_in_page_usage_expected.html delete mode 100644 verto/tests/assets/interactive-container/doc_example_override_thumbnail_html.md delete mode 100644 verto/tests/assets/interactive-container/doc_example_override_thumbnail_html_expected.html delete mode 100644 verto/tests/assets/interactive-container/doc_example_thumbnail_path_html_template.html delete mode 100644 verto/tests/assets/interactive-tag/doc_example_whole_page_usage.md delete mode 100644 verto/tests/assets/interactive-tag/doc_example_whole_page_usage_expected.html delete mode 100644 verto/tests/assets/interactive-tag/whole_page_external_thumbnail.md delete mode 100644 verto/tests/assets/interactive-tag/whole_page_external_thumbnail_expected.html delete mode 100644 verto/tests/assets/interactive-tag/whole_page_parameters.md delete mode 100644 verto/tests/assets/interactive-tag/whole_page_parameters_expected.html delete mode 100644 verto/tests/assets/interactive-tag/whole_page_thumbnail.md delete mode 100644 verto/tests/assets/interactive-tag/whole_page_thumbnail_expected.html delete mode 100644 verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters.md delete mode 100644 verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters_expected.html diff --git a/verto/processor-info.json b/verto/processor-info.json index b40a72ec..ccc2f4fe 100644 --- a/verto/processor-info.json +++ b/verto/processor-info.json @@ -313,6 +313,7 @@ "interactive-tag": { "class": "custom", "tag_argument": "interactive", + "pattern": "(^|\\n) *\\{interactive (?P[^\\}]*)?(?Ptext=\"true\")(?P[^\\}]*)?\\} *(\\n|$)", "template_name": "interactive", "arguments": { "slug": { diff --git a/verto/processors/GenericContainerBlockProcessor.py b/verto/processors/GenericContainerBlockProcessor.py index 95ab1834..25247898 100644 --- a/verto/processors/GenericContainerBlockProcessor.py +++ b/verto/processors/GenericContainerBlockProcessor.py @@ -69,7 +69,6 @@ def run(self, parent, blocks): blocks.insert(0, after) argument_values = parse_arguments(self.processor, start_tag.group('args'), self.arguments) - print(argument_values) content_blocks = [] the_rest = '' diff --git a/verto/processors/InteractiveTagBlockProcessor.py b/verto/processors/InteractiveTagBlockProcessor.py index 7cb0afb0..e17fecc3 100644 --- a/verto/processors/InteractiveTagBlockProcessor.py +++ b/verto/processors/InteractiveTagBlockProcessor.py @@ -18,6 +18,20 @@ def __init__(self, ext, *args, **kwargs): self.scripts = ext.required_files['page_scripts'] self.required_interactives = ext.required_files['interactives'] self.required_images = ext.required_files['images'] + self.text_pattern = re.compile(ext.processor_info[self.processor]['pattern']) + + def test(self, parent, block): + ''' Tests a block to see if the run method should be applied. + + Args: + parent: The parent node of the element tree that children + will reside in. + block: The block to be tested. + + Returns: + True if there are any start or end tags within the block. + ''' + return self.text_pattern.search(block) is None and self.pattern.search(block) is not None def custom_parsing(self, argument_values): '''Determines the file path to use for an interactive's thumbnail. diff --git a/verto/tests/ImageContainerTest.py b/verto/tests/ImageContainerTest.py index f6db09d0..05922acd 100644 --- a/verto/tests/ImageContainerTest.py +++ b/verto/tests/ImageContainerTest.py @@ -6,7 +6,6 @@ from verto.processors.ImageContainerBlockProcessor import ImageContainerBlockProcessor from verto.errors.ImageMissingCaptionError import ImageMissingCaptionError from verto.errors.ImageCaptionContainsImageError import ImageCaptionContainsImageError -from verto.errors.ArgumentMissingError import ArgumentMissingError from verto.errors.ArgumentValueError import ArgumentValueError from verto.errors.TagNotMatchedError import TagNotMatchedError from verto.tests.ProcessorTest import ProcessorTest diff --git a/verto/tests/InteractiveContainerTest.py b/verto/tests/InteractiveContainerTest.py index 1ea5f1b7..d720d671 100644 --- a/verto/tests/InteractiveContainerTest.py +++ b/verto/tests/InteractiveContainerTest.py @@ -249,7 +249,7 @@ def test_whole_page_thumbnail_parameters(self): } self.assertEqual(self.verto_extension.required_files, required_files) - def test_iframe_parameters(self): + def test_iframe(self): '''Test iframe interactive is ignored. ''' test_string = self.read_test_file(self.processor_name, 'iframe.md') @@ -275,117 +275,72 @@ def test_missing_type(self): test_string = self.read_test_file(self.processor_name, 'missing_type.md') blocks = self.to_blocks(test_string) - self.assertListEqual([False], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([True, False, True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - # def test_invalid_type(self): - # '''Test ArgumentValueError is raised when interactive type is not valid. - # ''' - # test_string = self.read_test_file(self.processor_name, 'invalid_type.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) - - # #~ - # # Doc Tests - # #~ - - # def test_doc_example_in_page(self): - # '''Example of an in-page interactive. - # ''' - # test_string = self.read_test_file(self.processor_name, 'doc_example_in_page_usage.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'doc_example_in_page_usage_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # required_files = { - # 'interactives': { - # 'binary-cards' - # }, - # 'images': set(), - # 'page_scripts': { - # 'interactive/binary-cards/scripts.html' - # }, - # 'scratch_images': set() - # } - # self.assertEqual(self.verto_extension.required_files, required_files) - - # def test_doc_example_whole_page(self): - # '''Example of a whole-page interactive. - # ''' - # test_string = self.read_test_file(self.processor_name, 'doc_example_whole_page_usage.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'doc_example_whole_page_usage_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # required_files = { - # 'interactives': { - # "binary-cards" - # }, - # 'images': { - # 'interactives/binary-cards/img/thumbnail.png' - # }, - # 'page_scripts': set(), - # 'scratch_images': set() - # } - # self.assertEqual(self.verto_extension.required_files, required_files) - - # def test_doc_example_iframe(self): - # '''Example of an iframe interactive. - # ''' - # test_string = self.read_test_file(self.processor_name, 'doc_example_iframe_usage.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'doc_example_iframe_usage_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # required_files = { - # 'interactives': { - # 'binary-cards' - # }, - # 'images': set(), - # 'page_scripts': set(), - # 'scratch_images': set() - # } - # self.assertEqual(self.verto_extension.required_files, required_files) - - # def test_doc_example_override_html(self): - # '''Example showing overriding the html-template. - # ''' - # test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') - # blocks = self.to_blocks(test_string) - - # self.assertListEqual([True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - # html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) - # verto_extension = VertoExtension([self.processor_name], html_templates={self.processor_name: html_template}) - - # converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) - # expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) - # self.assertEqual(expected_string, converted_test_string) - - # required_files = { - # 'interactives': { - # 'binary-cards' - # }, - # 'images': { - # 'binarycards.png' - # }, - # 'page_scripts': set(), - # 'scratch_images': set() - # } - # self.assertEqual(verto_extension.required_files, required_files) + def test_invalid_type(self): + '''Test ArgumentValueError is raised when interactive type is not valid. + ''' + test_string = self.read_test_file(self.processor_name, 'invalid_type.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + self.assertRaises(ArgumentValueError, lambda x: markdown.markdown(x, extensions=[self.verto_extension]), test_string) + + # ~ + # Doc Tests + # ~ + + def test_doc_example_whole_page(self): + '''Example of a whole-page interactive. + ''' + test_string = self.read_test_file(self.processor_name, 'doc_example_whole_page_usage.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'doc_example_whole_page_usage_expected.html', strip=True) + self.assertEqual(expected_string, converted_test_string) + + required_files = { + 'interactives': { + "binary-cards" + }, + 'images': { + 'interactives/binary-cards/img/thumbnail.png' + }, + 'page_scripts': set(), + 'scratch_images': set() + } + self.assertEqual(self.verto_extension.required_files, required_files) + + def test_doc_example_override_html(self): + '''Example showing overriding the html-template. + ''' + test_string = self.read_test_file(self.processor_name, 'doc_example_override_html.md') + blocks = self.to_blocks(test_string) + + self.assertListEqual([True, False, True], [InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + + html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) + + converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) + expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) + + self.assertEqual(expected_string, converted_test_string) + + required_files = { + 'interactives': { + 'binary-cards' + }, + 'images': { + 'binarycards.png' + }, + 'page_scripts': set(), + 'scratch_images': set() + } + self.assertEqual(verto_extension.required_files, required_files) diff --git a/verto/tests/InteractiveTagTest.py b/verto/tests/InteractiveTagTest.py index b421a128..67930297 100644 --- a/verto/tests/InteractiveTagTest.py +++ b/verto/tests/InteractiveTagTest.py @@ -23,125 +23,27 @@ def __init__(self, *args, **kwargs): ''' ProcessorTest.__init__(self, *args, **kwargs) self.processor_name = 'interactive-tag' + self.tag_argument = 'interactive' self.ext = Mock() + self.ext.jinja_templates = {'interactive': ProcessorTest.loadJinjaTemplate(self, 'interactive')} self.ext.processor_info = ProcessorTest.loadProcessorInfo(self) - self.ext.jinja_templates = {self.processor_name: ProcessorTest.loadJinjaTemplate(self, self.processor_name)} self.ext.required_files = defaultdict(set) - def test_whole_page_external_thumbnail(self): - '''Test external image for image thumbnail. - ''' - test_string = self.read_test_file(self.processor_name, 'whole_page_external_thumbnail.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'whole_page_external_thumbnail_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - required_files = { - 'interactives': { - "binary-cards" - }, - 'images': set(), - 'page_scripts': set(), - 'scratch_images': set() - } - self.assertEqual(self.verto_extension.required_files, required_files) - def test_whole_page_text(self): - '''Test whole page interactive with text is correctly parsed. + '''Test whole page interactive with text is ignored. ''' test_string = self.read_test_file(self.processor_name, 'whole_page_text.md') blocks = self.to_blocks(test_string) - self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) + self.assertListEqual([False, False, False], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) expected_string = self.read_test_file(self.processor_name, 'whole_page_text_expected.html', strip=True) self.assertEqual(expected_string, converted_test_string) required_files = { - 'interactives': { - "binary-cards" - }, - 'images': { - 'interactives/binary-cards/img/thumbnail.png' - }, - 'page_scripts': set(), - 'scratch_images': set() - } - self.assertEqual(self.verto_extension.required_files, required_files) - - def test_whole_page_parameters(self): - '''Test whole page interactive with parameters is correctly parsed. - ''' - test_string = self.read_test_file(self.processor_name, 'whole_page_parameters.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'whole_page_parameters_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - required_files = { - 'interactives': { - "binary-cards" - }, - 'images': { - 'interactives/binary-cards/img/thumbnail.png' - }, - 'page_scripts': set(), - 'scratch_images': set() - } - self.assertEqual(self.verto_extension.required_files, required_files) - - def test_whole_page_thumbnail(self): - '''Test whole page interactive with thumbnail is correctly parsed and thumbnail path is added to required files. - ''' - test_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - required_files = { - 'interactives': { - "binary-cards" - }, - 'images': { - 'interactives/binary-cards/img/binarycards.png' - }, - 'page_scripts': set(), - 'scratch_images': set() - } - self.assertEqual(self.verto_extension.required_files, required_files) - - - def test_whole_page_thumbnail_parameters(self): - '''Test whole page interactive with thumbnail and parameters is correctly parsed and thumbnail path is added to required files. - ''' - test_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_parameters.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'whole_page_thumbnail_parameters_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - required_files = { - 'interactives': { - "binary-cards" - }, - 'images': { - 'binarycards.png' - }, + 'interactives': set(), + 'images': set(), 'page_scripts': set(), 'scratch_images': set() } @@ -227,9 +129,9 @@ def test_multiple_interactives(self): } self.assertEqual(self.verto_extension.required_files, required_files) - #~ + # ~ # Doc Tests - #~ + # ~ def test_doc_example_in_page(self): '''Example of an in-page interactive. @@ -255,30 +157,6 @@ def test_doc_example_in_page(self): } self.assertEqual(self.verto_extension.required_files, required_files) - def test_doc_example_whole_page(self): - '''Example of a whole-page interactive. - ''' - test_string = self.read_test_file(self.processor_name, 'doc_example_whole_page_usage.md') - blocks = self.to_blocks(test_string) - - self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) - - converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension]) - expected_string = self.read_test_file(self.processor_name, 'doc_example_whole_page_usage_expected.html', strip=True) - self.assertEqual(expected_string, converted_test_string) - - required_files = { - 'interactives': { - "binary-cards" - }, - 'images': { - 'interactives/binary-cards/img/thumbnail.png' - }, - 'page_scripts': set(), - 'scratch_images': set() - } - self.assertEqual(self.verto_extension.required_files, required_files) - def test_doc_example_iframe(self): '''Example of an iframe interactive. ''' @@ -310,7 +188,7 @@ def test_doc_example_override_html(self): self.assertListEqual([True], [InteractiveTagBlockProcessor(self.ext, self.md.parser).test(blocks, block) for block in blocks], msg='"{}"'.format(test_string)) html_template = self.read_test_file(self.processor_name, 'doc_example_override_html_template.html', strip=True) - verto_extension = VertoExtension([self.processor_name], html_templates={self.processor_name: html_template}) + verto_extension = VertoExtension([self.processor_name], html_templates={self.tag_argument: html_template}) converted_test_string = markdown.markdown(test_string, extensions=[verto_extension]) expected_string = self.read_test_file(self.processor_name, 'doc_example_override_html_expected.html', strip=True) diff --git a/verto/tests/assets/interactive-container/doc_example_iframe_usage.md b/verto/tests/assets/interactive-container/doc_example_iframe_usage.md deleted file mode 100644 index e06b0837..00000000 --- a/verto/tests/assets/interactive-container/doc_example_iframe_usage.md +++ /dev/null @@ -1 +0,0 @@ -{interactive slug="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"} diff --git a/verto/tests/assets/interactive-container/doc_example_iframe_usage_expected.html b/verto/tests/assets/interactive-container/doc_example_iframe_usage_expected.html deleted file mode 100644 index 25f235b0..00000000 --- a/verto/tests/assets/interactive-container/doc_example_iframe_usage_expected.html +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/verto/tests/assets/interactive-container/doc_example_in_page_usage.md b/verto/tests/assets/interactive-container/doc_example_in_page_usage.md deleted file mode 100644 index bc4f421a..00000000 --- a/verto/tests/assets/interactive-container/doc_example_in_page_usage.md +++ /dev/null @@ -1 +0,0 @@ -{interactive slug="binary-cards" type="in-page"} diff --git a/verto/tests/assets/interactive-container/doc_example_in_page_usage_expected.html b/verto/tests/assets/interactive-container/doc_example_in_page_usage_expected.html deleted file mode 100644 index 3bc4a667..00000000 --- a/verto/tests/assets/interactive-container/doc_example_in_page_usage_expected.html +++ /dev/null @@ -1 +0,0 @@ -{% include 'interactive/binary-cards/index.html' %} diff --git a/verto/tests/assets/interactive-container/doc_example_override_html.md b/verto/tests/assets/interactive-container/doc_example_override_html.md index 352b06ab..9355eb43 100644 --- a/verto/tests/assets/interactive-container/doc_example_override_html.md +++ b/verto/tests/assets/interactive-container/doc_example_override_html.md @@ -1 +1,5 @@ -{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="Binary Cards Interactive"} +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="true"} + +Binary Cards Interactive + +{interactive end} diff --git a/verto/tests/assets/interactive-container/doc_example_override_thumbnail_html.md b/verto/tests/assets/interactive-container/doc_example_override_thumbnail_html.md deleted file mode 100644 index 352b06ab..00000000 --- a/verto/tests/assets/interactive-container/doc_example_override_thumbnail_html.md +++ /dev/null @@ -1 +0,0 @@ -{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive-container/doc_example_override_thumbnail_html_expected.html b/verto/tests/assets/interactive-container/doc_example_override_thumbnail_html_expected.html deleted file mode 100644 index 3fe204ff..00000000 --- a/verto/tests/assets/interactive-container/doc_example_override_thumbnail_html_expected.html +++ /dev/null @@ -1,6 +0,0 @@ - - -
    -Binary Cards Interactive -
    -
    diff --git a/verto/tests/assets/interactive-container/doc_example_thumbnail_path_html_template.html b/verto/tests/assets/interactive-container/doc_example_thumbnail_path_html_template.html deleted file mode 100644 index 56d4c58a..00000000 --- a/verto/tests/assets/interactive-container/doc_example_thumbnail_path_html_template.html +++ /dev/null @@ -1,3 +0,0 @@ -{% autoescape false -%} -{{ "{% static '" }}interactives/{{ slug }}/img/{{ file_path }}{{ "' %}" }} -{%- endautoescape %} diff --git a/verto/tests/assets/interactive-container/doc_example_whole_page_usage.md b/verto/tests/assets/interactive-container/doc_example_whole_page_usage.md index aa820f2d..af3e23c7 100644 --- a/verto/tests/assets/interactive-container/doc_example_whole_page_usage.md +++ b/verto/tests/assets/interactive-container/doc_example_whole_page_usage.md @@ -1 +1,5 @@ -{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="true"} + +Binary Cards Interactive + +{interactive end} diff --git a/verto/tests/assets/interactive-container/iframe_expected.html b/verto/tests/assets/interactive-container/iframe_expected.html index 2647dcc9..daa8f4b3 100644 --- a/verto/tests/assets/interactive-container/iframe_expected.html +++ b/verto/tests/assets/interactive-container/iframe_expected.html @@ -1 +1 @@ -

    {interactive slug="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"}

    +

    {interactive slug="binary-cards" type="iframe" parameters="digits=5&start=BBBBB"}

    diff --git a/verto/tests/assets/interactive-container/invalid_type.md b/verto/tests/assets/interactive-container/invalid_type.md index 62b2d6d2..e4d783a2 100644 --- a/verto/tests/assets/interactive-container/invalid_type.md +++ b/verto/tests/assets/interactive-container/invalid_type.md @@ -1 +1,5 @@ -{interactive slug="binary-cards" type="not-a-real-type" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} +{interactive slug="binary-cards" type="not-a-real-type" parameters="digits=5&start=BBBBB" text="true"} + +Just like sand it slips through your hands + +{interactive end} diff --git a/verto/tests/assets/interactive-container/missing_type.md b/verto/tests/assets/interactive-container/missing_type.md index 7efd0ef9..6de7d3b0 100644 --- a/verto/tests/assets/interactive-container/missing_type.md +++ b/verto/tests/assets/interactive-container/missing_type.md @@ -1 +1,5 @@ -{interactive slug="binary-cards" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} +{interactive slug="binary-cards" parameters="digits=5&start=BBBBB" text="true"} + +And you're not invisibile + +{interactive end} diff --git a/verto/tests/assets/interactive-tag/doc_example_override_html.md b/verto/tests/assets/interactive-tag/doc_example_override_html.md index 352b06ab..33681e40 100644 --- a/verto/tests/assets/interactive-tag/doc_example_override_html.md +++ b/verto/tests/assets/interactive-tag/doc_example_override_html.md @@ -1 +1 @@ -{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="Binary Cards Interactive"} +{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png"} diff --git a/verto/tests/assets/interactive-tag/doc_example_override_html_expected.html b/verto/tests/assets/interactive-tag/doc_example_override_html_expected.html index fb071360..ae503f6b 100644 --- a/verto/tests/assets/interactive-tag/doc_example_override_html_expected.html +++ b/verto/tests/assets/interactive-tag/doc_example_override_html_expected.html @@ -1,5 +1,5 @@
    -Binary Cards Interactive +load binary-cards
    diff --git a/verto/tests/assets/interactive-tag/doc_example_override_html_template.html b/verto/tests/assets/interactive-tag/doc_example_override_html_template.html index 701edf7e..d711f3e9 100644 --- a/verto/tests/assets/interactive-tag/doc_example_override_html_template.html +++ b/verto/tests/assets/interactive-tag/doc_example_override_html_template.html @@ -14,7 +14,7 @@ {% if text -%} {{ text }} {% else -%} -Click to load {{ slug }} +load {{ slug }} {% endif -%}
    diff --git a/verto/tests/assets/interactive-tag/doc_example_whole_page_usage.md b/verto/tests/assets/interactive-tag/doc_example_whole_page_usage.md deleted file mode 100644 index aa820f2d..00000000 --- a/verto/tests/assets/interactive-tag/doc_example_whole_page_usage.md +++ /dev/null @@ -1 +0,0 @@ -{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive-tag/doc_example_whole_page_usage_expected.html b/verto/tests/assets/interactive-tag/doc_example_whole_page_usage_expected.html deleted file mode 100644 index fea9ee9c..00000000 --- a/verto/tests/assets/interactive-tag/doc_example_whole_page_usage_expected.html +++ /dev/null @@ -1,6 +0,0 @@ - - -
    -Binary Cards Interactive -
    -
    diff --git a/verto/tests/assets/interactive-tag/whole_page_external_thumbnail.md b/verto/tests/assets/interactive-tag/whole_page_external_thumbnail.md deleted file mode 100644 index 0dff9ad3..00000000 --- a/verto/tests/assets/interactive-tag/whole_page_external_thumbnail.md +++ /dev/null @@ -1 +0,0 @@ -{interactive slug="binary-cards" type="whole-page" thumbnail="http://totallylegit/filepath/foran/image.png"} diff --git a/verto/tests/assets/interactive-tag/whole_page_external_thumbnail_expected.html b/verto/tests/assets/interactive-tag/whole_page_external_thumbnail_expected.html deleted file mode 100644 index cb1677dc..00000000 --- a/verto/tests/assets/interactive-tag/whole_page_external_thumbnail_expected.html +++ /dev/null @@ -1,6 +0,0 @@ - - -
    -Click to load binary-cards -
    -
    diff --git a/verto/tests/assets/interactive-tag/whole_page_parameters.md b/verto/tests/assets/interactive-tag/whole_page_parameters.md deleted file mode 100644 index aa820f2d..00000000 --- a/verto/tests/assets/interactive-tag/whole_page_parameters.md +++ /dev/null @@ -1 +0,0 @@ -{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive-tag/whole_page_parameters_expected.html b/verto/tests/assets/interactive-tag/whole_page_parameters_expected.html deleted file mode 100644 index fea9ee9c..00000000 --- a/verto/tests/assets/interactive-tag/whole_page_parameters_expected.html +++ /dev/null @@ -1,6 +0,0 @@ - - -
    -Binary Cards Interactive -
    -
    diff --git a/verto/tests/assets/interactive-tag/whole_page_text.md b/verto/tests/assets/interactive-tag/whole_page_text.md index 396f316e..d4c6daf2 100644 --- a/verto/tests/assets/interactive-tag/whole_page_text.md +++ b/verto/tests/assets/interactive-tag/whole_page_text.md @@ -1 +1,5 @@ -{interactive slug="binary-cards" type="whole-page" text="Binary Cards Interactive"} +{interactive slug="binary-cards" type="whole-page" text="true"} + +Binary Cards Interactive + +{interactive end} diff --git a/verto/tests/assets/interactive-tag/whole_page_text_expected.html b/verto/tests/assets/interactive-tag/whole_page_text_expected.html index a259a370..d58577bb 100644 --- a/verto/tests/assets/interactive-tag/whole_page_text_expected.html +++ b/verto/tests/assets/interactive-tag/whole_page_text_expected.html @@ -1,6 +1,3 @@ - - -
    -Binary Cards Interactive -
    -
    +

    {interactive slug="binary-cards" type="whole-page" text="true"}

    +

    Binary Cards Interactive

    +

    {interactive end}

    diff --git a/verto/tests/assets/interactive-tag/whole_page_thumbnail.md b/verto/tests/assets/interactive-tag/whole_page_thumbnail.md deleted file mode 100644 index 4625c3a2..00000000 --- a/verto/tests/assets/interactive-tag/whole_page_thumbnail.md +++ /dev/null @@ -1 +0,0 @@ -{interactive slug="binary-cards" type="whole-page" thumbnail="interactives/binary-cards/img/binarycards.png"} diff --git a/verto/tests/assets/interactive-tag/whole_page_thumbnail_expected.html b/verto/tests/assets/interactive-tag/whole_page_thumbnail_expected.html deleted file mode 100644 index 9ec659d6..00000000 --- a/verto/tests/assets/interactive-tag/whole_page_thumbnail_expected.html +++ /dev/null @@ -1,6 +0,0 @@ - - -
    -Click to load binary-cards -
    -
    diff --git a/verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters.md b/verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters.md deleted file mode 100644 index 33681e40..00000000 --- a/verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters.md +++ /dev/null @@ -1 +0,0 @@ -{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png"} diff --git a/verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters_expected.html b/verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters_expected.html deleted file mode 100644 index f1b49c5e..00000000 --- a/verto/tests/assets/interactive-tag/whole_page_thumbnail_parameters_expected.html +++ /dev/null @@ -1,6 +0,0 @@ - - -
    -Click to load binary-cards -
    -
    diff --git a/verto/tests/start_tests.py b/verto/tests/start_tests.py index 972e94f6..40645002 100644 --- a/verto/tests/start_tests.py +++ b/verto/tests/start_tests.py @@ -86,32 +86,32 @@ def unit_suite(): '''Builds unittests. (Not really unittests). ''' return unittest.TestSuite(( - # unittest.makeSuite(BoxedTextTest), - # unittest.makeSuite(ButtonLinkTest), - # unittest.makeSuite(CommentTest), - # unittest.makeSuite(ConditionalTest), - # unittest.makeSuite(FrameTest), - # unittest.makeSuite(GlossaryLinkTest), - # unittest.makeSuite(HeadingTest), - # unittest.makeSuite(ImageInlineTest), - # unittest.makeSuite(ImageTagTest), - # unittest.makeSuite(ImageContainerTest), - # unittest.makeSuite(InteractiveTagTest), + unittest.makeSuite(BoxedTextTest), + unittest.makeSuite(ButtonLinkTest), + unittest.makeSuite(CommentTest), + unittest.makeSuite(ConditionalTest), + unittest.makeSuite(FrameTest), + unittest.makeSuite(GlossaryLinkTest), + unittest.makeSuite(HeadingTest), + unittest.makeSuite(ImageInlineTest), + unittest.makeSuite(ImageTagTest), + unittest.makeSuite(ImageContainerTest), + unittest.makeSuite(InteractiveTagTest), unittest.makeSuite(InteractiveContainerTest), - # unittest.makeSuite(JinjaTest), - # unittest.makeSuite(PanelTest), - # unittest.makeSuite(SaveTitleTest), - # unittest.makeSuite(ScratchTest), - # unittest.makeSuite(ScratchInlineTest), - # unittest.makeSuite(StyleTest), - # unittest.makeSuite(RelativeLinkTest), - # unittest.makeSuite(RemoveTest), - # unittest.makeSuite(RemoveTitleTest), - # unittest.makeSuite(TableOfContentsTest), - # unittest.makeSuite(VideoTest), - - # unittest.makeSuite(HtmlParserTest), - # unittest.makeSuite(MarkdownOverrideTest), + unittest.makeSuite(JinjaTest), + unittest.makeSuite(PanelTest), + unittest.makeSuite(SaveTitleTest), + unittest.makeSuite(ScratchTest), + unittest.makeSuite(ScratchInlineTest), + unittest.makeSuite(StyleTest), + unittest.makeSuite(RelativeLinkTest), + unittest.makeSuite(RemoveTest), + unittest.makeSuite(RemoveTitleTest), + unittest.makeSuite(TableOfContentsTest), + unittest.makeSuite(VideoTest), + + unittest.makeSuite(HtmlParserTest), + unittest.makeSuite(MarkdownOverrideTest), )) From 903f82885a60426475c5644d68abf9e7e1a114fe Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 7 Aug 2018 13:17:58 +1200 Subject: [PATCH 63/73] Added forgotten test files.... --- verto/tests/assets/image-container/missing_file_path.md | 5 +++++ verto/tests/assets/image-tag/missing_file_path.md | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 verto/tests/assets/image-container/missing_file_path.md create mode 100644 verto/tests/assets/image-tag/missing_file_path.md diff --git a/verto/tests/assets/image-container/missing_file_path.md b/verto/tests/assets/image-container/missing_file_path.md new file mode 100644 index 00000000..ec60d734 --- /dev/null +++ b/verto/tests/assets/image-container/missing_file_path.md @@ -0,0 +1,5 @@ +Some text before. + +{image caption="false" alignment="center"} + +Some text after. diff --git a/verto/tests/assets/image-tag/missing_file_path.md b/verto/tests/assets/image-tag/missing_file_path.md new file mode 100644 index 00000000..ec60d734 --- /dev/null +++ b/verto/tests/assets/image-tag/missing_file_path.md @@ -0,0 +1,5 @@ +Some text before. + +{image caption="false" alignment="center"} + +Some text after. From fa29d3047f2243df08eaa6b51118eb2bba1cde99 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 7 Aug 2018 13:24:59 +1200 Subject: [PATCH 64/73] Updated docs --- docs/source/processors/interactive.rst | 29 ++++++++++++++------------ 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/source/processors/interactive.rst b/docs/source/processors/interactive.rst index b6234ed2..c76f005e 100644 --- a/docs/source/processors/interactive.rst +++ b/docs/source/processors/interactive.rst @@ -18,7 +18,7 @@ interactive as requested. You can include an interactive using the following text tag: -.. literalinclude:: ../../../verto/tests/assets/interactive/doc_example_in_page_usage.md +.. literalinclude:: ../../../verto/tests/assets/interactive-tag/doc_example_in_page_usage.md :language: none Required Tag Parameters @@ -47,9 +47,12 @@ Required Tag Parameters Optional Tag Parameters *************************************** -- ``text`` (used with ``whole-page`` value) - Sets the text for the interactive - link. If no text is given, the link uses the text ``Click to load - {{ slug }}``. +- ``text`` - Boolean flag to indicate whether the interactive has custom text to dispaly. + + - If given as ``true``, the the subtitle is the first block of text with the interactive block. + - This is only use with the ``whole-page`` value + - If no text is given, the link uses the text ``Click to load {{ slug }}``. + - ``parameters`` (used with ``whole-page`` and ``iframe`` values) - Adds the parameters to interactive link. For example: ``digits=5&start=BBBBB``. @@ -90,36 +93,36 @@ Examples Using the following example tag: -.. literalinclude:: ../../../verto/tests/assets/interactive/doc_example_in_page_usage.md +.. literalinclude:: ../../../verto/tests/assets/interactive-tag/doc_example_in_page_usage.md :language: none The resulting HTML would be: -.. literalinclude:: ../../../verto/tests/assets/interactive/doc_example_in_page_usage_expected.html +.. literalinclude:: ../../../verto/tests/assets/interactive-tag/doc_example_in_page_usage_expected.html :language: html **whole-page example** Using the following example tag: -.. literalinclude:: ../../../verto/tests/assets/interactive/doc_example_whole_page_usage.md +.. literalinclude:: ../../../verto/tests/assets/interactive-container/doc_example_whole_page_usage.md :language: none The resulting HTML would be: -.. literalinclude:: ../../../verto/tests/assets/interactive/doc_example_whole_page_usage_expected.html +.. literalinclude:: ../../../verto/tests/assets/interactive-container/doc_example_whole_page_usage_expected.html :language: html **iframe example** Using the following example tag: -.. literalinclude:: ../../../verto/tests/assets/interactive/doc_example_iframe_usage.md +.. literalinclude:: ../../../verto/tests/assets/interactive-tag/doc_example_iframe_usage.md :language: none The resulting HTML would be: -.. literalinclude:: ../../../verto/tests/assets/interactive/doc_example_iframe_usage_expected.html +.. literalinclude:: ../../../verto/tests/assets/interactive-tag/doc_example_iframe_usage_expected.html :language: html Overriding HTML for Interactives @@ -142,17 +145,17 @@ thumbnail. For example, providing the following HTML: -.. literalinclude:: ../../../verto/tests/assets/interactive/doc_example_override_html_template.html +.. literalinclude:: ../../../verto/tests/assets/interactive-container/doc_example_override_html_template.html :language: css+jinja with the following tag: -.. literalinclude:: ../../../verto/tests/assets/interactive/doc_example_override_html.md +.. literalinclude:: ../../../verto/tests/assets/interactive-container/doc_example_override_html.md :language: none would result in: -.. literalinclude:: ../../../verto/tests/assets/interactive/doc_example_override_html_expected.html +.. literalinclude:: ../../../verto/tests/assets/interactive-container/doc_example_override_html_expected.html :language: html From 8284d05a27f1bf3167217718130bbfe061dfd029 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Tue, 7 Aug 2018 13:37:51 +1200 Subject: [PATCH 65/73] Removed unused test files --- verto/tests/assets/interactive-container/whole_page_text.md | 1 - .../interactive-container/whole_page_text_expected.html | 6 ------ .../interactive-tag/doc_example_override_thumbnail_html.md | 1 - .../doc_example_override_thumbnail_html_expected.html | 6 ------ .../doc_example_thumbnail_path_html_template.html | 3 --- 5 files changed, 17 deletions(-) delete mode 100644 verto/tests/assets/interactive-container/whole_page_text.md delete mode 100644 verto/tests/assets/interactive-container/whole_page_text_expected.html delete mode 100644 verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html.md delete mode 100644 verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html_expected.html delete mode 100644 verto/tests/assets/interactive-tag/doc_example_thumbnail_path_html_template.html diff --git a/verto/tests/assets/interactive-container/whole_page_text.md b/verto/tests/assets/interactive-container/whole_page_text.md deleted file mode 100644 index 396f316e..00000000 --- a/verto/tests/assets/interactive-container/whole_page_text.md +++ /dev/null @@ -1 +0,0 @@ -{interactive slug="binary-cards" type="whole-page" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive-container/whole_page_text_expected.html b/verto/tests/assets/interactive-container/whole_page_text_expected.html deleted file mode 100644 index a259a370..00000000 --- a/verto/tests/assets/interactive-container/whole_page_text_expected.html +++ /dev/null @@ -1,6 +0,0 @@ - - -
    -Binary Cards Interactive -
    -
    diff --git a/verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html.md b/verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html.md deleted file mode 100644 index 352b06ab..00000000 --- a/verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html.md +++ /dev/null @@ -1 +0,0 @@ -{interactive slug="binary-cards" type="whole-page" parameters="digits=5&start=BBBBB" thumbnail="binarycards.png" text="Binary Cards Interactive"} diff --git a/verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html_expected.html b/verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html_expected.html deleted file mode 100644 index 3fe204ff..00000000 --- a/verto/tests/assets/interactive-tag/doc_example_override_thumbnail_html_expected.html +++ /dev/null @@ -1,6 +0,0 @@ - - -
    -Binary Cards Interactive -
    -
    diff --git a/verto/tests/assets/interactive-tag/doc_example_thumbnail_path_html_template.html b/verto/tests/assets/interactive-tag/doc_example_thumbnail_path_html_template.html deleted file mode 100644 index 56d4c58a..00000000 --- a/verto/tests/assets/interactive-tag/doc_example_thumbnail_path_html_template.html +++ /dev/null @@ -1,3 +0,0 @@ -{% autoescape false -%} -{{ "{% static '" }}interactives/{{ slug }}/img/{{ file_path }}{{ "' %}" }} -{%- endautoescape %} From 3ebca6dd03f20f6a424268b378e2fb6610cb5226 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Sun, 12 Aug 2018 20:09:09 +1200 Subject: [PATCH 66/73] converted custom argument rule tests to strings rather than json files --- verto/tests/BoxedTextTest.py | 41 ++++++++++++++++++++---------- verto/tests/ButtonLinkTest.py | 39 ++++++++++++++++++---------- verto/tests/FrameTest.py | 10 ++++---- verto/tests/GlossaryLinkTest.py | 10 ++++---- verto/tests/ImageContainerTest.py | 33 ++++++++++++++++-------- verto/tests/ImageInlineTest.py | 33 ++++++++++++++++-------- verto/tests/ImageTagTest.py | 33 ++++++++++++++++-------- verto/tests/InteractiveTest.py | 40 +++++++++++++++++++---------- verto/tests/PanelTest.py | 32 ++++++++++++++--------- verto/tests/RelativeLinkTest.py | 3 +-- verto/tests/RemoveTitleTest.py | 1 + verto/tests/ScratchInlineTest.py | 4 +-- verto/tests/ScratchTest.py | 10 ++++---- verto/tests/TableOfContentsTest.py | 5 ++-- verto/tests/VideoTest.py | 10 ++++---- 15 files changed, 193 insertions(+), 111 deletions(-) diff --git a/verto/tests/BoxedTextTest.py b/verto/tests/BoxedTextTest.py index c7f33163..258afebc 100644 --- a/verto/tests/BoxedTextTest.py +++ b/verto/tests/BoxedTextTest.py @@ -1,8 +1,5 @@ import markdown from unittest.mock import Mock -from collections import OrderedDict -import json -import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.GenericContainerBlockProcessor import GenericContainerBlockProcessor @@ -126,8 +123,12 @@ def test_indented_value_no(self): def test_custom_arguments_indented_required(self): '''Tests to ensure that boxed text tag is rendered correctly when indented argument is required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/indented_required_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "boxed-text": { + "indented": True + } + } + verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -145,8 +146,11 @@ def test_custom_arguments_indented_required(self): def test_custom_arguments_type_required(self): '''Tests to ensure that boxed text tag is rendered correctly when type argument is required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/type_required_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "boxed-text": { + "type": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -164,8 +168,12 @@ def test_custom_arguments_type_required(self): def test_custom_arguments_indented_and_type_required(self): '''Tests to ensure that boxed text tag is rendered correctly when both indented and type arguments are required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/indented_and_type_required_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "boxed-text": { + "indented": True, + "type": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -183,8 +191,11 @@ def test_custom_arguments_indented_and_type_required(self): def test_custom_arguments_indented_required_not_provided(self): '''Tests to ensure that error is raised when indented argument is required and not given. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/indented_required_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "boxed-text": { + "indented": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -200,8 +211,12 @@ def test_custom_arguments_indented_required_not_provided(self): def test_custom_arguments_indented_and_type_required_type_not_provided(self): '''Tests to ensure that error is raised when indented and type arguments are required and type is not given. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/boxed-text/indented_and_type_required_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "boxed-text": { + "indented": True, + "type": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules diff --git a/verto/tests/ButtonLinkTest.py b/verto/tests/ButtonLinkTest.py index 71e936ba..dd465541 100644 --- a/verto/tests/ButtonLinkTest.py +++ b/verto/tests/ButtonLinkTest.py @@ -1,8 +1,5 @@ import markdown from unittest.mock import Mock -from collections import OrderedDict -import json -import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.GenericTagBlockProcessor import GenericTagBlockProcessor @@ -91,8 +88,11 @@ def test_contains_file_link_button(self): def test_custom_arguments_link_false(self): '''Tests to ensure that button link tag is rendered correctly when link argument is required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/link_false_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "button-link": { + "link": False + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -110,8 +110,11 @@ def test_custom_arguments_link_false(self): def test_custom_arguments_text_false(self): '''Tests to ensure that button link tag is rendered correctly when text argument is false. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/text_false_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "button-link": { + "text": False + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -129,8 +132,11 @@ def test_custom_arguments_text_false(self): def test_custom_arguments_file_true(self): '''Tests to ensure that button link tag is rendered correctly when file argument is true. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/file_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "button-link": { + "file": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -148,8 +154,12 @@ def test_custom_arguments_file_true(self): def test_custom_arguments_text_false_file_true(self): '''Tests to ensure that button link tag is rendered correctly when text argument is false and file argument is true. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/text_false_file_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "button-link": { + "file": True, + "text": False + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -167,8 +177,11 @@ def test_custom_arguments_text_false_file_true(self): def test_custom_arguments_file_true_not_provided(self): '''Tests to ensure that error is raised when file argument is required and not given. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/button-link/file_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "button-link": { + "file": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules diff --git a/verto/tests/FrameTest.py b/verto/tests/FrameTest.py index 256337fe..68aa2839 100644 --- a/verto/tests/FrameTest.py +++ b/verto/tests/FrameTest.py @@ -1,8 +1,5 @@ import markdown from unittest.mock import Mock -from collections import OrderedDict -import json -import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.GenericTagBlockProcessor import GenericTagBlockProcessor @@ -54,8 +51,11 @@ def test_example_single_quote_argument_error(self): def test_custom_argument_rules_link_false(self): '''Tests to ensure that iframe tag is rendered correctly when link argument is not required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/iframe/link_false_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "iframe": { + "link": False + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules diff --git a/verto/tests/GlossaryLinkTest.py b/verto/tests/GlossaryLinkTest.py index cb56c7e7..0e1100a9 100644 --- a/verto/tests/GlossaryLinkTest.py +++ b/verto/tests/GlossaryLinkTest.py @@ -1,9 +1,6 @@ import markdown import re from unittest.mock import Mock -from collections import OrderedDict -import json -import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.GlossaryLinkPattern import GlossaryLinkPattern @@ -201,8 +198,11 @@ def test_custom_arguments_reference_text_true(self): def test_custom_arguments_reference_text_true_not_provided(self): '''Tests to ensure that correct error is raised when reference text is required and not provided. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/glossary-link/reference_text_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "glossary-link": { + "reference-text": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules diff --git a/verto/tests/ImageContainerTest.py b/verto/tests/ImageContainerTest.py index bd792c0a..5f829a9b 100644 --- a/verto/tests/ImageContainerTest.py +++ b/verto/tests/ImageContainerTest.py @@ -1,8 +1,6 @@ import markdown from unittest.mock import Mock -from collections import defaultdict, OrderedDict -import json -import pkg_resources +from collections import defaultdict from verto.VertoExtension import VertoExtension from verto.processors.ImageContainerBlockProcessor import ImageContainerBlockProcessor @@ -453,8 +451,11 @@ def test_image_width_value_external_image(self): def test_custom_arguments_alt_false(self): '''Tests to ensure that image tag is rendered correctly when alt tag is not required and expected images are updated. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/alt_false_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "image-container": { + "alt": False + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -478,8 +479,11 @@ def test_custom_arguments_alt_false(self): def test_custom_arguments_hover_true(self): '''Tests to ensure that image tag is rendered correctly when hover argument is required and expected images are updated. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/hover_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "image-container": { + "hover-text": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -503,8 +507,12 @@ def test_custom_arguments_hover_true(self): def test_custom_arguments_alt_false_source_true(self): '''Tests to ensure that image tag is rendered correctly when alt argument is not required and source argument is true and expected images are updated. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/alt_false_source_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "image-container": { + "alt": False, + "source": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -528,8 +536,11 @@ def test_custom_arguments_alt_false_source_true(self): def test_custom_arguments_hover_true_not_provided(self): '''Tests to ensure that correct error is raised when hover text is required and not provided. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-container/hover_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "image-container": { + "hover-text": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules diff --git a/verto/tests/ImageInlineTest.py b/verto/tests/ImageInlineTest.py index 83306c2c..0a2a7591 100644 --- a/verto/tests/ImageInlineTest.py +++ b/verto/tests/ImageInlineTest.py @@ -1,9 +1,7 @@ import markdown import re from unittest.mock import Mock -from collections import defaultdict, OrderedDict -import json -import pkg_resources +from collections import defaultdict from verto.VertoExtension import VertoExtension from verto.processors.ImageInlinePattern import ImageInlinePattern @@ -326,8 +324,11 @@ def test_table_embed(self): def test_custom_arguments_alt_false(self): '''Tests to ensure that image tag is rendered correctly when alt tag is not required and expected images are updated. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-inline/alt_false_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "image-inline": { + "alt": False + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -350,8 +351,11 @@ def test_custom_arguments_alt_false(self): def test_custom_arguments_hover_true(self): '''Tests to ensure that image tag is rendered correctly when hover argument is required and expected images are updated. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-inline/hover_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "image-inline": { + "hover-text": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -374,8 +378,12 @@ def test_custom_arguments_hover_true(self): def test_custom_arguments_alt_false_source_true(self): '''Tests to ensure that image tag is rendered correctly when alt argument is not required and source argument is required and expected images are updated. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-inline/alt_false_source_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "image-inline": { + "alt": False, + "source": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -398,8 +406,11 @@ def test_custom_arguments_alt_false_source_true(self): def test_custom_arguments_hover_true_not_provided(self): '''Tests to ensure that correct error is raised when hover text is required and not provided. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-inline/hover_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "image-inline": { + "hover-text": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules diff --git a/verto/tests/ImageTagTest.py b/verto/tests/ImageTagTest.py index ff4e850e..ae01e45f 100644 --- a/verto/tests/ImageTagTest.py +++ b/verto/tests/ImageTagTest.py @@ -1,8 +1,6 @@ import markdown from unittest.mock import Mock -from collections import defaultdict, OrderedDict -import json -import pkg_resources +from collections import defaultdict from verto.VertoExtension import VertoExtension from verto.processors.ImageTagBlockProcessor import ImageTagBlockProcessor @@ -394,8 +392,11 @@ def test_image_width_value_external_image(self): def test_custom_arguments_alt_false(self): '''Tests to ensure that image tag is rendered correctly when alt tag is not required and expected images are updated. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-tag/alt_false_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "image-tag": { + "alt": False + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -419,8 +420,11 @@ def test_custom_arguments_alt_false(self): def test_custom_arguments_hover_true(self): '''Tests to ensure that image tag is rendered correctly when hover argument is required and expected images are updated. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-tag/hover_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "image-tag": { + "hover-text": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -444,8 +448,12 @@ def test_custom_arguments_hover_true(self): def test_custom_arguments_alt_false_source_true(self): '''Tests to ensure that image tag is rendered correctly when alt argument is not required and source argument is required and expected images are updated. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-tag/alt_false_source_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "image-tag": { + "alt": False, + "source": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -470,8 +478,11 @@ def test_custom_arguments_alt_false_source_true(self): def test_custom_arguments_hover_true_not_provided(self): '''Tests to ensure that correct error is raised when hover text is required and not provided. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/image-tag/hover_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "image-tag": { + "hover-text": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules diff --git a/verto/tests/InteractiveTest.py b/verto/tests/InteractiveTest.py index 19040510..fe1603ff 100644 --- a/verto/tests/InteractiveTest.py +++ b/verto/tests/InteractiveTest.py @@ -1,8 +1,6 @@ import markdown from unittest.mock import Mock -from collections import defaultdict, OrderedDict -import json -import pkg_resources +from collections import defaultdict from verto.VertoExtension import VertoExtension from verto.processors.InteractiveBlockProcessor import InteractiveBlockProcessor @@ -231,8 +229,11 @@ def test_multiple_interactives(self): def test_custom_arguments_text_true(self): '''Tests to ensure that interactive tag is rendered correctly when text argument is not required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/text_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "interactive": { + "text": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -250,8 +251,11 @@ def test_custom_arguments_text_true(self): def test_custom_arguments_parameters_true(self): '''Tests to ensure that interactive tag is rendered correctly when parameters argument is not required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/parameters_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "interactive": { + "parameters": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -269,8 +273,11 @@ def test_custom_arguments_parameters_true(self): def test_custom_arguments_thumbnail_true(self): '''Tests to ensure that interactive tag is rendered correctly when thumbnail argument is not required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/thumbnail_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "interactive": { + "thumbnail": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -288,8 +295,11 @@ def test_custom_arguments_thumbnail_true(self): def test_custom_arguments_text_true_not_provided(self): '''Tests to ensure that correct error is raised when text is required and not provided. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/text_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "interactive": { + "text": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -305,8 +315,12 @@ def test_custom_arguments_text_true_not_provided(self): def test_custom_arguments_text_and_thumbnail_true(self): '''Tests to ensure that interactive tag is rendered correctly when text and thumbnail arguments are required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/interactive/text_and_thumbnail_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "interactive": { + "text": True, + "thumbnail": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules diff --git a/verto/tests/PanelTest.py b/verto/tests/PanelTest.py index 74126bda..4151d02b 100644 --- a/verto/tests/PanelTest.py +++ b/verto/tests/PanelTest.py @@ -1,8 +1,5 @@ import markdown from unittest.mock import Mock -from collections import OrderedDict -import json -import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.PanelBlockProcessor import PanelBlockProcessor @@ -374,8 +371,11 @@ def test_panel_block_missing_whitespace(self): def test_custom_arguments_type_false(self): '''Tests to ensure that panel tag is rendered correctly when type argument is not required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/panel/type_false_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "panel": { + "type": False + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -393,8 +393,11 @@ def test_custom_arguments_type_false(self): def test_custom_arguments_subtitle_true(self): '''Tests to ensure that panel tag is rendered correctly when subtitle argument is required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/panel/subtitle_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "panel": { + "subtitle": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -412,8 +415,11 @@ def test_custom_arguments_subtitle_true(self): def test_custom_arguments_expanded_true(self): '''Tests to ensure that panel tag is rendered correctly when expanded argument is required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/panel/expanded_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "panel": { + "expanded": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -431,8 +437,11 @@ def test_custom_arguments_expanded_true(self): def test_custom_arguments_subtitle_true_not_provided(self): '''Tests to ensure that correct error is raised when subtitle is required and not provided. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/panel/subtitle_true_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "panel": { + "subtitle": True + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules @@ -445,7 +454,6 @@ def test_custom_arguments_subtitle_true_not_provided(self): self.assertRaises(ArgumentMissingError, lambda x: markdown.markdown(x, extensions=[verto_extension_custom_rules]), test_string) - # ~ # Doc Tests # ~ diff --git a/verto/tests/RelativeLinkTest.py b/verto/tests/RelativeLinkTest.py index ae9694e8..2811f1c4 100644 --- a/verto/tests/RelativeLinkTest.py +++ b/verto/tests/RelativeLinkTest.py @@ -1,10 +1,10 @@ import markdown import re from unittest.mock import Mock -from verto.VertoExtension import VertoExtension from verto.processors.RelativeLinkPattern import RelativeLinkPattern from verto.tests.ProcessorTest import ProcessorTest + class RelativeLinkTest(ProcessorTest): '''Tests to check the 'relative-link' pattern works as intended. This class is unique to other processors as it overrides @@ -216,7 +216,6 @@ def test_mailto_text(self): expected_string = self.read_test_file(self.processor_name, 'mailto_text_expected.html', strip=True).strip() self.assertEqual(expected_string, converted_test_string) - def test_ignore_news_schema(self): '''Tests that non-relative links are not matched. ''' diff --git a/verto/tests/RemoveTitleTest.py b/verto/tests/RemoveTitleTest.py index 8cc5eef0..248b2e11 100644 --- a/verto/tests/RemoveTitleTest.py +++ b/verto/tests/RemoveTitleTest.py @@ -4,6 +4,7 @@ from verto.processors.RemoveTitlePreprocessor import RemoveTitlePreprocessor from verto.tests.ProcessorTest import ProcessorTest + class RemoveTitleTest(ProcessorTest): '''Tests to check the 'remove-title' preprocesser works as intended. ''' diff --git a/verto/tests/ScratchInlineTest.py b/verto/tests/ScratchInlineTest.py index 3b5e3256..d5270fed 100644 --- a/verto/tests/ScratchInlineTest.py +++ b/verto/tests/ScratchInlineTest.py @@ -1,12 +1,10 @@ import markdown -from unittest.mock import Mock -from collections import defaultdict from verto.VertoExtension import VertoExtension from verto.processors.ScratchTreeprocessor import ScratchImageMetaData -from verto.processors.ScratchInlineTreeprocessor import ScratchInlineTreeprocessor from verto.tests.ProcessorTest import ProcessorTest + class ScratchInlineTest(ProcessorTest): '''Scratch blocks are unique in that they override behaviour in markdown. ''' diff --git a/verto/tests/ScratchTest.py b/verto/tests/ScratchTest.py index 27c35746..68e9feb5 100644 --- a/verto/tests/ScratchTest.py +++ b/verto/tests/ScratchTest.py @@ -1,11 +1,10 @@ import markdown -from unittest.mock import Mock -from collections import defaultdict from verto.VertoExtension import VertoExtension -from verto.processors.ScratchTreeprocessor import ScratchTreeprocessor, ScratchImageMetaData +from verto.processors.ScratchTreeprocessor import ScratchImageMetaData from verto.tests.ProcessorTest import ProcessorTest + class ScratchTest(ProcessorTest): '''Scratch blocks are unique in that they override behaviour in markdown and behaviour in markdown extensions, while also retaining @@ -23,9 +22,10 @@ def setUp(self): ''' self.verto_extension = VertoExtension([self.processor_name], {}, ['markdown.extensions.fenced_code']) - #~ + # ~ # Doc Tests - #~ + # ~ + def test_doc_example_basic(self): '''An example of common useage. ''' diff --git a/verto/tests/TableOfContentsTest.py b/verto/tests/TableOfContentsTest.py index 08fd50a1..e7edf4a9 100644 --- a/verto/tests/TableOfContentsTest.py +++ b/verto/tests/TableOfContentsTest.py @@ -23,9 +23,10 @@ def __init__(self, *args, **kwargs): self.ext.jinja_templates = {self.processor_name: ProcessorTest.loadJinjaTemplate(self, self.processor_name)} self.block_processor = GenericTagBlockProcessor(self.processor_name, self.ext, Mock()) - #~ + # ~ # Doc Tests - #~ + # ~ + def test_doc_example_basic(self): '''A generic example of common usage. ''' diff --git a/verto/tests/VideoTest.py b/verto/tests/VideoTest.py index 955d1867..33827513 100644 --- a/verto/tests/VideoTest.py +++ b/verto/tests/VideoTest.py @@ -1,8 +1,5 @@ import markdown from unittest.mock import Mock -from collections import OrderedDict -import json -import pkg_resources from verto.VertoExtension import VertoExtension from verto.processors.VideoBlockProcessor import VideoBlockProcessor @@ -179,8 +176,11 @@ def test_contains_multiple_videos(self): def test_url_false_custom_argument_rules(self): '''Tests to ensure that video tag is rendered correctly when url argument is not required. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/video/url_false_custom_argument_rules.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "video": { + "url": False + } + } verto_extension_custom_rules = VertoExtension( processors=[self.processor_name], custom_argument_rules=custom_argument_rules From fc2dee57578dcad1e272b9b3c3a43a9e8cf7855d Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Sun, 12 Aug 2018 20:26:27 +1200 Subject: [PATCH 67/73] removing unused test files --- verto/tests/ConfigurationTest.py | 33 ++++++++++++++----- ...d_type_required_custom_argument_rules.json | 6 ---- ...dented_required_custom_argument_rules.json | 5 --- .../type_required_custom_argument_rules.json | 5 --- .../file_true_custom_argument_rules.json | 5 --- .../link_false_custom_argument_rules.json | 5 --- .../text_false_custom_argument_rules.json | 5 --- ...false_file_true_custom_argument_rules.json | 6 ---- .../custom_argument_rules_image_panel.json | 8 ----- ...om_argument_rules_incorrect_processor.json | 8 ----- ...nt_rules_incorrect_processor_argument.json | 8 ----- ...rence_text_true_custom_argument_rules.json | 5 --- .../link_false_custom_argument_rules.json | 5 --- .../alt_false_custom_argument_rules.json | 5 --- ...lse_source_true_custom_argument_rules.json | 6 ---- .../hover_true_custom_argument_rules.json | 5 --- .../alt_false_custom_argument_rules.json | 5 --- ...lse_source_true_custom_argument_rules.json | 6 ---- .../hover_true_custom_argument_rules.json | 5 --- .../alt_false_custom_argument_rules.json | 5 --- ...lse_source_true_custom_argument_rules.json | 6 ---- .../hover_true_custom_argument_rules.json | 5 --- ...parameters_true_custom_argument_rules.json | 5 --- ..._thumbnail_true_custom_argument_rules.json | 6 ---- .../text_true_custom_argument_rules.json | 5 --- .../thumbnail_true_custom_argument_rules.json | 5 --- .../expanded_true_custom_argument_rules.json | 5 --- .../subtitle_true_custom_argument_rules.json | 5 --- .../type_false_custom_argument_rules.json | 5 --- .../url_false_custom_argument_rules.json | 5 --- 30 files changed, 24 insertions(+), 169 deletions(-) delete mode 100644 verto/tests/assets/boxed-text/indented_and_type_required_custom_argument_rules.json delete mode 100644 verto/tests/assets/boxed-text/indented_required_custom_argument_rules.json delete mode 100644 verto/tests/assets/boxed-text/type_required_custom_argument_rules.json delete mode 100644 verto/tests/assets/button-link/file_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/button-link/link_false_custom_argument_rules.json delete mode 100644 verto/tests/assets/button-link/text_false_custom_argument_rules.json delete mode 100644 verto/tests/assets/button-link/text_false_file_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/configuration/custom_argument_rules_image_panel.json delete mode 100644 verto/tests/assets/configuration/custom_argument_rules_incorrect_processor.json delete mode 100644 verto/tests/assets/configuration/custom_argument_rules_incorrect_processor_argument.json delete mode 100644 verto/tests/assets/glossary-link/reference_text_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/iframe/link_false_custom_argument_rules.json delete mode 100644 verto/tests/assets/image-container/alt_false_custom_argument_rules.json delete mode 100644 verto/tests/assets/image-container/alt_false_source_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/image-container/hover_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/image-inline/alt_false_custom_argument_rules.json delete mode 100644 verto/tests/assets/image-inline/alt_false_source_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/image-inline/hover_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/image-tag/alt_false_custom_argument_rules.json delete mode 100644 verto/tests/assets/image-tag/alt_false_source_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/image-tag/hover_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/interactive/parameters_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/interactive/text_and_thumbnail_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/interactive/text_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/interactive/thumbnail_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/panel/expanded_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/panel/subtitle_true_custom_argument_rules.json delete mode 100644 verto/tests/assets/panel/type_false_custom_argument_rules.json delete mode 100644 verto/tests/assets/video/url_false_custom_argument_rules.json diff --git a/verto/tests/ConfigurationTest.py b/verto/tests/ConfigurationTest.py index d3213f8e..e5b7639a 100644 --- a/verto/tests/ConfigurationTest.py +++ b/verto/tests/ConfigurationTest.py @@ -1,7 +1,4 @@ import markdown -from collections import OrderedDict -import json -import pkg_resources from verto.Verto import Verto, VertoResult from verto.VertoExtension import VertoExtension @@ -401,8 +398,14 @@ def test_custom_argument_rules_for_multiple_tags(self): def test_custom_argument_rules_for_multiple_tags_error(self): '''Checks that error is raised when a tag's custom argument rules are not followed. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/configuration/custom_argument_rules_image_panel.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "panel": { + "subtitle": True + }, + "image-tag": { + "alt": False + } + } processors = {'image-tag', 'panel', 'comment'} verto = VertoExtension(processors=processors, custom_argument_rules=custom_argument_rules) @@ -412,8 +415,14 @@ def test_custom_argument_rules_for_multiple_tags_error(self): def test_custom_argument_rules_incorrect_processor_error(self): '''Checks that error is raised when a processor given in custom argument rules does not exist. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/configuration/custom_argument_rules_incorrect_processor.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "panel": { + "totallyrealargument": True + }, + "image-tag": { + "alt": False + } + } processors = {'image-tag', 'panel', 'comment'} self.assertRaises(CustomArgumentRulesError, lambda: VertoExtension(processors=processors, custom_argument_rules=custom_argument_rules)) @@ -421,8 +430,14 @@ def test_custom_argument_rules_incorrect_processor_error(self): def test_custom_argument_rules_incorrect_processor_argument_error(self): '''Checks that error is raised when a processor given in custom argument rules does not exist. ''' - json_data = pkg_resources.resource_string('verto', 'tests/assets/configuration/custom_argument_rules_incorrect_processor_argument.json').decode('utf-8') - custom_argument_rules = json.loads(json_data, object_pairs_hook=OrderedDict) + custom_argument_rules = { + "panl": { + "subtitle": True + }, + "image-tag": { + "alt": False + } + } processors = {'image-tag', 'panel', 'comment'} self.assertRaises(CustomArgumentRulesError, lambda: VertoExtension(processors=processors, custom_argument_rules=custom_argument_rules)) diff --git a/verto/tests/assets/boxed-text/indented_and_type_required_custom_argument_rules.json b/verto/tests/assets/boxed-text/indented_and_type_required_custom_argument_rules.json deleted file mode 100644 index 53f47286..00000000 --- a/verto/tests/assets/boxed-text/indented_and_type_required_custom_argument_rules.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "boxed-text": { - "indented": true, - "type": true - } -} diff --git a/verto/tests/assets/boxed-text/indented_required_custom_argument_rules.json b/verto/tests/assets/boxed-text/indented_required_custom_argument_rules.json deleted file mode 100644 index d8e93e7f..00000000 --- a/verto/tests/assets/boxed-text/indented_required_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "boxed-text": { - "indented": true - } -} diff --git a/verto/tests/assets/boxed-text/type_required_custom_argument_rules.json b/verto/tests/assets/boxed-text/type_required_custom_argument_rules.json deleted file mode 100644 index 29e51f83..00000000 --- a/verto/tests/assets/boxed-text/type_required_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "boxed-text": { - "type": true - } -} diff --git a/verto/tests/assets/button-link/file_true_custom_argument_rules.json b/verto/tests/assets/button-link/file_true_custom_argument_rules.json deleted file mode 100644 index 78238e78..00000000 --- a/verto/tests/assets/button-link/file_true_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "button-link": { - "file": true - } -} diff --git a/verto/tests/assets/button-link/link_false_custom_argument_rules.json b/verto/tests/assets/button-link/link_false_custom_argument_rules.json deleted file mode 100644 index e0a55640..00000000 --- a/verto/tests/assets/button-link/link_false_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "button-link": { - "link": false - } -} diff --git a/verto/tests/assets/button-link/text_false_custom_argument_rules.json b/verto/tests/assets/button-link/text_false_custom_argument_rules.json deleted file mode 100644 index 31410a7e..00000000 --- a/verto/tests/assets/button-link/text_false_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "button-link": { - "text": false - } -} diff --git a/verto/tests/assets/button-link/text_false_file_true_custom_argument_rules.json b/verto/tests/assets/button-link/text_false_file_true_custom_argument_rules.json deleted file mode 100644 index 936d4ba9..00000000 --- a/verto/tests/assets/button-link/text_false_file_true_custom_argument_rules.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "button-link": { - "file": true, - "text": false - } -} diff --git a/verto/tests/assets/configuration/custom_argument_rules_image_panel.json b/verto/tests/assets/configuration/custom_argument_rules_image_panel.json deleted file mode 100644 index ed177f2f..00000000 --- a/verto/tests/assets/configuration/custom_argument_rules_image_panel.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "panel": { - "subtitle": true - }, - "image-tag": { - "alt": false - } -} diff --git a/verto/tests/assets/configuration/custom_argument_rules_incorrect_processor.json b/verto/tests/assets/configuration/custom_argument_rules_incorrect_processor.json deleted file mode 100644 index 25f8ebc1..00000000 --- a/verto/tests/assets/configuration/custom_argument_rules_incorrect_processor.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "panl": { - "subtitle": true - }, - "image-tag": { - "alt": false - } -} diff --git a/verto/tests/assets/configuration/custom_argument_rules_incorrect_processor_argument.json b/verto/tests/assets/configuration/custom_argument_rules_incorrect_processor_argument.json deleted file mode 100644 index 23ded3bb..00000000 --- a/verto/tests/assets/configuration/custom_argument_rules_incorrect_processor_argument.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "panel": { - "totallyrealargument": true - }, - "image-tag": { - "alt": false - } -} diff --git a/verto/tests/assets/glossary-link/reference_text_true_custom_argument_rules.json b/verto/tests/assets/glossary-link/reference_text_true_custom_argument_rules.json deleted file mode 100644 index 580dc5de..00000000 --- a/verto/tests/assets/glossary-link/reference_text_true_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "glossary-link": { - "reference-text": true - } -} diff --git a/verto/tests/assets/iframe/link_false_custom_argument_rules.json b/verto/tests/assets/iframe/link_false_custom_argument_rules.json deleted file mode 100644 index 16ffdd75..00000000 --- a/verto/tests/assets/iframe/link_false_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "iframe": { - "link": false - } -} diff --git a/verto/tests/assets/image-container/alt_false_custom_argument_rules.json b/verto/tests/assets/image-container/alt_false_custom_argument_rules.json deleted file mode 100644 index 5772d7eb..00000000 --- a/verto/tests/assets/image-container/alt_false_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "image-container": { - "alt": false - } -} diff --git a/verto/tests/assets/image-container/alt_false_source_true_custom_argument_rules.json b/verto/tests/assets/image-container/alt_false_source_true_custom_argument_rules.json deleted file mode 100644 index e6e6b066..00000000 --- a/verto/tests/assets/image-container/alt_false_source_true_custom_argument_rules.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "image-container": { - "alt": false, - "source": true - } -} diff --git a/verto/tests/assets/image-container/hover_true_custom_argument_rules.json b/verto/tests/assets/image-container/hover_true_custom_argument_rules.json deleted file mode 100644 index 174a05ec..00000000 --- a/verto/tests/assets/image-container/hover_true_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "image-container": { - "hover-text": true - } -} diff --git a/verto/tests/assets/image-inline/alt_false_custom_argument_rules.json b/verto/tests/assets/image-inline/alt_false_custom_argument_rules.json deleted file mode 100644 index c838e868..00000000 --- a/verto/tests/assets/image-inline/alt_false_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "image-inline": { - "alt": false - } -} diff --git a/verto/tests/assets/image-inline/alt_false_source_true_custom_argument_rules.json b/verto/tests/assets/image-inline/alt_false_source_true_custom_argument_rules.json deleted file mode 100644 index f16994a3..00000000 --- a/verto/tests/assets/image-inline/alt_false_source_true_custom_argument_rules.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "image-inline": { - "alt": false, - "source": true - } -} diff --git a/verto/tests/assets/image-inline/hover_true_custom_argument_rules.json b/verto/tests/assets/image-inline/hover_true_custom_argument_rules.json deleted file mode 100644 index a40f1625..00000000 --- a/verto/tests/assets/image-inline/hover_true_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "image-inline": { - "hover-text": true - } -} diff --git a/verto/tests/assets/image-tag/alt_false_custom_argument_rules.json b/verto/tests/assets/image-tag/alt_false_custom_argument_rules.json deleted file mode 100644 index bf09da76..00000000 --- a/verto/tests/assets/image-tag/alt_false_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "image-tag": { - "alt": false - } -} diff --git a/verto/tests/assets/image-tag/alt_false_source_true_custom_argument_rules.json b/verto/tests/assets/image-tag/alt_false_source_true_custom_argument_rules.json deleted file mode 100644 index 853a1559..00000000 --- a/verto/tests/assets/image-tag/alt_false_source_true_custom_argument_rules.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "image-tag": { - "alt": false, - "source": true - } -} diff --git a/verto/tests/assets/image-tag/hover_true_custom_argument_rules.json b/verto/tests/assets/image-tag/hover_true_custom_argument_rules.json deleted file mode 100644 index ed656286..00000000 --- a/verto/tests/assets/image-tag/hover_true_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "image-tag": { - "hover-text": true - } -} diff --git a/verto/tests/assets/interactive/parameters_true_custom_argument_rules.json b/verto/tests/assets/interactive/parameters_true_custom_argument_rules.json deleted file mode 100644 index a7b8184b..00000000 --- a/verto/tests/assets/interactive/parameters_true_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "interactive": { - "parameters": true - } -} diff --git a/verto/tests/assets/interactive/text_and_thumbnail_true_custom_argument_rules.json b/verto/tests/assets/interactive/text_and_thumbnail_true_custom_argument_rules.json deleted file mode 100644 index 3dcfbe1f..00000000 --- a/verto/tests/assets/interactive/text_and_thumbnail_true_custom_argument_rules.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "interactive": { - "text": true, - "thumbnail": true - } -} diff --git a/verto/tests/assets/interactive/text_true_custom_argument_rules.json b/verto/tests/assets/interactive/text_true_custom_argument_rules.json deleted file mode 100644 index 6c3ddb4b..00000000 --- a/verto/tests/assets/interactive/text_true_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "interactive": { - "text": true - } -} diff --git a/verto/tests/assets/interactive/thumbnail_true_custom_argument_rules.json b/verto/tests/assets/interactive/thumbnail_true_custom_argument_rules.json deleted file mode 100644 index 1115c139..00000000 --- a/verto/tests/assets/interactive/thumbnail_true_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "interactive": { - "thumbnail": true - } -} diff --git a/verto/tests/assets/panel/expanded_true_custom_argument_rules.json b/verto/tests/assets/panel/expanded_true_custom_argument_rules.json deleted file mode 100644 index 7c10d5a7..00000000 --- a/verto/tests/assets/panel/expanded_true_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "panel": { - "expanded": true - } -} diff --git a/verto/tests/assets/panel/subtitle_true_custom_argument_rules.json b/verto/tests/assets/panel/subtitle_true_custom_argument_rules.json deleted file mode 100644 index e82b0819..00000000 --- a/verto/tests/assets/panel/subtitle_true_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "panel": { - "subtitle": true - } -} diff --git a/verto/tests/assets/panel/type_false_custom_argument_rules.json b/verto/tests/assets/panel/type_false_custom_argument_rules.json deleted file mode 100644 index 0d02f63f..00000000 --- a/verto/tests/assets/panel/type_false_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "panel": { - "type": false - } -} diff --git a/verto/tests/assets/video/url_false_custom_argument_rules.json b/verto/tests/assets/video/url_false_custom_argument_rules.json deleted file mode 100644 index 0264314a..00000000 --- a/verto/tests/assets/video/url_false_custom_argument_rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "video": { - "url": false - } -} From 7f4fbbff1edcfbe66908c16c573524bf5cf2d7b1 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Sun, 12 Aug 2018 20:30:05 +1200 Subject: [PATCH 68/73] modified docs for new custom argument rules parameter type --- docs/source/usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 6716053f..c215f36b 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -51,7 +51,7 @@ Once the module is imported, you can create a Verto converter creating an Verto - ``extensions`` - A list of extra Markdown extensions to run in the converter. Details on how to use this parameter can be found on the :doc:`extensions` page. -- ``custom_argument_rules`` - A json file to modify the default argument rules for each tag. The default rules can found by reading the documentation for each tag. +- ``custom_argument_rules`` - A dictionary to modify the default argument rules for each tag. The default rules can found by reading the documentation for each tag. - *For example:* By default, the ``image-inline`` tag requires alt text to be given, to change this, the following custom argument rules file would be used: From 2e990a9761342d6422f3db956fc20831fcf2997c Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Sun, 12 Aug 2018 20:31:24 +1200 Subject: [PATCH 69/73] Added missing docstring --- verto/Verto.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/verto/Verto.py b/verto/Verto.py index de360237..a883aa92 100644 --- a/verto/Verto.py +++ b/verto/Verto.py @@ -43,6 +43,8 @@ def __init__(self, processors=DEFAULT_PROCESSORS, html_templates={}, extensions= eg: {'image': ''} extensions: A list of extra extensions to run on the markdown package. + custom_argument_rules: A dictionary of rules for the processors to + override default processor rules. ''' self.processors = set(processors) self.html_templates = dict(html_templates) From a350b6f46eabb812bbc67215179b73150034fca8 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Mon, 20 Aug 2018 11:43:24 +1200 Subject: [PATCH 70/73] Update sphinx from 1.7.6 to 1.7.7 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a65f2589..6a313d11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ python-slugify==1.2.5 setuptools==40.0.0 # Required dependencies for building documentation -sphinx==1.7.6 +sphinx==1.7.7 sphinx_rtd_theme==0.4.1 From ce3fcdbd88b3bb836cd8e9ffb3639064c2cf8bf1 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 20 Aug 2018 15:29:19 +1200 Subject: [PATCH 71/73] Added missing full stop. --- docs/source/processors/interactive.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/processors/interactive.rst b/docs/source/processors/interactive.rst index c76f005e..77ad59d3 100644 --- a/docs/source/processors/interactive.rst +++ b/docs/source/processors/interactive.rst @@ -50,7 +50,7 @@ Optional Tag Parameters - ``text`` - Boolean flag to indicate whether the interactive has custom text to dispaly. - If given as ``true``, the the subtitle is the first block of text with the interactive block. - - This is only use with the ``whole-page`` value + - This is only use with the ``whole-page`` value. - If no text is given, the link uses the text ``Click to load {{ slug }}``. - ``parameters`` (used with ``whole-page`` and ``iframe`` values) - Adds the parameters From 8bf6f095e106dad987c275eb3626653244d2da5e Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Wed, 22 Aug 2018 02:44:03 +1200 Subject: [PATCH 72/73] Update setuptools from 40.0.0 to 40.2.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a65f2589..5bf104d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ markdown==2.6.11 Jinja2==2.10 python-slugify==1.2.5 -setuptools==40.0.0 +setuptools==40.2.0 # Required dependencies for building documentation sphinx==1.7.6 From 55a3cdc49c79b81958a1ae8b7856c590e979f440 Mon Sep 17 00:00:00 2001 From: Hayley van Waas Date: Mon, 27 Aug 2018 17:12:39 +1200 Subject: [PATCH 73/73] Bumped version number and updated changelog in docs --- docs/source/changelog.rst | 11 +++++++++++ verto/__init__.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index baa8eca7..9d3c693f 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -1,6 +1,17 @@ Changelog ####################################### +0.8.0 +======================================= + +- Modify :doc:`processors/interactive` processor for translating text, by required text between start and end tags for whole page interactives. +- Modify Verto parameters available on creation to allow modification of default required parameters for each processor. +- Dependency updates: + + - Update ``setuptools`` to 40.2.0. + - Update ``sphinx`` to 1.7.7. + - Update ``sphinx_rtx_theme`` to 0.4.1. + 0.7.4 ======================================= diff --git a/verto/__init__.py b/verto/__init__.py index 7a7d10fd..4c63cee3 100644 --- a/verto/__init__.py +++ b/verto/__init__.py @@ -1,4 +1,4 @@ # flake8: noqa from .Verto import Verto -__version__ = '0.7.4' +__version__ = '0.8.0'