20
from breezy.tests import TestCase, TestCaseWithTransport
20
from breezy.tests import TestCase
22
22
from breezy.iterablefile import IterableFile
23
from breezy.patches import (
38
iter_patched_from_hunks,
23
from breezy.patches import (MalformedLine,
36
iter_patched_from_hunks,
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())
329
class AppliedPatchesTests(TestCaseWithTransport):
331
def test_apply_simple(self):
332
tree = self.make_branch_and_tree('.')
333
self.build_tree_contents([('a', 'a\n')])
336
patch = parse_patch(b"""\
342
""".splitlines(True))
343
with AppliedPatches(tree, [patch]) as newtree:
344
self.assertEqual(b'b\n', newtree.get_file_text('a'))
346
def test_apply_delete(self):
347
tree = self.make_branch_and_tree('.')
348
self.build_tree_contents([('a', 'a\n')])
351
patch = parse_patch(b"""\
356
""".splitlines(True))
357
with AppliedPatches(tree, [patch]) as newtree:
358
self.assertFalse(newtree.has_filename('a'))
360
def test_apply_add(self):
361
tree = self.make_branch_and_tree('.')
362
self.build_tree_contents([('a', 'a\n')])
365
patch = parse_patch(b"""\
370
""".splitlines(True))
371
with AppliedPatches(tree, [patch]) as newtree:
372
self.assertEqual(b'b\n', newtree.get_file_text('b'))