Exemplo n.º 1
0
    def test_doc_example_override_html(self):
        '''A 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], [
            VideoBlockProcessor(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)
Exemplo n.º 2
0
    def test_youtube_be_link(self):
        '''Tests that short youtube links are embedded.
        '''
        test_string = self.read_test_file(self.processor_name,
                                          'youtube_be_link.md')
        blocks = self.to_blocks(test_string)

        self.assertListEqual([False, True, 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=[self.verto_extension])
        expected_file_string = self.read_test_file(
            self.processor_name, 'youtube_be_link_expected.html', strip=True)
        self.assertEqual(converted_test_string, expected_file_string)
Exemplo n.º 3
0
    def test_contains_title(self):
        '''Tests output for video with title.
        '''
        test_string = self.read_test_file(self.processor_name,
                                          'contains_title.md')
        blocks = self.to_blocks(test_string)

        self.assertListEqual([True], [
            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=[self.verto_extension])
        expected_file_string = self.read_test_file(
            self.processor_name, 'contains_title_expected.html', strip=True)
        self.assertEqual(converted_test_string, expected_file_string)
Exemplo n.º 4
0
    def test_contains_no_video(self):
        '''Tests that input that doesn't use the video processor tag is
        unchanged.
        '''
        test_string = self.read_test_file(self.processor_name,
                                          'contains_no_video.md')
        blocks = self.to_blocks(test_string)

        self.assertFalse(all(
            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=[self.verto_extension])
        expected_file_string = self.read_test_file(
            self.processor_name, 'contains_no_video_expected.html', strip=True)
        self.assertEqual(converted_test_string, expected_file_string)
Exemplo n.º 5
0
    def test_missing_identifier(self):
        '''Tests that a youtube link without an identifier will throw
        the NoVideoIdentifierError exception.
        '''
        test_string = self.read_test_file(self.processor_name,
                                          'missing_identifier.md')
        blocks = self.to_blocks(test_string)

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

        self.assertRaises(
            NoVideoIdentifierError,
            lambda x: markdown.markdown(x, extensions=[self.verto_extension]),
            test_string)
Exemplo n.º 6
0
    def test_unsupported_video_type(self):
        '''Tests that links to other websites result in an
        UnsupportedVideoPlayerError exception.
        '''
        test_string = self.read_test_file(self.processor_name,
                                          'unsupported_video_type.md')
        blocks = self.to_blocks(test_string)

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

        self.assertRaises(
            UnsupportedVideoPlayerError,
            lambda x: markdown.markdown(x, extensions=[self.verto_extension]),
            test_string)
Exemplo n.º 7
0
    def test_doc_example_basic(self):
        '''A generic 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], [
            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=[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)
Exemplo n.º 8
0
    def test_multiple_vimeo_links(self):
        '''Tests output of multiple vimeo links.
        '''
        test_string = self.read_test_file(self.processor_name,
                                          'multiple_vimeo_links.md')
        blocks = self.to_blocks(test_string)

        self.assertListEqual([True, True, True], [
            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=[self.verto_extension])
        expected_file_string = self.read_test_file(
            self.processor_name,
            'multiple_vimeo_links_expected.html',
            strip=True)
        self.assertEqual(converted_test_string, expected_file_string)
Exemplo n.º 9
0
    def test_custom_argument_rules_title_true_not_provided(self):
        '''Tests to ensure that error is raised when title argument is required but not provided.
        '''
        custom_argument_rules = {"video": {"title": 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,
                                          'title_true_not_provided.md')
        blocks = self.to_blocks(test_string)

        self.assertListEqual([True], [
            VideoBlockProcessor(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)
Exemplo n.º 10
0
    def test_url_false_custom_argument_rules(self):
        '''Tests to ensure that video tag is rendered correctly when url argument is not required.
        '''
        custom_argument_rules = {"video": {"url": False}}
        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)
Exemplo n.º 11
0
    def test_youtube_and_vimeo_links(self):
        '''Test that youtube links and vimeo links work together in the
        same document.
        '''
        test_string = self.read_test_file(self.processor_name,
                                          'youtube_and_vimeo_links.md')
        blocks = self.to_blocks(test_string)

        self.assertListEqual([
            False, False, True, True, False, True, False, True, False, True,
            True, False, True, True
        ], [
            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=[self.verto_extension])
        expected_file_string = self.read_test_file(
            self.processor_name,
            'youtube_and_vimeo_links_expected.html',
            strip=True)
        self.assertEqual(converted_test_string, expected_file_string)
Exemplo n.º 12
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)