tests
The tests in the repo-guide/tests
directory validate the behavior of the repo-guide
tool. The most interesting file in this directory is test_repo_guide.py
, which contains several tests for the core functionality, especially the prompt construction and end-to-end documentation generation.
Here's a breakdown of some key tests:
-
test_version
: Verifies the CLI tool returns the correct version number. -
test_prompt_construction
: This test checks that the prompt sent to the LLM is constructed correctly for the root directory. It creates a temporary repository with a basic file structure, adds dummy generated readmes, and asserts that the prompt generated byDocGenerator._build_prompt
matches the expected structure, including the correct paths, link URLs, and content for files and subdirectories. -
test_subdirectory_prompt_construction
: Similar to the previous test, but it focuses on generating prompts for a subdirectory (src
). This ensures that relative paths within subdirectories are handled correctly. -
test_file_decoding_failures
: This test ensures that the tool gracefully handles files with encoding issues. It creates files with different encodings (UTF-8, Latin-1, and a broken UTF-16 file) and verifies that only readable files are included in the prompt, preventing errors during processing. -
test_repo_url
,test_repo_url_with_subdirectory
, andtest_ssh_org_repo_url
: These tests validate the construction of the repository URL, which is used to create links to the original files in the repository. They test different scenarios, including cases where the tool is run from a subdirectory and cases where the repository URL is in SSH format. -
test_doc_generation_end_to_end
andtest_doc_generation_src_directory
: These are end-to-end tests that simulate the entire documentation generation process using the CLI. They create a temporary repository, run therepo-guide
command, and verify that the generated documentation files are created in the correct locations with the expected content.test_doc_generation_src_directory
tests the case where the documentation is generated for a subdirectory (src
). They use a mock LLM model to avoid actually calling an external LLM service during testing.