~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_patches.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-06 20:42:40 UTC
  • mto: This revision was merged to the branch mainline in revision 4088.
  • Revision ID: john@arbash-meinel.com-20090306204240-mzjavv31z3gu1x7i
Fix a small bug in setup.py when an extension fails to build

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
 
19
19
import os.path
24
24
from bzrlib.patches import (MalformedLine,
25
25
                            MalformedHunkHeader,
26
26
                            MalformedPatchHeader,
27
 
                            BinaryPatch,
28
 
                            BinaryFiles,
29
 
                            Patch,
30
27
                            ContextLine,
31
28
                            InsertLine,
32
29
                            RemoveLine,
48
45
                                 "test_patches_data", filename)
49
46
        return file(data_path, "rb")
50
47
 
51
 
    def data_lines(self, filename):
52
 
        datafile = self.datafile(filename)
53
 
        try:
54
 
            return datafile.readlines()
55
 
        finally:
56
 
            datafile.close()
57
 
 
58
48
    def testValidPatchHeader(self):
59
49
        """Parse a valid patch header"""
60
50
        lines = "--- orig/commands.py\n+++ mod/dommands.py\n".split('\n')
146
136
        patchtext = self.datafile("patchtext.patch").read()
147
137
        self.compare_parsed(patchtext)
148
138
 
149
 
    def test_parse_binary(self):
150
 
        """Test parsing a whole patch"""
151
 
        patches = parse_patches(self.data_lines("binary.patch"))
152
 
        self.assertIs(BinaryPatch, patches[0].__class__)
153
 
        self.assertIs(Patch, patches[1].__class__)
154
 
        self.assertContainsRe(patches[0].oldname, '^bar\t')
155
 
        self.assertContainsRe(patches[0].newname, '^qux\t')
156
 
        self.assertContainsRe(str(patches[0]),
157
 
                                  'Binary files bar\t.* and qux\t.* differ\n')
158
 
 
159
 
    def test_parse_binary_after_normal(self):
160
 
        patches = parse_patches(self.data_lines("binary-after-normal.patch"))
161
 
        self.assertIs(BinaryPatch, patches[1].__class__)
162
 
        self.assertIs(Patch, patches[0].__class__)
163
 
        self.assertContainsRe(patches[1].oldname, '^bar\t')
164
 
        self.assertContainsRe(patches[1].newname, '^qux\t')
165
 
        self.assertContainsRe(str(patches[1]),
166
 
                                  'Binary files bar\t.* and qux\t.* differ\n')
167
 
 
168
 
    def test_roundtrip_binary(self):
169
 
        patchtext = ''.join(self.data_lines("binary.patch"))
170
 
        patches = parse_patches(patchtext.splitlines(True))
171
 
        self.assertEqual(patchtext, ''.join(str(p) for p in patches))
172
 
 
173
139
    def testInit(self):
174
140
        """Handle patches missing half the position, range tuple"""
175
141
        patchtext = \
228
194
                count += 1
229
195
            self.assertEqual(count, len(mod_lines))
230
196
 
231
 
    def test_iter_patched_binary(self):
232
 
        binary_lines = self.data_lines('binary.patch')
233
 
        e = self.assertRaises(BinaryFiles, iter_patched, [], binary_lines)
234
 
 
235
 
 
236
197
    def test_iter_patched_from_hunks(self):
237
198
        """Test a few patch files, and make sure they work."""
238
199
        files = [