|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
1 | 5 | from src.code_embedding import CodeEmbedder
|
2 | 6 | from src.script_content_reader import ScriptContentReader
|
3 | 7 | from src.script_metadata_extractor import ScriptMetadataExtractor
|
4 | 8 |
|
5 | 9 |
|
6 |
| -def test_code_embedder(tmp_path) -> None: |
7 |
| - original_paths = [ |
8 |
| - "tests/data/readme0.md", |
9 |
| - "tests/data/readme1.md", |
10 |
| - "tests/data/readme2.md", |
11 |
| - "tests/data/readme3.md", |
12 |
| - ] |
13 |
| - expected_paths = [ |
14 |
| - "tests/data/expected_readme0.md", |
15 |
| - "tests/data/expected_readme1.md", |
16 |
| - "tests/data/expected_readme2.md", |
17 |
| - "tests/data/expected_readme3.md", |
18 |
| - ] |
19 |
| - |
| 10 | +@pytest.mark.parametrize( |
| 11 | + "before_code_embedding_path, after_code_embedding_path", |
| 12 | + [ |
| 13 | + # Full path and missing path |
| 14 | + ( |
| 15 | + "tests/data/readme0.md", |
| 16 | + "tests/data/expected_readme0.md", |
| 17 | + ), |
| 18 | + # Section |
| 19 | + ( |
| 20 | + "tests/data/readme1.md", |
| 21 | + "tests/data/expected_readme1.md", |
| 22 | + ), |
| 23 | + # Empty readme |
| 24 | + ( |
| 25 | + "tests/data/readme2.md", |
| 26 | + "tests/data/expected_readme2.md", |
| 27 | + ), |
| 28 | + # Objects |
| 29 | + ( |
| 30 | + "tests/data/readme3.md", |
| 31 | + "tests/data/expected_readme3.md", |
| 32 | + ), |
| 33 | + ], |
| 34 | + ids=[ |
| 35 | + "full_path_missing_path", |
| 36 | + "section", |
| 37 | + "empty_readme", |
| 38 | + "objects", |
| 39 | + ], |
| 40 | +) |
| 41 | +def test_code_embedder( |
| 42 | + before_code_embedding_path: str, after_code_embedding_path: str, tmp_path: Path |
| 43 | +) -> None: |
20 | 44 | # Create a temporary copy of the original file
|
21 |
| - temp_readme_paths = [tmp_path / f"readme{i}.md" for i in range(len(original_paths))] |
22 |
| - for original_path, temp_readme_path in zip(original_paths, temp_readme_paths): |
23 |
| - with open(original_path) as readme_file: |
24 |
| - temp_readme_path.write_text(readme_file.read()) |
| 45 | + temp_readme_path = tmp_path / "readme.md" |
| 46 | + with open(before_code_embedding_path) as readme_file: |
| 47 | + temp_readme_path.write_text(readme_file.read()) |
25 | 48 |
|
26 | 49 | code_embedder = CodeEmbedder(
|
27 |
| - readme_paths=[str(temp_readme_path) for temp_readme_path in temp_readme_paths], |
| 50 | + readme_paths=[str(temp_readme_path)], |
28 | 51 | script_metadata_extractor=ScriptMetadataExtractor(),
|
29 | 52 | script_content_reader=ScriptContentReader(),
|
30 | 53 | )
|
31 | 54 |
|
32 | 55 | code_embedder()
|
33 | 56 |
|
34 |
| - for expected_path, temp_readme_path in zip(expected_paths, temp_readme_paths): |
35 |
| - with open(expected_path) as expected_file: |
36 |
| - expected_readme_content = expected_file.readlines() |
| 57 | + with open(after_code_embedding_path) as expected_file: |
| 58 | + expected_readme_content = expected_file.readlines() |
37 | 59 |
|
38 |
| - with open(temp_readme_path) as updated_file: |
39 |
| - updated_readme_content = updated_file.readlines() |
| 60 | + with open(temp_readme_path) as updated_file: |
| 61 | + updated_readme_content = updated_file.readlines() |
40 | 62 |
|
41 |
| - assert updated_readme_content == expected_readme_content |
| 63 | + assert updated_readme_content == expected_readme_content |
0 commit comments