forked from openai/openai-agents-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_apply_diff.py
More file actions
64 lines (41 loc) · 2.24 KB
/
Copy pathtest_apply_diff.py
File metadata and controls
64 lines (41 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Tests for the V4A diff helper."""
from __future__ import annotations
import pytest
from agents import apply_diff
def test_apply_diff_with_floating_hunk_adds_lines() -> None:
diff = "\n".join(["@@", "+hello", "+world"]) # no trailing newline
assert apply_diff("", diff) == "hello\nworld\n"
def test_apply_diff_with_empty_input_and_crlf_diff_preserves_crlf() -> None:
diff = "\r\n".join(["@@", "+hello", "+world"])
assert apply_diff("", diff) == "hello\r\nworld\r\n"
def test_apply_diff_create_mode_requires_plus_prefix() -> None:
diff = "plain line"
with pytest.raises(ValueError):
apply_diff("", diff, mode="create")
def test_apply_diff_create_mode_preserves_trailing_newline() -> None:
diff = "\n".join(["+hello", "+world", "+"])
assert apply_diff("", diff, mode="create") == "hello\nworld\n"
def test_apply_diff_applies_contextual_replacement() -> None:
input_text = "line1\nline2\nline3\n"
diff = "\n".join(["@@ line1", "-line2", "+updated", " line3"])
assert apply_diff(input_text, diff) == "line1\nupdated\nline3\n"
def test_apply_diff_raises_on_context_mismatch() -> None:
input_text = "one\ntwo\n"
diff = "\n".join(["@@ -1,2 +1,2 @@", " x", "-two", "+2"])
with pytest.raises(ValueError):
apply_diff(input_text, diff)
def test_apply_diff_with_crlf_input_and_lf_diff_preserves_crlf() -> None:
input_text = "line1\r\nline2\r\nline3\r\n"
diff = "\n".join(["@@ line1", "-line2", "+updated", " line3"])
assert apply_diff(input_text, diff) == "line1\r\nupdated\r\nline3\r\n"
def test_apply_diff_with_lf_input_and_crlf_diff_preserves_lf() -> None:
input_text = "line1\nline2\nline3\n"
diff = "\r\n".join(["@@ line1", "-line2", "+updated", " line3"])
assert apply_diff(input_text, diff) == "line1\nupdated\nline3\n"
def test_apply_diff_with_crlf_input_and_crlf_diff_preserves_crlf() -> None:
input_text = "line1\r\nline2\r\nline3\r\n"
diff = "\r\n".join(["@@ line1", "-line2", "+updated", " line3"])
assert apply_diff(input_text, diff) == "line1\r\nupdated\r\nline3\r\n"
def test_apply_diff_create_mode_preserves_crlf_newlines() -> None:
diff = "\r\n".join(["+hello", "+world", "+"])
assert apply_diff("", diff, mode="create") == "hello\r\nworld\r\n"