-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refactor Code Embedder test
- Loading branch information
Showing
1 changed file
with
47 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,63 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from src.code_embedding import CodeEmbedder | ||
from src.script_content_reader import ScriptContentReader | ||
from src.script_metadata_extractor import ScriptMetadataExtractor | ||
|
||
|
||
def test_code_embedder(tmp_path) -> None: | ||
original_paths = [ | ||
"tests/data/readme0.md", | ||
"tests/data/readme1.md", | ||
"tests/data/readme2.md", | ||
"tests/data/readme3.md", | ||
] | ||
expected_paths = [ | ||
"tests/data/expected_readme0.md", | ||
"tests/data/expected_readme1.md", | ||
"tests/data/expected_readme2.md", | ||
"tests/data/expected_readme3.md", | ||
] | ||
|
||
@pytest.mark.parametrize( | ||
"before_code_embedding_path, after_code_embedding_path", | ||
[ | ||
# Full path and missing path | ||
( | ||
"tests/data/readme0.md", | ||
"tests/data/expected_readme0.md", | ||
), | ||
# Section | ||
( | ||
"tests/data/readme1.md", | ||
"tests/data/expected_readme1.md", | ||
), | ||
# Empty readme | ||
( | ||
"tests/data/readme2.md", | ||
"tests/data/expected_readme2.md", | ||
), | ||
# Objects | ||
( | ||
"tests/data/readme3.md", | ||
"tests/data/expected_readme3.md", | ||
), | ||
], | ||
ids=[ | ||
"full_path_missing_path", | ||
"section", | ||
"empty_readme", | ||
"objects", | ||
], | ||
) | ||
def test_code_embedder( | ||
before_code_embedding_path: str, after_code_embedding_path: str, tmp_path: Path | ||
) -> None: | ||
# Create a temporary copy of the original file | ||
temp_readme_paths = [tmp_path / f"readme{i}.md" for i in range(len(original_paths))] | ||
for original_path, temp_readme_path in zip(original_paths, temp_readme_paths): | ||
with open(original_path) as readme_file: | ||
temp_readme_path.write_text(readme_file.read()) | ||
temp_readme_path = tmp_path / "readme.md" | ||
with open(before_code_embedding_path) as readme_file: | ||
temp_readme_path.write_text(readme_file.read()) | ||
|
||
code_embedder = CodeEmbedder( | ||
readme_paths=[str(temp_readme_path) for temp_readme_path in temp_readme_paths], | ||
readme_paths=[str(temp_readme_path)], | ||
script_metadata_extractor=ScriptMetadataExtractor(), | ||
script_content_reader=ScriptContentReader(), | ||
) | ||
|
||
code_embedder() | ||
|
||
for expected_path, temp_readme_path in zip(expected_paths, temp_readme_paths): | ||
with open(expected_path) as expected_file: | ||
expected_readme_content = expected_file.readlines() | ||
with open(after_code_embedding_path) as expected_file: | ||
expected_readme_content = expected_file.readlines() | ||
|
||
with open(temp_readme_path) as updated_file: | ||
updated_readme_content = updated_file.readlines() | ||
with open(temp_readme_path) as updated_file: | ||
updated_readme_content = updated_file.readlines() | ||
|
||
assert updated_readme_content == expected_readme_content | ||
assert updated_readme_content == expected_readme_content |