Skip to content

Commit 5f78a64

Browse files
committed
Refactor patch application tests to use static method
1 parent 119b33a commit 5f78a64

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

tests/test_build_patch.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
1-
from pathlib import Path
2-
31
from style_variant_builder.build import CSLBuilder
42

53

64
def test_apply_patch_success(tmp_path):
7-
# Create a simple template and diff
5+
# Create a simple template and diff that adds a macro
86
template = tmp_path / "template.csl"
97
template.write_text("""<style><info/><macro name='foo'/></style>\n""")
108
diff = tmp_path / "patch.diff"
119
diff.write_text(
12-
"""--- a/template.csl\n+++ b/template.csl\n@@ -1 +1,2 @@\n <style><info/><macro name='foo'/></style>\n+<!-- Added line -->\n"""
10+
"""--- a/template.csl\n+++ b/template.csl\n@@ -1 +1 @@\n-<style><info/><macro name='foo'/></style>\n+<style><info/><macro name='foo'/><macro name='bar'/></style>\n"""
1311
)
14-
builder = CSLBuilder(
15-
templates_dir=tmp_path,
16-
diffs_dir=tmp_path,
17-
output_dir=tmp_path,
18-
development_dir=tmp_path,
19-
style_family="template",
12+
output_dir = tmp_path / "output"
13+
output_dir.mkdir()
14+
15+
# Test the static worker method directly
16+
diff_name, success, message = CSLBuilder._process_single_diff(
17+
diff_path=diff,
18+
template_path=template,
19+
target_output_dir=output_dir,
20+
development_dir=None,
2021
export_development=False,
21-
generate_diffs=False,
22-
group_by_family=False,
2322
)
24-
result = builder._apply_patch(template, diff)
25-
assert result is not None
26-
patched = Path(result).read_text()
27-
assert "Added line" in patched
23+
24+
assert success is True
25+
assert diff_name == "patch.diff"
26+
output_file = output_dir / "patch.csl"
27+
assert output_file.exists()
28+
patched = output_file.read_text()
29+
# Check that the new macro was added
30+
assert 'name="bar"' in patched
31+
# Check that the notice comment was added by the pruner
32+
assert "Style Variant Builder" in patched
2833

2934

3035
def test_apply_patch_failure(tmp_path):
@@ -33,15 +38,17 @@ def test_apply_patch_failure(tmp_path):
3338
template.write_text("<style><info/></style>\n")
3439
diff = tmp_path / "broken.diff"
3540
diff.write_text("this is not a valid diff")
36-
builder = CSLBuilder(
37-
templates_dir=tmp_path,
38-
diffs_dir=tmp_path,
39-
output_dir=tmp_path,
40-
development_dir=tmp_path,
41-
style_family="template",
41+
output_dir = tmp_path / "output"
42+
output_dir.mkdir()
43+
44+
# Test the static worker method directly
45+
diff_name, success, message = CSLBuilder._process_single_diff(
46+
diff_path=diff,
47+
template_path=template,
48+
target_output_dir=output_dir,
49+
development_dir=None,
4250
export_development=False,
43-
generate_diffs=False,
44-
group_by_family=False,
4551
)
46-
result = builder._apply_patch(template, diff)
47-
assert result is None
52+
53+
assert success is False
54+
assert "Failed to apply patch" in message

0 commit comments

Comments
 (0)