Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    def test_iframe(self):
        '''Test iframe interactive is ignored.
        '''
        test_string = self.read_test_file(self.processor_name, 'iframe.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))

        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)

        required_files = {
            'interactives': set(),
            'images': set(),
            'page_scripts': set(),
            'scratch_images': set()
        }
        self.assertEqual(self.verto_extension.required_files, required_files)
Exemplo n.º 3
0
    def test_custom_arguments_parameters_and_thumbnail_true(self):
        '''Tests to ensure that interactive tag is rendered correctly when text and thumbnail arguments are required.
        '''
        custom_argument_rules = {
            "interactive-container": {
                "parameters": True,
                "thumbnail": True
            }
        }
        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_and_thumbnail_true.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=[verto_extension_custom_rules])
        expected_string = self.read_test_file(
            self.processor_name,
            'parameters_and_thumbnail_true_expected.html',
            strip=True)
        self.assertEqual(expected_string, converted_test_string)
Exemplo n.º 4
0
    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(
            [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_expected.html',
            strip=True)
        self.assertEqual(expected_string, converted_test_string)

        required_files = {
            'interactives': {'arrows', 'flying-boxes'},
            'images': {
                '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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)

        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,
            'multiple_interactives_some_text_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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    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)

        self.assertListEqual([False, True, False, True, False], [
            InteractiveContainerBlockProcessor(self.ext, self.md.parser).test(
                blocks, block) for block in blocks
        ],
                             msg='"{}"'.format(test_string))

        self.assertRaises(
            InteractiveTextContainsInteractiveError,
            lambda x: markdown.markdown(x, extensions=[self.verto_extension]),
            test_string)
Exemplo n.º 11
0
    def test_custom_arguments_text_true_not_provided(self):
        '''Tests to ensure that correct error is raised when text is required and not provided.
        '''
        custom_argument_rules = {"interactive-container": {"text": True}}
        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([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=[verto_extension_custom_rules]), test_string)
Exemplo n.º 12
0
    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)
Exemplo n.º 13
0
 def buildProcessors(self, md, md_globals):
     '''
     Populates internal variables for processors. This should not be
     called externally, this is used by the extendMarkdown method.
     Args:
         md: An instance of the markdown object being extended.
         md_globals: Global variables in the markdown module namespace.
     '''
     self.preprocessors = [
         ['comment', CommentPreprocessor(self, md), '_begin'],
         ['save-title',
          SaveTitlePreprocessor(self, md), '_end'],
         ['remove-title',
          RemoveTitlePreprocessor(self, md), '_end'],
     ]
     self.blockprocessors = [
         # Markdown overrides
         ['heading',
          HeadingBlockProcessor(self, md.parser), '<hashheader'],
         # Single line (in increasing complexity)
         [
             'interactive-tag',
             InteractiveTagBlockProcessor(self, md.parser), '<paragraph'
         ],
         [
             'interactive-container',
             InteractiveContainerBlockProcessor(self, md.parser),
             '<paragraph'
         ],
         [
             'image-container',
             ImageContainerBlockProcessor(self, md.parser), '<paragraph'
         ],
         [
             'image-tag',
             ImageTagBlockProcessor(self, md.parser), '<paragraph'
         ],
         ['video',
          VideoBlockProcessor(self, md.parser), '<paragraph'],
         [
             'conditional',
             ConditionalProcessor(self, md.parser), '<paragraph'
         ],
         ['panel',
          PanelBlockProcessor(self, md.parser), '<paragraph'],
         [
             'blockquote',
             BlockquoteBlockProcessor(self, md.parser), '<paragraph'
         ],
         # Multiline
     ]
     self.inlinepatterns = [  # A special treeprocessor
         ['relative-link',
          RelativeLinkPattern(self, md), '_begin'],
         ['glossary-link',
          GlossaryLinkPattern(self, md), '_begin'],
         ['image-inline',
          ImageInlinePattern(self, md), '_begin']
     ]
     scratch_ordering = '>inline' if 'hilite' not in self.compatibility else '<hilite'
     self.treeprocessors = [
         ['scratch',
          ScratchTreeprocessor(self, md), scratch_ordering],
         [
             'scratch-inline',
             ScratchInlineTreeprocessor(self, md), '>inline'
         ],
     ]
     self.postprocessors = []
     self.buildGenericProcessors(md, md_globals)