Exemplo n.º 1
0
 def test_render_to_html_with_error(self):
     """ Test the ``render_to_html`` function with erroneous node """
     root_tree_node = RootTreeNode()
     tree_node_l1 = root_tree_node.new_child('level1', get_test_node('level1-1'),
                                             source_open_tag='[level1-1]',
                                             source_close_tag='[/level1-1]', error_message='foo')
     tree_node_l1.error_message = 'foo'
     root_tree_node.new_child('level1', get_test_node('level1-2'))
     tree_node_l2 = tree_node_l1.new_child('level2', get_test_node('level2-1'))
     tree_node_l1.new_child('level2', get_test_node('level2-2'))
     root_tree_node.new_child('level1', get_test_node('level1-3'))
     tree_node_l2.new_child('level3', get_test_node('level3-1'))
     tree_node_l3 = tree_node_l2.new_child('level3', get_test_node('level3-2'),
                                           source_open_tag='[level3-2]',
                                           source_close_tag='[/level3-2]', error_message='bar')
     tree_node_l3.error_message = 'bar'
     tree_node_l1.new_child('level2', get_test_node('level2-3'))
     output = render_to_html(root_tree_node,
                             html_error_template='<error={error_message}>{source}</error>',
                             some_custom_kwarg='foobar')
     expected_output = '<error=foo>[level1-1]</error>\n' \
                       '[HTML+level2-1]' \
                       '[HTML+level3-1][/HTML]' \
                       '<error=bar>[level3-2]</error>\n<error=bar>[/level3-2]</error>' \
                       '[/HTML]' \
                       '[HTML+level2-2][/HTML]' \
                       '[HTML+level2-3][/HTML]\n' \
                       '<error=foo>[/level1-1]</error>' \
                       '[HTML+level1-2][/HTML]' \
                       '[HTML+level1-3][/HTML]'
     self.assertEqual(expected_output, output)
Exemplo n.º 2
0
 def test_render_to_html_with_error_suppressed(self):
     """ Test the ``render_to_html`` function with erroneous node (error suppressed) """
     root_tree_node = RootTreeNode()
     tree_node_l1 = root_tree_node.new_child('level1', get_test_node('level1-1'),
                                             source_open_tag='[level1-1]',
                                             source_close_tag='[/level1-1]', error_message='foo')
     tree_node_l1.error_message = 'foo'
     root_tree_node.new_child('level1', get_test_node('level1-2'))
     tree_node_l2 = tree_node_l1.new_child('level2', get_test_node('level2-1'))
     tree_node_l1.new_child('level2', get_test_node('level2-2'))
     root_tree_node.new_child('level1', get_test_node('level1-3'))
     tree_node_l2.new_child('level3', get_test_node('level3-1'))
     tree_node_l3 = tree_node_l2.new_child('level3', get_test_node('level3-2'),
                                           source_open_tag='[level3-2]',
                                           source_close_tag='[/level3-2]', error_message='bar')
     tree_node_l3.error_message = 'bar'
     tree_node_l1.new_child('level2', get_test_node('level2-3'))
     output = render_to_html(root_tree_node,
                             html_error_template=SUPPRESS_ERROR_HTML_TEMPLATE,
                             some_custom_kwarg='foobar')
     expected_output = '<!-- foo --> [level1-1]\n' \
                       '[HTML+level2-1]' \
                       '[HTML+level3-1][/HTML]' \
                       '<!-- bar --> [level3-2]\n<!-- bar --> [/level3-2]' \
                       '[/HTML]' \
                       '[HTML+level2-2][/HTML]' \
                       '[HTML+level2-3][/HTML]\n' \
                       '<!-- foo --> [/level1-1]' \
                       '[HTML+level1-2][/HTML]' \
                       '[HTML+level1-3][/HTML]'
     self.assertEqual(expected_output, output)
