Beispiel #1
0
def document_tree_two_levels_deep(document_tree_two_subpages):
    sub_page1 = document_tree_two_subpages.children[0]
    sub_page1.children.append(
        DocumentTreeNode(sub_page1.in_file.parent / "sub_page1_1.adoc", sub_page1))
    sub_page1.children.append(
        DocumentTreeNode(sub_page1.in_file.parent / "sub_page1_2.adoc", sub_page1))
    return document_tree_two_subpages
 def verify_node(node: DocumentTreeNode, expected_parent: DocumentTreeNode,
                 expected_prev: DocumentTreeNode,
                 expected_next: DocumentTreeNode):
     assert node.root() is root
     assert node.parent is expected_parent
     assert node.preorder_traversal_prev() is expected_prev
     assert node.preorder_traversal_next() is expected_next
Beispiel #3
0
def document_tree_two_subpages():
    root = DocumentTreeNode(Path("/project/index.adoc"))
    sub_page1 = DocumentTreeNode(root.in_file.parent / "sub_page1.adoc", root)
    root.children.append(sub_page1)
    sub_page2 = DocumentTreeNode(root.in_file.parent / "sub_page2.adoc", root)
    root.children.append(sub_page2)
    return root
Beispiel #4
0
def test_document_tree_node():
    # Test tree:
    #
    #       root
    #        /|\
    #       / | \
    #      /  |  \
    #     /   |   \
    #    a    b    c
    #    /\        /\
    #   /  \      /  \
    # a_a  a_b  c_a  c_b
    #      / \
    #     /   \
    #    /     \
    #  a_b_a  a_b_b
    root = DocumentTreeNode('root')
    a = DocumentTreeNode('a', root)
    root.children.append(a)
    b = DocumentTreeNode('b', root)
    root.children.append(b)
    c = DocumentTreeNode('c', root)
    root.children.append(c)
    a_a = DocumentTreeNode('a_a', a)
    a.children.append(a_a)
    a_b = DocumentTreeNode('a_b', a)
    a.children.append(a_b)
    a_b_a = DocumentTreeNode('a_b_a', a_b)
    a_b.children.append(a_b_a)
    a_b_b = DocumentTreeNode('a_b_b', a_b)
    a_b.children.append(a_b_b)
    c_a = DocumentTreeNode('c_a', c)
    c.children.append(c_a)
    c_b = DocumentTreeNode('c_b', c)
    c.children.append(c_b)

    def verify_node(node: DocumentTreeNode, expected_parent: DocumentTreeNode,
                    expected_prev: DocumentTreeNode, expected_next: DocumentTreeNode):
        assert node.root() is root
        assert node.parent is expected_parent
        assert node.preorder_traversal_prev() is expected_prev
        assert node.preorder_traversal_next() is expected_next

    verify_node(root, expected_parent=None, expected_prev=None, expected_next=a)
    verify_node(a, expected_parent=root, expected_prev=root, expected_next=a_a)
    verify_node(a_a, expected_parent=a, expected_prev=a, expected_next=a_b)
    verify_node(a_b, expected_parent=a, expected_prev=a_a, expected_next=a_b_a)
    verify_node(a_b_a, expected_parent=a_b, expected_prev=a_b, expected_next=a_b_b)
    verify_node(a_b_b, expected_parent=a_b, expected_prev=a_b_a, expected_next=b)
    verify_node(b, expected_parent=root, expected_prev=a_b_b, expected_next=c)
    verify_node(c, expected_parent=root, expected_prev=b, expected_next=c_a)
    verify_node(c, expected_parent=root, expected_prev=b, expected_next=c_a)
    verify_node(c_a, expected_parent=c, expected_prev=c, expected_next=c_b)
    verify_node(c_b, expected_parent=c, expected_prev=c_a, expected_next=None)
def empty_context(input_file, fragment_dir, package_manager):
    return Context(base_dir=input_file.parent,
                   fragment_dir=fragment_dir,
                   reference=ApiReference(),
                   package_manager=package_manager,
                   current_document=DocumentTreeNode(input_file),
                   current_package=Package(PackageManager.INPUT_FILES))
def test_document_tree_node__title__remove_formatting(tmp_path, content,
                                                      title):
    adoc_file = tmp_path / "file.adoc"
    adoc_file.write_text(content)

    doc = DocumentTreeNode(adoc_file)
    assert doc.title == title
def test_document_tree_node__title__no_title(tmp_path):
    adoc_file = tmp_path / "file.adoc"
    adoc_file.write_text(
        "My title\n\nOther text.\n\n== Other title\n\nMore text.")

    doc = DocumentTreeNode(adoc_file)
    assert doc.title == "file"
