/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 breezy/tests/test_patches.py

  • Committer: Jelmer Vernooij
  • Date: 2019-06-03 23:48:08 UTC
  • mfrom: (7316 work)
  • mto: This revision was merged to the branch mainline in revision 7328.
  • Revision ID: jelmer@jelmer.uk-20190603234808-15yk5c7054tj8e2b
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import os.path
19
19
 
20
 
from breezy.tests import TestCase, TestCaseWithTransport
 
20
from breezy.tests import TestCase
21
21
 
22
22
from breezy.iterablefile import IterableFile
23
 
from breezy.patches import (
24
 
    AppliedPatches,
25
 
    MalformedLine,
26
 
    MalformedHunkHeader,
27
 
    MalformedPatchHeader,
28
 
    BinaryPatch,
29
 
    BinaryFiles,
30
 
    Patch,
31
 
    ContextLine,
32
 
    InsertLine,
33
 
    RemoveLine,
34
 
    difference_index,
35
 
    get_patch_names,
36
 
    hunk_from_header,
37
 
    iter_patched,
38
 
    iter_patched_from_hunks,
39
 
    parse_line,
40
 
    parse_patch,
41
 
    parse_patches,
42
 
    NO_NL,
43
 
    )
 
23
from breezy.patches import (MalformedLine,
 
24
                            MalformedHunkHeader,
 
25
                            MalformedPatchHeader,
 
26
                            BinaryPatch,
 
27
                            BinaryFiles,
 
28
                            Patch,
 
29
                            ContextLine,
 
30
                            InsertLine,
 
31
                            RemoveLine,
 
32
                            difference_index,
 
33
                            get_patch_names,
 
34
                            hunk_from_header,
 
35
                            iter_patched,
 
36
                            iter_patched_from_hunks,
 
37
                            parse_line,
 
38
                            parse_patch,
 
39
                            parse_patches,
 
40
                            NO_NL)
44
41
 
45
42
 
46
43
class PatchesTester(TestCase):
324
321
        """Test the added, removed and hunks values for stats_values."""
325
322
        patch = parse_patch(self.datafile("diff"))
326
323
        self.assertEqual((299, 407, 48), patch.stats_values())
327
 
 
328
 
 
329
 
class AppliedPatchesTests(TestCaseWithTransport):
330
 
 
331
 
    def test_apply_simple(self):
332
 
        tree = self.make_branch_and_tree('.')
333
 
        self.build_tree_contents([('a', 'a\n')])
334
 
        tree.add('a')
335
 
        tree.commit('Add a')
336
 
        patch = parse_patch(b"""\
337
 
--- a/a
338
 
+++ a/a
339
 
@@ -1 +1 @@
340
 
-a
341
 
+b
342
 
""".splitlines(True))
343
 
        with AppliedPatches(tree, [patch]) as newtree:
344
 
            self.assertEqual(b'b\n', newtree.get_file_text('a'))
345
 
 
346
 
    def test_apply_delete(self):
347
 
        tree = self.make_branch_and_tree('.')
348
 
        self.build_tree_contents([('a', 'a\n')])
349
 
        tree.add('a')
350
 
        tree.commit('Add a')
351
 
        patch = parse_patch(b"""\
352
 
--- a/a
353
 
+++ /dev/null
354
 
@@ -1 +0,0 @@
355
 
-a
356
 
""".splitlines(True))
357
 
        with AppliedPatches(tree, [patch]) as newtree:
358
 
            self.assertFalse(newtree.has_filename('a'))
359
 
 
360
 
    def test_apply_add(self):
361
 
        tree = self.make_branch_and_tree('.')
362
 
        self.build_tree_contents([('a', 'a\n')])
363
 
        tree.add('a')
364
 
        tree.commit('Add a')
365
 
        patch = parse_patch(b"""\
366
 
--- /dev/null
367
 
+++ a/b
368
 
@@ -0,0 +1 @@
369
 
+b
370
 
""".splitlines(True))
371
 
        with AppliedPatches(tree, [patch]) as newtree:
372
 
            self.assertEqual(b'b\n', newtree.get_file_text('b'))