Exemplo n.º 3
0
    def test_debug_print_ast_with_erroneous_parent(self):
        """ Test if the ``debug_print_ast`` work as expected when an erroneous aprent is found. """
        # RootTreeNode
        #  - level 1 child 1
        #   - level 2 child 1
        #     - level 3 child 1
        #  - level 1 child 2
        root_tree_node = RootTreeNode()
        l1_tree_node = root_tree_node.new_child('level_1_child_1', DummyTreeNode, attrs={'foo': 'bar'})
        root_tree_node.new_child('level_1_child_2', DummyTreeNode)
        l2_tree_node = l1_tree_node.new_child('level_2_child_1', DummyTreeNode)
        l3_tree_node = l2_tree_node.new_child('level_3_child_1', DummyTreeNode, content='Hello world!')

        # Add some oops
        l3_tree_node.parent = root_tree_node

        output_returned = []

        def _print_to_str(*args):
            output_returned.append(' '.join(args))
        debug_print_ast(root_tree_node, print_fnct=_print_to_str)

        expected_output = [
            "RootTreeNode(name=\"None\", attrs={}, content='', len(children)=2) ",
            "    DummyTreeNode(name=\"level_1_child_1\", attrs={'foo': 'bar'}, content='', len(children)=1) ",
            "        DummyTreeNode(name=\"level_2_child_1\", attrs={}, content='', len(children)=1) ",
            "            DummyTreeNode(name=\"level_3_child_1\", attrs={}, content='Hello world!', len(children)=0) !! Parent mismatch !!",
            "    DummyTreeNode(name=\"level_1_child_2\", attrs={}, content='', len(children)=0) "
        ]
        self.maxDiff = None
        self.assertEqual(expected_output, output_returned)
Exemplo n.º 4
0
 def test_get_attribute_value_second_try(self):
     """ Test the ``get_attribute_value`` helper method """
     document_tree = RootTreeNode()
     tree_node = document_tree.new_child('node', DummyTreeNode, attrs={'at1': '', 'at2': 'bar', 'at3': 'baz'})
     self.assertEqual('bar', tree_node.get_attribute_value('at1', 'at2', 'at3'))
     tree_node = document_tree.new_child('node', DummyTreeNode, attrs={'at3': 'baz'})
     self.assertEqual('baz', tree_node.get_attribute_value('at1', 'at2', 'at3'))