def context(input_file, fragment_dir, api_reference, package_manager):
    c = Context(base_dir=input_file.parent,
                fragment_dir=fragment_dir,
                reference=api_reference,
                package_manager=package_manager,
                current_document=DocumentTreeNode(input_file),
                current_package=Package(PackageManager.INPUT_FILES))
    return c
Beispiel #9
0
def test_include_with_leveloffset(api, context, input_file):
    include_file = input_file.parent / "includes" / "another_file.adoc"
    include_file.parent.mkdir(parents=True)
    include_file.touch()
    context.current_document.children.append(
        DocumentTreeNode(include_file, context.current_document))

    result = api.include("includes/another_file.adoc", leveloffset="-1")
    assert result.startswith("include::")
    assert result.endswith("[leveloffset=-1]")
Beispiel #10
0
def test_docinfo_footer_file__singlepage__included(empty_context, input_file):
    empty_context.register_adoc_file(input_file)

    included_file = input_file.with_name("sub_doc.adoc")
    empty_context.current_document = DocumentTreeNode(
        included_file, empty_context.current_document)
    empty_context.register_adoc_file(included_file)

    footer_file = empty_context.docinfo_footer_file()
    assert footer_file.parent == input_file.parent
    assert footer_file.name == f".asciidoxy.{input_file.stem}-docinfo-footer.html"
Beispiel #11
0
def test_include_absolute_path_multipage(api, context, input_file, multi_page):
    include_file_rel = Path("includes") / "another_file.adoc"
    include_file = input_file.parent / include_file_rel
    include_file.parent.mkdir(parents=True)
    include_file.touch()
    context.current_document.children.append(
        DocumentTreeNode(include_file, context.current_document))

    result = api.include(include_file)
    assert result == f"<<{include_file_rel}#,{include_file_rel}>>"
    assert include_file.with_name(f".asciidoxy.{include_file.name}").is_file()
Beispiel #12
0
def test_include_multipage_with_prefix_text(api, context, input_file,
                                            multi_page):
    prefix = ". "
    include_file_rel = Path("includes") / "another_file.adoc"
    include_file = input_file.parent / include_file_rel
    include_file.parent.mkdir(parents=True)
    include_file.touch()
    context.current_document.children.append(
        DocumentTreeNode(include_file, context.current_document))

    result = api.include(include_file_rel, link_prefix=prefix)
    assert result == f"{prefix}<<{include_file_rel}#,{include_file_rel}>>"
Beispiel #13
0
def test_include_absolute_path(api, context, input_file):
    include_file = input_file.parent / "includes" / "another_file.adoc"
    include_file.parent.mkdir(parents=True)
    include_file.touch()
    context.current_document.children.append(
        DocumentTreeNode(include_file, context.current_document))

    result = api.include(os.fspath(include_file))
    assert result.startswith("include::")
    assert result.endswith("[leveloffset=+1]")

    file_name = input_file.parent / result[9:-16]
    assert file_name.is_file()
    assert file_name.name == ".asciidoxy.another_file.adoc"
def document_tree_three_levels_deep():
    # Test tree:
    #
    #       root
    #        /|\
    #       / | \
    #      /  |  \
    #     /   |   \
    #    a    b    c
    #    /\        /\
    #   /  \      /  \
    # a_a  a_b  c_a  c_b
    #      / \
    #     /   \
    #    /     \
    #  a_b_a  a_b_b
    root_dir = Path("project").resolve()
    root = DocumentTreeNode(root_dir / "index.adoc")
    a = DocumentTreeNode(root_dir / "a.adoc", root)
    root.children.append(a)
    b = DocumentTreeNode(root_dir / "b.adoc", root)
    root.children.append(b)
    c = DocumentTreeNode(root_dir / "c.adoc", root)
    root.children.append(c)
    a_a = DocumentTreeNode(root_dir / "a" / "a_a.adoc", a)
    a.children.append(a_a)
    a_b = DocumentTreeNode(root_dir / "a" / "a_b.adoc", a)
    a.children.append(a_b)
    a_b_a = DocumentTreeNode(root_dir / "a" / "b" / "a_b_a.adoc", a_b)
    a_b.children.append(a_b_a)
    a_b_b = DocumentTreeNode(root_dir / "a" / "b" / "a_b_b.adoc", a_b)
    a_b.children.append(a_b_b)
    c_a = DocumentTreeNode(root_dir / "c" / "c_a.adoc", c)
    c.children.append(c_a)
    c_b = DocumentTreeNode(root_dir / "c" / "c_b.adoc", c)
    c.children.append(c_b)
    return root
Beispiel #15
0
def test_navigation_bar_single_document():
    doc = DocumentTreeNode("/project/index.adoc")
    assert not navigation_bar(doc)
def test_document_tree_node__title__no_file(tmp_path):
    adoc_file = tmp_path / "file.adoc"
    assert not adoc_file.exists()

    doc = DocumentTreeNode(adoc_file)
    assert doc.title == "file"