Example #1
0
 def test_variable_level_children(self):
     readme = "# Title\nText\n\n## Subtitle\nText\n\n### Subtitle 2\nText\n\n## Subtitle 3\nText"
     gold = g.Node(
         section="$root",
         children=[
             g.Node(
                 section="# Title",
                 body="Text",
                 children=[
                     g.Node(
                         section="## Subtitle",
                         body="Text",
                         children=[
                             g.Node(
                                 section="### Subtitle 2",
                                 body="Text",
                             )
                         ],
                     ),
                     g.Node(
                         section="## Subtitle 3",
                         body="Text",
                     ),
                 ],
             )
         ],
     )
     output = readme_to_graph(readme)
     self.assertEqual(gold, output)
Example #2
0
 def test_increasingly_nested(self):
     readme = "# Title\nText\n\n## Subtitle\nMore text\n\n### Sub-subtitle\neven more text"
     gold = g.Node(
         section="$root",
         children=[
             g.Node(
                 section="# Title",
                 body="Text",
                 children=[
                     g.Node(
                         section="## Subtitle",
                         body="More text",
                         children=[
                             g.Node(
                                 section="### Sub-subtitle",
                                 body="even more text",
                             )
                         ],
                     )
                 ],
             )
         ],
     )
     output = readme_to_graph(readme)
     self.assertEqual(gold, output)
Example #3
0
 def test_section_no_body_no_children(self):
     readme = "# Title"
     gold = g.Node(
         section="$root",
         children=[g.Node(section="# Title")],
     )
     output = readme_to_graph(readme)
     self.assertEqual(gold, output)
Example #4
0
def update_readme_graph(readme_path: str, doc_path: str, level: int) -> dict:
    try:
        readme = open(readme_path, "r").read()
    except FileNotFoundError:
        readme = ""

    readme_graph = readme_to_graph(readme)
    doc_graph = python_to_graph(doc_path, level)
    updated = update(readme_graph, doc_graph)

    return updated
Example #5
0
 def test_mult_same_level_children(self):
     readme = "# Title\nText\n\n## Subtitle\nMore text\n\n## Subtitle 2\neven more text"
     gold = g.Node(
         section="$root",
         children=[
             g.Node(
                 section="# Title",
                 body="Text",
                 children=[
                     g.Node(
                         section="## Subtitle",
                         body="More text",
                     ),
                     g.Node(
                         section="## Subtitle 2",
                         body="even more text",
                     ),
                 ],
             )
         ],
     )
     output = readme_to_graph(readme)
     self.assertEqual(gold, output)
Example #6
0
 def test_null_readme(self):
     readme = ""
     gold = g.Node(section="$root")
     output = readme_to_graph(readme)
     self.assertEqual(gold, output)
Example #7
0
 def test_no_section_with_body(self):
     # TODO: this behavior might need to change
     readme = "Some text"
     gold = {}
     output = readme_to_graph(readme)
     self.assertEqual(gold, output)