Exemplo n.º 5
0
 def test_sanitize_node(self):
     """ Test if the ``sanitize_node`` method mark the node as erroneous when title is missing """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('email', EmailLinkTreeNode, attrs={})
     tree_node.sanitize_node([])
     self.assertEqual('Missing or erroneous target email address', tree_node.error_message)
     tree_node = root_tree_node.new_child('email', EmailLinkTreeNode, attrs={'email': '*****@*****.**'})
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
Exemplo n.º 6
0
 def test_sanitize_node_erroneous_language_name(self):
     """ Test the ``sanitize_node`` method with erroneous language name. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={})
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={'code': 'foobar'})
     tree_node.sanitize_node([])
     self.assertEqual('Unknown language', tree_node.error_message)
Exemplo n.º 7
0
 def test_sanitize_node(self):
     """ Test if the ``sanitize_node`` method mark the node as erroneous when title is missing """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('color', ColorTextTreeNode, attrs={'color': 'blue'})
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
     tree_node = root_tree_node.new_child('color', ColorTextTreeNode, attrs={'color': ''})
     tree_node.sanitize_node([])
     self.assertEqual('Missing color value', tree_node.error_message)
Exemplo n.º 8
0
 def test_has_errors_true(self):
     """ Test the ``has_errors`` helper. """
     document_tree = RootTreeNode()
     document_tree.new_child('node', DummyTreeNode)
     l1_tree_node = document_tree.new_child('test_l1', OtherDummyTreeNode)
     l1_tree_node.new_child('node', DummyTreeNode)
     l2_tree_node = l1_tree_node.new_child('test_l2', OtherDummyTreeNode, error_message='foobar')
     l2_tree_node.new_child('node', DummyTreeNode)
     self.assertTrue(document_tree.has_errors())
Exemplo n.º 9
0
 def test_has_errors_false(self):
     """ Test the ``has_errors`` helper. """
     document_tree = RootTreeNode()
     document_tree.new_child('node', DummyTreeNode)
     l1_tree_node = document_tree.new_child('test_l1', OtherDummyTreeNode)
     l1_tree_node.new_child('node', DummyTreeNode)
     l2_tree_node = l1_tree_node.new_child('test_l2', OtherDummyTreeNode)
     l2_tree_node.new_child('node', DummyTreeNode)
     self.assertFalse(document_tree.has_errors())
Exemplo n.º 10
0
 def test_sanitize_node(self):
     """ Test if the ``sanitize_node`` method mark the node as erroneous when title is missing """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('url', UrlLinkTreeNode, attrs={})
     tree_node.sanitize_node([])
     self.assertEqual('Missing or erroneous target URL', tree_node.error_message)
     tree_node = root_tree_node.new_child('url', UrlLinkTreeNode, attrs={'url': 'http://example.com'})
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
Exemplo n.º 11
0
 def test_search_in_tree(self):
     """ Test the ``search_in_tree`` helper. """
     document_tree = RootTreeNode()
     node1 = document_tree.new_child('node', DummyTreeNode)
     l1_tree_node = document_tree.new_child('test_l1', OtherDummyTreeNode)
     node2 = l1_tree_node.new_child('node', DummyTreeNode)
     l2_tree_node = l1_tree_node.new_child('test_l2', OtherDummyTreeNode)
     node3 = l2_tree_node.new_child('node', DummyTreeNode)
     nodes = list(document_tree.search_in_tree(DummyTreeNode))
     self.assertEqual([node1, node2, node3], nodes)
Exemplo n.º 12
0
 def test_sanitize_node(self):
     """ Test if the ``sanitize_node`` method mark the node as erroneous when title is missing """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('youtube', YoutubeTreeNode,
                                          content='https://www.youtube.com/watch?v=dQw4w9WgXcQ')
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
     tree_node = root_tree_node.new_child('youtube', YoutubeTreeNode, content='')
     tree_node.sanitize_node([])
     self.assertEqual('Missing or erroneous video URL', tree_node.error_message)
Exemplo n.º 13
0
 def test_make_paragraphs_erroneous_nodes(self):
     """ Test the ``make_paragraphs`` paragraph utility. """
     root_tree_node = RootTreeNode()
     a = root_tree_node.new_child(None, TextTreeNode, content='Text 1')
     b = root_tree_node.new_child(None, TextTreeNode, content='', error_message='Foobar')
     c = root_tree_node.new_child(None, NewlineTreeNode)
     make_paragraphs(root_tree_node)
     self.assertEqual(len(root_tree_node.children), 1)
     self.assertIsInstance(root_tree_node.children[0], ParagraphTreeNode)
     self.assertEqual([a, b, c], root_tree_node.children[0].children)
Exemplo n.º 14
0
 def test_make_paragraphs_trailing_newline(self):
     """ Test the ``make_paragraphs`` paragraph utility. """
     root_tree_node = RootTreeNode()
     z = root_tree_node.new_child(None, NewlineTreeNode)
     a = root_tree_node.new_child(None, TextTreeNode, content='Text 1')
     b = root_tree_node.new_child(None, NewlineTreeNode)
     make_paragraphs(root_tree_node)
     self.assertEqual(len(root_tree_node.children), 2)
     self.assertEqual(root_tree_node.children[0], z)
     self.assertIsInstance(root_tree_node.children[1], ParagraphTreeNode)
     self.assertEqual([a, b], root_tree_node.children[1].children)
Exemplo n.º 15
0
 def test_pre_process_node(self):
     """ Test the ``pre_process_node`` method. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('figure', FigureDeclarationTreeNode)
     tree_node.pre_process_node()
     self.assertEqual('', tree_node.error_message)
     self.assertEqual({'figure-1'}, root_tree_node.known_ids)
     tree_node = root_tree_node.new_child('figure', FigureDeclarationTreeNode, attrs={'id': 'figure-1'})
     tree_node.pre_process_node()
     self.assertEqual('ID already used previously', tree_node.error_message)
     self.assertEqual({'figure-1'}, root_tree_node.known_ids)
Exemplo n.º 16
0
 def test_make_paragraphs_custom_class(self):
     """ Test the ``make_paragraphs`` paragraph utility. """
     root_tree_node = RootTreeNode()
     a = root_tree_node.new_child(None, TextTreeNode, content='Text 1')
     b = root_tree_node.new_child(None, NewlineTreeNode)
     c = root_tree_node.new_child(None, TextTreeNode, content='Text 1')
     d = root_tree_node.new_child(None, NewlineTreeNode)
     make_paragraphs(root_tree_node, paragraph_node_cls=CustomParagraphTreeNode)
     self.assertEqual(len(root_tree_node.children), 1)
     self.assertIsInstance(root_tree_node.children[0], CustomParagraphTreeNode)
     self.assertEqual([a, b, c, d], root_tree_node.children[0].children)
