~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_patches.py

  • Committer: Patch Queue Manager
  • Date: 2015-04-21 05:32:33 UTC
  • mfrom: (6602.1.1 bzr.dev)
  • Revision ID: pqm@pqm.ubuntu.com-20150421053233-x63rhby1q3612v2h
(richard-wilbur) (jelmer)Make bzr build reproducible for Debian. (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004 - 2008 Aaron Bentley, Canonical Ltd
2
 
# <aaron.bentley@utoronto.ca>
 
1
# Copyright (C) 2005-2010 Aaron Bentley, Canonical Ltd
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
55
54
        finally:
56
55
            datafile.close()
57
56
 
 
57
    def test_parse_patches_leading_noise(self):
 
58
        # https://bugs.launchpad.net/bzr/+bug/502076
 
59
        # https://code.launchpad.net/~toshio/bzr/allow-dirty-patches/+merge/18854
 
60
        lines = ["diff -pruN commands.py",
 
61
                 "--- orig/commands.py",
 
62
                 "+++ mod/dommands.py"]
 
63
        bits = parse_patches(iter(lines), allow_dirty=True)
 
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
 
58
79
    def testValidPatchHeader(self):
59
80
        """Parse a valid patch header"""
60
81
        lines = "--- orig/commands.py\n+++ mod/dommands.py\n".split('\n')
71
92
    def testValidHunkHeader(self):
72
93
        """Parse a valid hunk header"""
73
94
        header = "@@ -34,11 +50,6 @@\n"
74
 
        hunk = hunk_from_header(header);
 
95
        hunk = hunk_from_header(header)
75
96
        self.assertEqual(hunk.orig_pos, 34)
76
97
        self.assertEqual(hunk.orig_range, 11)
77
98
        self.assertEqual(hunk.mod_pos, 50)
81
102
    def testValidHunkHeader2(self):
82
103
        """Parse a tricky, valid hunk header"""
83
104
        header = "@@ -1 +0,0 @@\n"
84
 
        hunk = hunk_from_header(header);
 
105
        hunk = hunk_from_header(header)
85
106
        self.assertEqual(hunk.orig_pos, 1)
86
107
        self.assertEqual(hunk.orig_range, 1)
87
108
        self.assertEqual(hunk.mod_pos, 0)
110
131
        self.makeMalformed("@@ -34,11 +50,6.5 @@\n")
111
132
        self.makeMalformed("@@ -34,11 +50,-6 @@\n")
112
133
 
113
 
    def lineThing(self,text, type):
 
134
    def lineThing(self, text, type):
114
135
        line = parse_line(text)
115
136
        self.assertIsInstance(line, type)
116
137
        self.assertEqual(str(line), text)
139
160
        i = difference_index(patchtext, pstr)
140
161
        if i is not None:
141
162
            print "%i: \"%s\" != \"%s\"" % (i, patchtext[i], pstr[i])
142
 
        self.assertEqual (patchtext, str(patch))
 
163
        self.assertEqual(patchtext, str(patch))
143
164
 
144
165
    def testAll(self):
145
166
        """Test parsing a whole patch"""
154
175
        self.assertContainsRe(patches[0].oldname, '^bar\t')
155
176
        self.assertContainsRe(patches[0].newname, '^qux\t')
156
177
        self.assertContainsRe(str(patches[0]),
157
 
                                  'Binary files bar\t.* and qux\t.* differ\n')
 
178
                              'Binary files bar\t.* and qux\t.* differ\n')
158
179
 
159
180
    def test_parse_binary_after_normal(self):
160
181
        patches = parse_patches(self.data_lines("binary-after-normal.patch"))
163
184
        self.assertContainsRe(patches[1].oldname, '^bar\t')
164
185
        self.assertContainsRe(patches[1].newname, '^qux\t')
165
186
        self.assertContainsRe(str(patches[1]),
166
 
                                  'Binary files bar\t.* and qux\t.* differ\n')
 
187
                              'Binary files bar\t.* and qux\t.* differ\n')
167
188
 
168
189
    def test_roundtrip_binary(self):
169
190
        patchtext = ''.join(self.data_lines("binary.patch"))
221
242
            mod_lines = list(self.datafile(mod))
222
243
 
223
244
            patched_file = IterableFile(iter_patched(orig_lines, patch))
224
 
            lines = []
225
245
            count = 0
226
246
            for patch_line in patched_file:
227
247
                self.assertEqual(patch_line, mod_lines[count])
232
252
        binary_lines = self.data_lines('binary.patch')
233
253
        e = self.assertRaises(BinaryFiles, iter_patched, [], binary_lines)
234
254
 
235
 
 
236
255
    def test_iter_patched_from_hunks(self):
237
256
        """Test a few patch files, and make sure they work."""
238
257
        files = [
249
268
            mod_lines = list(self.datafile(mod))
250
269
            iter_patched = iter_patched_from_hunks(orig_lines, parsed.hunks)
251
270
            patched_file = IterableFile(iter_patched)
252
 
            lines = []
253
271
            count = 0
254
272
            for patch_line in patched_file:
255
273
                self.assertEqual(patch_line, mod_lines[count])