7
7
import unittest
8
8
9
9
10
+ def _apply (src , diff_text , reverse = False , use_patch = False ):
11
+ diff = next (wtp .parse_patch (diff_text ))
12
+ return wtp .apply .apply_diff (diff , src , reverse , use_patch )
13
+
14
+
15
+ def _apply_r (src , diff_text , reverse = True , use_patch = False ):
16
+ return _apply (src , diff_text , reverse , use_patch )
17
+
18
+
10
19
class ApplyTestSuite (unittest .TestCase ):
11
20
"""Basic test cases."""
12
21
@@ -27,38 +36,29 @@ def test_diff_default(self):
27
36
with open ('tests/casefiles/diff-default.diff' ) as f :
28
37
diff_text = f .read ()
29
38
30
- diff = next (wtp .parse_patch (diff_text ))
31
-
32
- new_text = wtp .apply .apply_diff (diff , self .lao )
33
- self .assertEqual (new_text , self .tzu )
39
+ self .assertEqual (_apply (self .lao , diff_text ), self .tzu )
40
+ self .assertEqual (_apply_r (self .tzu , diff_text ), self .lao )
34
41
35
42
def test_diff_context (self ):
36
43
with open ('tests/casefiles/diff-context.diff' ) as f :
37
44
diff_text = f .read ()
38
45
39
- diff = next (wtp .parse_patch (diff_text ))
40
-
41
- new_text = wtp .apply .apply_diff (diff , self .lao )
42
- self .assertEqual (new_text , self .tzu )
46
+ self .assertEqual (_apply (self .lao , diff_text ), self .tzu )
47
+ self .assertEqual (_apply_r (self .tzu , diff_text ), self .lao )
43
48
44
49
def test_diff_unified (self ):
45
50
with open ('tests/casefiles/diff-unified.diff' ) as f :
46
51
diff_text = f .read ()
47
52
48
- diff = next (wtp .parse_patch (diff_text ))
49
-
50
- new_text = wtp .apply .apply_diff (diff , self .lao )
51
-
52
- self .assertEqual (new_text , self .tzu )
53
+ self .assertEqual (_apply (self .lao , diff_text ), self .tzu )
54
+ self .assertEqual (_apply_r (self .tzu , diff_text ), self .lao )
53
55
54
56
def test_diff_unified_bad (self ):
55
57
with open ('tests/casefiles/diff-unified-bad.diff' ) as f :
56
58
diff_text = f .read ()
57
59
58
- diff = next (wtp .parse_patch (diff_text ))
59
-
60
60
with assert_raises (exceptions .ApplyException ) as ec :
61
- wtp . apply . apply_diff ( diff , self .lao )
61
+ _apply ( self .lao , diff_text )
62
62
63
63
e = ec .exception
64
64
e_str = str (e )
@@ -71,10 +71,8 @@ def test_diff_unified_bad2(self):
71
71
with open ('tests/casefiles/diff-unified-bad2.diff' ) as f :
72
72
diff_text = f .read ()
73
73
74
- diff = next (wtp .parse_patch (diff_text ))
75
-
76
74
with assert_raises (exceptions .ApplyException ) as ec :
77
- wtp . apply . apply_diff ( diff , self .lao )
75
+ _apply ( self .lao , diff_text )
78
76
79
77
e = ec .exception
80
78
e_str = str (e )
@@ -87,10 +85,8 @@ def test_diff_unified_bad_backward(self):
87
85
with open ('tests/casefiles/diff-unified-bad2.diff' ) as f :
88
86
diff_text = f .read ()
89
87
90
- diff = next (wtp .parse_patch (diff_text ))
91
-
92
88
with assert_raises (exceptions .ApplyException ) as ec :
93
- wtp . apply . apply_diff ( diff , self .tzu )
89
+ _apply ( self .tzu , diff_text )
94
90
95
91
e = ec .exception
96
92
e_str = str (e )
@@ -103,10 +99,8 @@ def test_diff_unified_bad_empty_source(self):
103
99
with open ('tests/casefiles/diff-unified-bad2.diff' ) as f :
104
100
diff_text = f .read ()
105
101
106
- diff = next (wtp .parse_patch (diff_text ))
107
-
108
102
with assert_raises (exceptions .ApplyException ) as ec :
109
- wtp . apply . apply_diff ( diff , '' )
103
+ _apply ( '' , diff_text )
110
104
111
105
e = ec .exception
112
106
e_str = str (e )
@@ -119,39 +113,42 @@ def test_diff_unified_patchutil(self):
119
113
with open ('tests/casefiles/diff-unified.diff' ) as f :
120
114
diff_text = f .read ()
121
115
122
- diff = next (wtp .parse_patch (diff_text ))
116
+ self .assertEqual (
117
+ _apply (self .lao , diff_text , use_patch = True ),
118
+ (self .tzu , None ),
119
+ )
120
+ self .assertEqual (
121
+ _apply_r (self .tzu , diff_text , use_patch = True ),
122
+ (self .lao , None ),
123
+ )
123
124
124
- new_text = wtp . apply . apply_diff ( diff , self .lao , use_patch = True )
125
+ new_text = _apply ( self .lao , diff_text , use_patch = True )
125
126
self .assertEqual (new_text , (self .tzu , None ))
126
127
128
+ def _do_apply ():
129
+ return _apply (['' ] + self .lao , diff_text , use_patch = True )
130
+
127
131
self .assertRaises (
128
132
exceptions .ApplyException ,
129
- wtp .apply .apply_diff ,
130
- diff ,
131
- ['' ] + self .lao ,
132
- use_patch = True ,
133
+ _do_apply ,
133
134
)
134
135
135
136
def test_diff_rcs (self ):
136
137
with open ('tests/casefiles/diff-rcs.diff' ) as f :
137
138
diff_text = f .read ()
138
139
139
- diff = next ( wtp . parse_patch ( diff_text ) )
140
+ new_text = _apply ( self . lao , diff_text )
140
141
141
- new_text = wtp .apply .apply_diff (diff , self .lao )
142
142
self .assertEqual (new_text , self .tzu )
143
143
144
144
def test_diff_ed (self ):
145
- self .maxDiff = None
146
145
with open ('tests/casefiles/diff-ed.diff' ) as f :
147
146
diff_text = f .read ()
148
147
149
- diff = next (wtp .parse_patch (diff_text ))
150
-
151
- new_text = wtp .apply .apply_diff (diff , self .lao )
148
+ new_text = _apply (self .lao , diff_text )
152
149
self .assertEqual (self .tzu , new_text )
153
150
154
- new_text = wtp . apply . apply_diff ( diff , self .lao , use_patch = True )
151
+ new_text = _apply ( self .lao , diff_text , use_patch = True )
155
152
self .assertEqual (new_text , (self .tzu , None ))
156
153
157
154
0 commit comments