Exemplo n.º 17
0
 def test_get_figure_id_from_counter_increment(self):
     """ Test the ``get_figure_id_from_counter`` method by calling it multiple time with different figures. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('figure', FigureDeclarationTreeNode)
     self.assertEqual('figure-1', tree_node.get_figure_id_from_counter())
     self.assertEqual('figure-1', tree_node.get_figure_id_from_counter())
     tree_node_2 = root_tree_node.new_child('figure', FigureDeclarationTreeNode)
     self.assertEqual('figure-2', tree_node_2.get_figure_id_from_counter())
     self.assertEqual('figure-2', tree_node_2.get_figure_id_from_counter())
     tree_node_3 = root_tree_node.new_child('figure', FigureDeclarationTreeNode)
     self.assertEqual('figure-3', tree_node_3.get_figure_id_from_counter())
     self.assertEqual('figure-3', tree_node_3.get_figure_id_from_counter())
Exemplo n.º 18
0
 def test_sanitize_node_negative_line_numbers(self):
     """ Test the ``sanitize_node`` method with negative line numbers. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={})
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={'hl_lines': '-1'})
     tree_node.sanitize_node([])
     self.assertEqual('Line number must be positive', tree_node.error_message)
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={'linenostart': '-1'})
     tree_node.sanitize_node([])
     self.assertEqual('Line number must be positive', tree_node.error_message)
Exemplo n.º 19
0
 def test_sanitize_node_erroneous_line_numbers(self):
     """ Test the ``sanitize_node`` method with erroneous line numbers. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={})
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={'hl_lines': 'abc'})
     tree_node.sanitize_node([])
     self.assertEqual('abc is not a number', tree_node.error_message)
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={'linenostart': 'abc'})
     tree_node.sanitize_node([])
     self.assertEqual('abc is not a number', tree_node.error_message)
Exemplo n.º 20
0
 def test_sanitize_node(self):
     """ Test the ``sanitize_node`` method. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('list', ListTreeNode, attrs={'start': '3'})
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
     tree_node = root_tree_node.new_child('list', ListTreeNode, attrs={'start': '-3'})
     tree_node.sanitize_node([])
     self.assertEqual('First line number must be positive', tree_node.error_message)
     tree_node = root_tree_node.new_child('list', ListTreeNode, attrs={'start': 'abcd'})
     tree_node.sanitize_node([])
     self.assertEqual('abcd is not a number', tree_node.error_message)
Exemplo n.º 21
0
 def test_get_raw_content_method_no_recursion(self):
     """ Test if the ``get_raw_content`` method work as expected. """
     # RootTreeNode
     #  - level 1 child 1
     #   - level 2 child
     #     - level 3 child
     #  - level 1 child 2
     root_tree_node = RootTreeNode()
     l1_tree_node = root_tree_node.new_child('level 1 child 1', DummyTreeNode, content='Level 1-1')
     root_tree_node.new_child('level 1 child 2', DummyTreeNode, content='Level 1-2')
     l2_tree_node = l1_tree_node.new_child('level 2 child', DummyTreeNode, content='Level 2')
     l2_tree_node.new_child('level 3 child', DummyTreeNode, content='Level 3')
     raw_content = l1_tree_node.get_raw_content(recursive=False)
     self.assertEqual('Level 1-1', raw_content)
Exemplo n.º 22
0
 def test_sanitize_node(self):
     """ Test if the ``sanitize_node`` method mark the node as erroneous when title is missing """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('goto', GoToAnchorTreeNode, attrs={'id': ''})
     tree_node.sanitize_node([])
     self.assertEqual('Missing anchor ID', tree_node.error_message)
     self.assertEqual(set(), root_tree_node.known_ids)
     tree_node = root_tree_node.new_child('goto', GoToAnchorTreeNode, attrs={'id': 'test'})
     tree_node.sanitize_node([])
     self.assertEqual('Unknown anchor ID', tree_node.error_message)
     root_tree_node.known_ids.add('test')
     tree_node = root_tree_node.new_child('goto', GoToAnchorTreeNode, attrs={'id': 'test'})
     tree_node.sanitize_node([])
     self.assertEqual('', tree_node.error_message)
