~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_patches.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-06-30 18:28:17 UTC
  • mfrom: (5967.10.2 test-cat)
  • Revision ID: pqm@pqm.ubuntu.com-20110630182817-83a5q9r9rxfkdn8r
(mbp) don't use subprocesses for testing cat (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
        # https://bugs.launchpad.net/bzr/+bug/502076
59
59
        # https://code.launchpad.net/~toshio/bzr/allow-dirty-patches/+merge/18854
60
60
        lines = ["diff -pruN commands.py",
61
 
                 "--- orig/commands.py",
62
 
                 "+++ mod/dommands.py"]
 
61
            "--- orig/commands.py",
 
62
            "+++ mod/dommands.py"]
63
63
        bits = parse_patches(iter(lines), allow_dirty=True)
64
64
 
65
 
    def test_preserve_dirty_head(self):
66
 
        """Parse a patch containing a dirty header, and preserve lines"""
67
 
        lines = ["=== added directory 'foo/bar'\n",
68
 
                 "=== modified file 'orig/commands.py'\n",
69
 
                 "--- orig/commands.py\n",
70
 
                 "+++ mod/dommands.py\n"]
71
 
        patches = parse_patches(
72
 
            lines.__iter__(), allow_dirty=True, keep_dirty=True)
73
 
        self.assertEqual(patches[0]['dirty_head'],
74
 
                         ["=== added directory 'foo/bar'\n",
75
 
                          "=== modified file 'orig/commands.py'\n"])
76
 
        self.assertEqual(patches[0]['patch'].get_header().splitlines(True),
77
 
                         ["--- orig/commands.py\n", "+++ mod/dommands.py\n"])
78
 
 
79
65
    def testValidPatchHeader(self):
80
66
        """Parse a valid patch header"""
81
67
        lines = "--- orig/commands.py\n+++ mod/dommands.py\n".split('\n')
92
78
    def testValidHunkHeader(self):
93
79
        """Parse a valid hunk header"""
94
80
        header = "@@ -34,11 +50,6 @@\n"
95
 
        hunk = hunk_from_header(header)
 
81
        hunk = hunk_from_header(header);
96
82
        self.assertEqual(hunk.orig_pos, 34)
97
83
        self.assertEqual(hunk.orig_range, 11)
98
84
        self.assertEqual(hunk.mod_pos, 50)
102
88
    def testValidHunkHeader2(self):
103
89
        """Parse a tricky, valid hunk header"""
104
90
        header = "@@ -1 +0,0 @@\n"
105
 
        hunk = hunk_from_header(header)
 
91
        hunk = hunk_from_header(header);
106
92
        self.assertEqual(hunk.orig_pos, 1)
107
93
        self.assertEqual(hunk.orig_range, 1)
108
94
        self.assertEqual(hunk.mod_pos, 0)
131
117
        self.makeMalformed("@@ -34,11 +50,6.5 @@\n")
132
118
        self.makeMalformed("@@ -34,11 +50,-6 @@\n")
133
119
 
134
 
    def lineThing(self, text, type):
 
120
    def lineThing(self,text, type):
135
121
        line = parse_line(text)
136
122
        self.assertIsInstance(line, type)
137
123
        self.assertEqual(str(line), text)
160
146
        i = difference_index(patchtext, pstr)
161
147
        if i is not None:
162
148
            print "%i: \"%s\" != \"%s\"" % (i, patchtext[i], pstr[i])
163
 
        self.assertEqual(patchtext, str(patch))
 
149
        self.assertEqual (patchtext, str(patch))
164
150
 
165
151
    def testAll(self):
166
152
        """Test parsing a whole patch"""
175
161
        self.assertContainsRe(patches[0].oldname, '^bar\t')
176
162
        self.assertContainsRe(patches[0].newname, '^qux\t')
177
163
        self.assertContainsRe(str(patches[0]),
178
 
                              'Binary files bar\t.* and qux\t.* differ\n')
 
164
                                  'Binary files bar\t.* and qux\t.* differ\n')
179
165
 
180
166
    def test_parse_binary_after_normal(self):
181
167
        patches = parse_patches(self.data_lines("binary-after-normal.patch"))
184
170
        self.assertContainsRe(patches[1].oldname, '^bar\t')
185
171
        self.assertContainsRe(patches[1].newname, '^qux\t')
186
172
        self.assertContainsRe(str(patches[1]),
187
 
                              'Binary files bar\t.* and qux\t.* differ\n')
 
173
                                  'Binary files bar\t.* and qux\t.* differ\n')
188
174
 
189
175
    def test_roundtrip_binary(self):
190
176
        patchtext = ''.join(self.data_lines("binary.patch"))
242
228
            mod_lines = list(self.datafile(mod))
243
229
 
244
230
            patched_file = IterableFile(iter_patched(orig_lines, patch))
 
231
            lines = []
245
232
            count = 0
246
233
            for patch_line in patched_file:
247
234
                self.assertEqual(patch_line, mod_lines[count])
252
239
        binary_lines = self.data_lines('binary.patch')
253
240
        e = self.assertRaises(BinaryFiles, iter_patched, [], binary_lines)
254
241
 
 
242
 
255
243
    def test_iter_patched_from_hunks(self):
256
244
        """Test a few patch files, and make sure they work."""
257
245
        files = [
268
256
            mod_lines = list(self.datafile(mod))
269
257
            iter_patched = iter_patched_from_hunks(orig_lines, parsed.hunks)
270
258
            patched_file = IterableFile(iter_patched)
 
259
            lines = []
271
260
            count = 0
272
261
            for patch_line in patched_file:
273
262
                self.assertEqual(patch_line, mod_lines[count])