Skip to content

Commit 7221f73

Browse files
authoredNov 5, 2024··
refactor: Refactor tests
refactor: Refactor tests
2 parents 7f2f557 + 7534097 commit 7221f73

4 files changed

+384
-341
lines changed
 

‎tests/conftest.py

-21
This file was deleted.

‎tests/test_code_embedding.py

+47-25
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,63 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
15
from src.code_embedding import CodeEmbedder
26
from src.script_content_reader import ScriptContentReader
37
from src.script_metadata_extractor import ScriptMetadataExtractor
48

59

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:
2044
# 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())
2548

2649
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)],
2851
script_metadata_extractor=ScriptMetadataExtractor(),
2952
script_content_reader=ScriptContentReader(),
3053
)
3154

3255
code_embedder()
3356

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()
3759

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()
4062

41-
assert updated_readme_content == expected_readme_content
63+
assert updated_readme_content == expected_readme_content

0 commit comments

Comments
 (0)