Exemplo n.º 23
0
 def test_pre_process_node(self):
     """ Test if the ``pre_process_node`` method mark the node as erroneous when anchor ID is missing """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('anchor', AnchorTreeNode, content='')
     tree_node.pre_process_node()
     self.assertEqual('Missing anchor ID', tree_node.error_message)
     tree_node = root_tree_node.new_child('anchor', AnchorTreeNode, content='test')
     tree_node.pre_process_node()
     self.assertEqual('', tree_node.error_message)
     self.assertEqual({'test'}, root_tree_node.known_ids)
     tree_node = root_tree_node.new_child('anchor', AnchorTreeNode, content='test')
     tree_node.pre_process_node()
     self.assertEqual('ID already used previously', tree_node.error_message)
     self.assertEqual({'test'}, root_tree_node.known_ids)
Exemplo n.º 24
0
 def test_make_paragraphs_mixed_inline_block(self):
     """ Test the ``make_paragraphs`` paragraph utility. """
     root_tree_node = RootTreeNode()
     a = root_tree_node.new_child(None, TextTreeNode, content='Text 1')
     b = root_tree_node.new_child(None, NewlineTreeNode)
     z = root_tree_node.new_child('block', CustomBlockTreeNode)
     c = root_tree_node.new_child(None, TextTreeNode, content='Text 1')
     d = root_tree_node.new_child(None, NewlineTreeNode)
     make_paragraphs(root_tree_node)
     self.assertEqual(len(root_tree_node.children), 3)
     self.assertIsInstance(root_tree_node.children[0], ParagraphTreeNode)
     self.assertEqual([a, b], root_tree_node.children[0].children)
     self.assertEqual(root_tree_node.children[1], z)
     self.assertIsInstance(root_tree_node.children[2], ParagraphTreeNode)
     self.assertEqual([c, d], root_tree_node.children[2].children)
Exemplo n.º 25
0
 def test_render_inner_html(self):
     """ Test the ``render_inner_html`` function """
     root_tree_node = RootTreeNode()
     tree_node_l1 = root_tree_node.new_child('level1', get_test_node('level1-1'))
     root_tree_node.new_child('level1', get_test_node('level1-2'))
     tree_node_l2 = tree_node_l1.new_child('level2', get_test_node('level2-1'))
     tree_node_l1.new_child('level2', get_test_node('level2-2'))
     root_tree_node.new_child('level1', get_test_node('level1-3'))
     tree_node_l2.new_child('level3', get_test_node('level3-1'))
     tree_node_l2.new_child('level3', get_test_node('level3-2'))
     tree_node_l1.new_child('level2', get_test_node('level2-3'))
     output = render_inner_html(tree_node_l2, some_custom_kwarg='foobar')
     expected_output = '[HTML+level3-1][/HTML]' \
                       '[HTML+level3-2][/HTML]'
     self.assertEqual(expected_output, output)
Exemplo n.º 26
0
 def test_get_language_name_method(self):
     """ Test if the ``get_language_name`` return the value set at constructor. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('test', generate_fixed_code_block_type_cls('foobar'),
                                          attrs={}, content='# Hello World!')
     language_name = tree_node.get_language_name()
     self.assertEqual('foobar', language_name)
Exemplo n.º 27
0
 def test_render_text(self):
     """ Test the ``render_text`` method. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={'code': 'python'}, content='# Hello World!')
     output_result = tree_node.render_text('')
     expected_result = '1.   # Hello World!\n'
     self.assertEqual(expected_result, output_result)
Exemplo n.º 28
0
 def test_get_figure_id_slugify(self):
     """ Test the ``get_figure_id`` method call the ``slugify`` function. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={'id': 'test'})
     with unittest.mock.patch('skcode.tags.codeblocks.slugify') as mock_slugify:
         tree_node.get_figure_id()
     mock_slugify.assert_called_once_with('test')
Exemplo n.º 29
0
 def test_render_text_with_default_language(self):
     """ Test the ``render_text`` method with the default language set. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={}, content='# Hello World!')
     output_result = tree_node.render_text('')
     expected_result = '1.   # Hello World!\n'
     self.assertEqual(expected_result, output_result)
