def generate_file_toc(self, directory: str, file_path: str) -> str: """ Generate the table of contents for the given file path. Arguments: directory: Absolute path to the `docs/` directory. file_path: Relative path to a Markdown file. Returns: The generated file TOC. Example: (markdown) - [<file_title>](<absolute_URL_path_to_this_title) - [<heading_level_1](<abs_URL_path_to_this_title) """ validated_file_path = self.validate_file_path(directory, file_path) headings = self.find_headings(validated_file_path) file_toc = "" url_path = Base().repository_prefix + "docs/" + file_path for heading in headings: file_toc += self.create_bullet_point(heading, url_path) + "\n" return file_toc
def test_modify_link(): original_link = \ "[source](" + Base().repository_prefix + "test_data/module.py)" modified_link = "-> test_data/module.py" colored_link = COLORED._modify_link(original_link) assert modified_link in colored_link assert "97;40m" in colored_link
def test_get_documentation_in_alphabetical_order(): file_metadata = Base.read_file("test_data/module.py") doc = doksit._get_documentation(file_metadata) assert doc.index("class Bar") < doc.index("class Foo") assert doc.index("property variable") < doc.index("method method") assert doc.index("function another_function") \ < doc.index("function function")
def test_modify_link(): smooth = SmoothHighlighter("blabla") original_link = \ "[source](" + Base().repository_prefix + "test_data/module.py)" modified_link = "-> test_data/module.py" assert modified_link == smooth._modify_link(original_link)
def test_generate_file_toc(): directory = os.path.join(os.getcwd(), "docs") file_path = "example.md" result = toc.generate_file_toc(directory, file_path) url = Base().repository_prefix + "docs/" + file_path assert "- [F](" + url + "#f" + ")" in result
def test_get_documentation_for_module_with_template_variables(): file_metadata = Base.read_file("test_data/named_objects_a.py") doc = doksit._get_documentation(file_metadata) assert "test_data.named_objects_b" not in doc assert "## Blabla" in doc
def test_get_documentation_for_blank_file(): file_metadata = Base.read_file("test_data/blank.py") doc = doksit._get_documentation(file_metadata) assert doc is None
import subprocess import tempfile import pytest import yaml from doksit.cli import api from doksit.models import (Base, BRANCH_NAME_REGEX, CLASS_REGEX, FUNCTION_REGEX, METHOD_REGEX, REPOSITORY_URL_REGEX, STATIC_METHOD_REGEX, VARIABLE_REGEX) from tests.test_data import module from tests.test_data.module import Foo base = Base() def test_get_api_documentation(): assert not base.get_api_documentation() ############################################################################### def test_valid_config_load(): with open(".doksit.yml", "w") as file: file.write("docstring: doksit") assert base.config == {"docstring": "doksit"}
def file_metadata(): return Base.read_file("test_data/module.py")