Test the RepoLoader class.
()
| 5 | |
| 6 | |
| 7 | def test_repo_loader() -> None: |
| 8 | """ |
| 9 | Test the RepoLoader class. |
| 10 | """ |
| 11 | url = "https://github.com/eugeneyan/testing-ml" |
| 12 | repo_loader = RepoLoader(url, config=RepoLoaderConfig()) |
| 13 | |
| 14 | # directly create Document objects from github repo url |
| 15 | # (uses many GitHub API calls, not recommended; |
| 16 | # use load() instead, which clones if needed, then loads from local folder) |
| 17 | docs = repo_loader.load_docs_from_github(10, depth=0, lines=20) |
| 18 | assert len(docs) > 0 |
| 19 | assert len(docs) <= 10 |
| 20 | for doc in docs: |
| 21 | assert len(doc.content.split("\n")) <= 20 |
| 22 | |
| 23 | # tree structure direct from github; again not recommended if easy to clone. |
| 24 | tree = repo_loader.load_tree_from_github(depth=1, lines=3) |
| 25 | assert len(tree) > 0 |
| 26 | |
| 27 | # tree, docs from local clone (if exists, else clone first) |
| 28 | tree, docs = repo_loader.load(depth=1, lines=5) |
| 29 | assert len(tree) > 0 |
| 30 | assert len(docs) > 0, f"No docs loaded from repo {repo_loader.clone_path}" |
| 31 | |
| 32 | # test static fn that loads from a local folder; |
| 33 | # this is a general fn that can be used to load from any folder, |
| 34 | # not necessarily a git repo, or not necessarily even code, e.g., |
| 35 | # could be any folder of text files |
| 36 | tree, docs = RepoLoader.load_from_folder( |
| 37 | repo_loader.clone_path, |
| 38 | depth=1, |
| 39 | lines=5, |
| 40 | file_types=["md", "txt", "toml"], |
| 41 | exclude_dirs=[".git", "tests"], |
| 42 | ) |
| 43 | assert len(tree) > 0 |
| 44 | assert len(docs) > 0 |
| 45 | |
| 46 | # use a different fn to just load documents from folder |
| 47 | docs = RepoLoader.get_documents( |
| 48 | repo_loader.clone_path, |
| 49 | depth=1, |
| 50 | lines=5, |
| 51 | file_types=["md", "txt", "toml"], |
| 52 | exclude_dirs=[".git", "tests"], |
| 53 | ) |
| 54 | assert len(docs) > 0 |
| 55 | |
| 56 | # test making doc from single file path |
| 57 | docs = RepoLoader.get_documents( |
| 58 | Path(repo_loader.clone_path) / "pyproject.toml", |
| 59 | depth=1, |
| 60 | lines=5, |
| 61 | file_types=["md", "txt", "toml"], |
| 62 | exclude_dirs=[".git", "tests"], |
| 63 | ) |
| 64 | assert len(docs) == 1 |
nothing calls this directly
no test coverage detected
searching dependent graphs…