Exemplo n.º 30
0
 def test_render_text_with_trailing_blank_lines(self):
     """ Test the ``render_text`` method with trailing blank lines. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('code', CodeBlockTreeNode, attrs={'code': 'python'}, content='\n\n# Hello World!\n')
     output_result = tree_node.render_text('')
     expected_result = '1.   # Hello World!\n'
     self.assertEqual(expected_result, output_result)
Exemplo n.º 31
0
 def test_get_alert_type_uppercase(self):
     """ Test the ``get_alert_type`` method with a valid alert type but in uppercase. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('alert',
                                          AlertBoxTreeNode,
                                          attrs={'type': 'ERRor'})
     alert_type = tree_node.get_alert_type()
     self.assertEqual('error', alert_type)
Exemplo n.º 32
0
 def test_text_rendering_with_extra_whitespaces(self):
     """ Test text rendering with extra whitespaces around the inner text. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child(
         'abbr', AcronymTreeNode, attrs={'title': 'As Soon As Possible'})
     rendered_output = tree_node.render_text(' ASAP ')
     expected_output = ' ASAP (As Soon As Possible) '
     self.assertEqual(expected_output, rendered_output)
Exemplo n.º 33
0
 def test_text_rendering(self):
     """ Test text rendering. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child(
         'abbr', AcronymTreeNode, attrs={'title': 'As Soon As Possible'})
     rendered_output = tree_node.render_text('ASAP')
     expected_output = 'ASAP (As Soon As Possible)'
     self.assertEqual(expected_output, rendered_output)
Exemplo n.º 34
0
 def test_get_alert_type_with_invalid_type(self):
     """ Test the ``get_alert_type`` method with an invalid alert type. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('alert',
                                          AlertBoxTreeNode,
                                          attrs={'type': 'notatype'})
     alert_type = tree_node.get_alert_type()
     self.assertEqual(tree_node.default_type, alert_type)
Exemplo n.º 35
0
 def test_html_rendering_custom_css(self):
     """ Test HTML rendering. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('figcaption',
                                          CustomFigureCaptionTreeNode)
     rendered_output = tree_node.render_html('test')
     expected_output = '<figcaption class="custom_css">test</figcaption>\n'
     self.assertEqual(expected_output, rendered_output)
Exemplo n.º 36
0
 def test_get_attribute_value_second_try(self):
     """ Test the ``get_attribute_value`` helper method """
     document_tree = RootTreeNode()
     tree_node = document_tree.new_child('node',
                                         DummyTreeNode,
                                         attrs={
                                             'at1': '',
                                             'at2': 'bar',
                                             'at3': 'baz'
                                         })
     self.assertEqual('bar',
                      tree_node.get_attribute_value('at1', 'at2', 'at3'))
     tree_node = document_tree.new_child('node',
                                         DummyTreeNode,
                                         attrs={'at3': 'baz'})
     self.assertEqual('baz',
                      tree_node.get_attribute_value('at1', 'at2', 'at3'))
Exemplo n.º 37
0
 def test_render_text_with_alt_text(self):
     """ Test the ``render_text`` method with an alternative text. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('img', ImageTreeNode, attrs={'alt': 'Example image.'},
                                          content='http://example.com/image.jpg')
     output_result = tree_node.render_text('test')
     expected_result = 'http://example.com/image.jpg (Example image.)'
     self.assertEqual(expected_result, output_result)
Exemplo n.º 38
0
 def test_render_html_with_img_width(self):
     """ Test the ``render_html`` method with an image width. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('img', ImageTreeNode, attrs={'alt': 'Example image.', 'width': '120'},
                                          content='http://example.com/image.jpg')
     output_result = tree_node.render_html('test')
     expected_result = '<img src="http://example.com/image.jpg" alt="Example image." width="120" />'
     self.assertEqual(expected_result, output_result)
