/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_patches.py

  • Committer: Martin Pool
  • Date: 2008-04-24 07:22:53 UTC
  • mto: This revision was merged to the branch mainline in revision 3415.
  • Revision ID: mbp@sourcefrog.net-20080424072253-opmjij7xfy38w27f
Remove every assert statement from bzrlib!

Depending on the context they are:

 * turned into an explicit if/raise of either AssertionError 
   or something more specific -- particularly where they protect
   programming interfaces, complex invariants, or data file integrity
 * removed, if they're redundant with a later check, not protecting
   a meaningful invariant
 * turned into a selftest method on tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
                            parse_patches)
36
36
 
37
37
 
 
38
# XXX: Is there a good reason this uses unittest's test case rather than the
 
39
# bzrlib one?
 
40
 
38
41
class PatchesTester(unittest.TestCase):
39
42
    def datafile(self, filename):
40
43
        data_path = os.path.join(os.path.dirname(__file__), 
45
48
        """Parse a valid patch header"""
46
49
        lines = "--- orig/commands.py\n+++ mod/dommands.py\n".split('\n')
47
50
        (orig, mod) = get_patch_names(lines.__iter__())
48
 
        assert(orig == "orig/commands.py")
49
 
        assert(mod == "mod/dommands.py")
 
51
        self.assertEqual(orig, "orig/commands.py")
 
52
        self.assertEqual(mod, "mod/dommands.py")
50
53
 
51
54
    def testInvalidPatchHeader(self):
52
55
        """Parse an invalid patch header"""
58
61
        """Parse a valid hunk header"""
59
62
        header = "@@ -34,11 +50,6 @@\n"
60
63
        hunk = hunk_from_header(header);
61
 
        assert (hunk.orig_pos == 34)
62
 
        assert (hunk.orig_range == 11)
63
 
        assert (hunk.mod_pos == 50)
64
 
        assert (hunk.mod_range == 6)
65
 
        assert (str(hunk) == header)
 
64
        self.assertEqual(hunk.orig_pos, 34)
 
65
        self.assertEqual(hunk.orig_range, 11)
 
66
        self.assertEqual(hunk.mod_pos, 50)
 
67
        self.assertEqual(hunk.mod_range, 6)
 
68
        self.assertEqual(str(hunk), header)
66
69
 
67
70
    def testValidHunkHeader2(self):
68
71
        """Parse a tricky, valid hunk header"""
69
72
        header = "@@ -1 +0,0 @@\n"
70
73
        hunk = hunk_from_header(header);
71
 
        assert (hunk.orig_pos == 1)
72
 
        assert (hunk.orig_range == 1)
73
 
        assert (hunk.mod_pos == 0)
74
 
        assert (hunk.mod_range == 0)
75
 
        assert (str(hunk) == header)
 
74
        self.assertEqual(hunk.orig_pos, 1)
 
75
        self.assertEqual(hunk.orig_range, 1)
 
76
        self.assertEqual(hunk.mod_pos, 0)
 
77
        self.assertEqual(hunk.mod_range, 0)
 
78
        self.assertEqual(str(hunk), header)
76
79
 
77
80
    def testPDiff(self):
78
81
        """Parse a hunk header produced by diff -p"""
160
163
                    if line.contents != next:
161
164
                        sys.stdout.write(" orig:%spatch:%s" % (next,
162
165
                                         line.contents))
163
 
                    assert(line.contents == next)
 
166
                    self.assertEqual(line.contents, next)
164
167
        self.assertRaises(StopIteration, rem_iter.next)
165
168
 
166
169
    def testPatching(self):
188
191
    def testFirstLineRenumber(self):
189
192
        """Make sure we handle lines at the beginning of the hunk"""
190
193
        patch = parse_patch(self.datafile("insert_top.patch"))
191
 
        assert (patch.pos_in_mod(0)==1)
 
194
        self.assertEqual(patch.pos_in_mod(0), 1)
192
195
 
193
196
    def testParsePatches(self):
194
197
        """Make sure file names can be extracted from tricky unified diffs"""
224
227
        patch_files = []
225
228
        for patch in patches:
226
229
            patch_files.append((patch.oldname, patch.newname))
227
 
        assert (patch_files == filenames)
 
230
        self.assertEqual(patch_files, filenames)
228
231
            
229
232
def test():
230
233
    patchesTestSuite = unittest.makeSuite(PatchesTester,'test')