Exemplo n.º 39
0
 def test_render_html_with_alt_text_containing_html_entities(self):
     """ Test the ``render_html`` method with an alternative text containing HTML entities. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('img', ImageTreeNode, attrs={'alt': '<Example image.>'},
                                          content='http://example.com/image.jpg')
     output_result = tree_node.render_html('test')
     expected_result = '<img src="http://example.com/image.jpg" alt="&lt;Example image.&gt;" />'
     self.assertEqual(expected_result, output_result)
Exemplo n.º 40
0
 def test_default_render_text_implementation(self):
     """ Test the default ``render_text`` method implementation. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('child', DummyTreeNode)
     with self.assertRaises(NotImplementedError) as e:
         tree_node.render_text('', custom_value='foobar')
     self.assertEqual('render_text() need to be implemented in subclass',
                      str(e.exception))
Exemplo n.º 41
0
 def test_text_rendering_with_no_id(self):
     """ Test text rendering with no ID set. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('fnref',
                                          FootnoteReferenceTreeNode,
                                          content='')
     rendered_output = tree_node.render_html('Hello world!')
     self.assertEqual('Hello world!', rendered_output)
Exemplo n.º 42
0
 def test_get_footnote_ref_id(self):
     """  Test the ``get_footnote_ref_id`` method. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('fnref',
                                          FootnoteReferenceTreeNode,
                                          content='test')
     output = tree_node.get_footnote_ref_id('test')
     self.assertEqual('footnote-test', output)
Exemplo n.º 43
0
 def test_get_footnote_id_with_no_id_set(self):
     """ Test the ``get_footnote_id`` method with no ID set. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('fnref',
                                          FootnoteReferenceTreeNode,
                                          content='')
     output = tree_node.get_footnote_id()
     self.assertEqual('', output)
Exemplo n.º 44
0
 def test_html_rendering(self):
     """ Test HTML rendering. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child(
         'dd', DefinitionListTermDefinitionTreeNode)
     rendered_output = tree_node.render_html('test')
     expected_output = '<dd>test</dd>\n'
     self.assertEqual(expected_output, rendered_output)
Exemplo n.º 45
0
 def test_text_rendering(self):
     """ Test text rendering. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('figcaption',
                                          FigureCaptionTreeNode)
     rendered_output = tree_node.render_text('test')
     expected_output = ''
     self.assertEqual(expected_output, rendered_output)
Exemplo n.º 46
0
 def test_text_rendering(self):
     """ Test text rendering. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child(
         'dd', DefinitionListTermDefinitionTreeNode)
     rendered_output = tree_node.render_text('test')
     expected_output = 'test'
     self.assertEqual(expected_output, rendered_output)
Exemplo n.º 47
0
 def test_html_rendering_with_html_entities_in_title(self):
     """ Test HTML rendering with HTML entities in title. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child(
         'abbr', AcronymTreeNode, attrs={'title': '<As Soon As Possible>'})
     rendered_output = tree_node.render_html('ASAP')
     expected_output = '<abbr title="&lt;As Soon As Possible&gt;">ASAP</abbr>'
     self.assertEqual(expected_output, rendered_output)
Exemplo n.º 48
0
 def test_text_rendering_trailing_whitespaces(self):
     """ Test text rendering with trailing whitespaces. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child(
         'dd', DefinitionListTermDefinitionTreeNode)
     rendered_output = tree_node.render_text('  foo bar   ')
     expected_output = 'foo bar'
     self.assertEqual(expected_output, rendered_output)
Exemplo n.º 49
0
 def test_text_rendering_with_html_entities_in_title(self):
     """ Test text rendering with HTML entities in title. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child(
         'abbr', AcronymTreeNode, attrs={'title': '<As Soon As Possible>'})
     rendered_output = tree_node.render_text('ASAP')
     expected_output = 'ASAP (<As Soon As Possible>)'
     self.assertEqual(expected_output, rendered_output)
Exemplo n.º 50
0
 def test_render_inner_html(self):
     """ Test the ``render_inner_html`` function """
     root_tree_node = RootTreeNode()
     tree_node_l1 = root_tree_node.new_child('level1',
                                             get_test_node('level1-1'))
     root_tree_node.new_child('level1', get_test_node('level1-2'))
     tree_node_l2 = tree_node_l1.new_child('level2',
                                           get_test_node('level2-1'))
     tree_node_l1.new_child('level2', get_test_node('level2-2'))
     root_tree_node.new_child('level1', get_test_node('level1-3'))
     tree_node_l2.new_child('level3', get_test_node('level3-1'))
     tree_node_l2.new_child('level3', get_test_node('level3-2'))
     tree_node_l1.new_child('level2', get_test_node('level2-3'))
     output = render_inner_html(tree_node_l2, some_custom_kwarg='foobar')
     expected_output = '[HTML+level3-1][/HTML]' \
                       '[HTML+level3-2][/HTML]'
     self.assertEqual(expected_output, output)
Exemplo n.º 51
0
 def test_get_acronym_title_with_title_set(self):
     """ Test the ``get_acronym_title`` method when the "title" attribute is set. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('abbr',
                                          AcronymTreeNode,
                                          attrs={'title': 'test'})
     title = tree_node.get_acronym_title()
     self.assertEqual('test', title)
Exemplo n.º 52
0
 def test_get_alert_title_with_html_entities(self):
     """ Test the ``get_alert_title`` when the title contain HTML entities. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('alert',
                                          AlertBoxTreeNode,
                                          attrs={'title': '&lt;test&gt;'})
     title = tree_node.get_alert_title()
     self.assertEqual('<test>', title)
Exemplo n.º 53
0
 def test_get_alert_type_without_type(self):
     """ Test the ``get_alert_type`` method without an alert type. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('alert',
                                          AlertBoxTreeNode,
                                          attrs={})
     alert_type = tree_node.get_alert_type()
     self.assertEqual(tree_node.default_type, alert_type)
Exemplo n.º 54
0
 def test_get_alert_title_with_default_value(self):
     """ Test the ``get_alert_title`` with no title set. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('alert',
                                          AlertBoxTreeNode,
                                          attrs={})
     title = tree_node.get_alert_title()
     self.assertEqual('', title)
Exemplo n.º 55
0
 def test_get_alert_type(self):
     """ Test the ``get_alert_type`` method with a valid alert type. """
     root_tree_node = RootTreeNode()
     for known_alert_type in AlertBoxTreeNode.accepted_types:
         tree_node = root_tree_node.new_child(
             'alert', AlertBoxTreeNode, attrs={'type': known_alert_type})
         alert_type = tree_node.get_alert_type()
         self.assertEqual(known_alert_type, alert_type)
Exemplo n.º 56
0
 def test_get_alert_title_with_title_set(self):
     """ Test the ``get_alert_title`` with the "title" attribute set. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('alert',
                                          AlertBoxTreeNode,
                                          attrs={'title': 'test'})
     title = tree_node.get_alert_title()
     self.assertEqual('test', title)
Exemplo n.º 57
0
 def test_html_rendering(self):
     """ Test HTML rendering. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('figure',
                                          FigureDeclarationTreeNode)
     rendered_output = tree_node.render_html('test')
     expected_output = '<figure class="thumbnail" id="figure-1">test</figure>\n'
     self.assertEqual(expected_output, rendered_output)
Exemplo n.º 58
0
 def test_text_rendering_trailing_whitespaces(self):
     """ Test text rendering. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('figure',
                                          FigureDeclarationTreeNode)
     rendered_output = tree_node.render_text('   foo bar   ')
     expected_output = "+----------\n| foo bar\n+----------\n"
     self.assertEqual(expected_output, rendered_output)
Exemplo n.º 59
0
 def test_get_footnote_id_with_tagname_set(self):
     """ Test the ``get_footnote_id`` method with the tag name set. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('footnote',
                                          FootnoteDeclarationTreeNode,
                                          attrs={'footnote': 'test'})
     output = tree_node.get_footnote_id()
     self.assertEqual('test', output)
Exemplo n.º 60
0
 def test_get_footnote_id_with_no_id_set_and_counter_enabled(self):
     """ Test the ``get_footnote_id`` method with no ID set and auto-counter enabled. """
     root_tree_node = RootTreeNode()
     tree_node = root_tree_node.new_child('footnote',
                                          FootnoteDeclarationTreeNode,
                                          attrs={})
     output = tree_node.get_footnote_id()
     self.assertEqual('footnote-1', output)