~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge_directive.py

  • Committer: Daniel Watkins
  • Date: 2007-07-31 10:33:33 UTC
  • mto: (2687.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 2689.
  • Revision ID: d.m.watkins@warwick.ac.uk-20070731103333-sdelcaazn0fxgaf3
Added tests for ExtendedTestResult.wasStrictlySuccessful.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
import re
18
17
 
19
18
from bzrlib import (
20
19
    errors,
32
31
#\x20
33
32
booga"""
34
33
 
35
 
OUTPUT1_2 = """# Bazaar merge directive format 2 (Bazaar 0.90)
 
34
OUTPUT1_2 = """# Bazaar merge directive format 2 (Bazaar 0.19)
36
35
# revision_id: example:
37
36
# target_branch: http://example.com
38
37
# testament_sha1: sha
52
51
#\x20
53
52
booga"""
54
53
 
55
 
OUTPUT2_2 = """# Bazaar merge directive format 2 (Bazaar 0.90)
 
54
OUTPUT2_2 = """# Bazaar merge directive format 2 (Bazaar 0.19)
56
55
# revision_id: example:
57
56
# target_branch: http://example.com
58
57
# testament_sha1: sha
97
96
 
98
97
Aaron
99
98
 
100
 
# Bazaar merge directive format 2 (Bazaar 0.90)\r
101
 
# revision_id: example:
102
 
# target_branch: http://example.com
103
 
# testament_sha1: sha
104
 
# timestamp: 1970-01-01 00:09:33 +0002
105
 
# source_branch: http://example.org
106
 
# base_revision_id: null:
107
 
# message: Hi mom!
108
 
#\x20
109
 
# Begin patch
110
 
booga""".splitlines(True)
111
 
 
112
 
 
113
 
INPUT1_2_OLD = """
114
 
I was thinking today about creating a merge directive.
115
 
 
116
 
So I did.
117
 
 
118
 
Here it is.
119
 
 
120
 
(I've pasted it in the body of this message)
121
 
 
122
 
Aaron
123
 
 
124
99
# Bazaar merge directive format 2 (Bazaar 0.19)\r
125
100
# revision_id: example:
126
101
# target_branch: http://example.com
134
109
booga""".splitlines(True)
135
110
 
136
111
 
137
 
OLD_DIRECTIVE_2 = """# Bazaar merge directive format 2 (Bazaar 0.19)
138
 
# revision_id: abentley@panoramicfeedback.com-20070807234458-\
139
 
#   nzhkoyza56lan7z5
140
 
# target_branch: http://panoramicfeedback.com/opensource/bzr/repo\
141
 
#   /bzr.ab
142
 
# testament_sha1: d825a5cdb267a90ec2ba86b00895f3d8a9bed6bf
143
 
# timestamp: 2007-08-10 16:15:02 -0400
144
 
# source_branch: http://panoramicfeedback.com/opensource/bzr/repo\
145
 
#   /bzr.ab
146
 
# base_revision_id: abentley@panoramicfeedback.com-20070731163346-\
147
 
#   623xwcycwij91xen
148
 
#
149
 
""".splitlines(True)
150
 
 
151
 
 
152
112
class TestMergeDirective(object):
153
113
 
154
114
    def test_merge_source(self):
310
270
To: pqm@example.com
311
271
User-Agent: Bazaar \(.*\)
312
272
 
313
 
# Bazaar merge directive format 2 \\(Bazaar 0.90\\)
 
273
# Bazaar merge directive format 2 \\(Bazaar 0.19\\)
314
274
# revision_id: rev2a
315
275
# target_branch: (.|\n)*
316
276
# testament_sha1: .*
338
298
To: pqm@example.com
339
299
User-Agent: Bazaar \(.*\)
340
300
 
341
 
# Bazaar merge directive format 2 \\(Bazaar 0.90\\)
 
301
# Bazaar merge directive format 2 \\(Bazaar 0.19\\)
342
302
# revision_id: rev2a
343
303
# target_branch: (.|\n)*
344
304
# testament_sha1: .*
353
313
        tree_a = self.make_branch_and_tree('tree_a')
354
314
        tree_a.branch.get_config().set_user_option('email',
355
315
            'J. Random Hacker <jrandom@example.com>')
356
 
        self.build_tree_contents([('tree_a/file', 'content_a\ncontent_b\n'),
357
 
                                  ('tree_a/file_2', 'content_x\rcontent_y\r')])
358
 
        tree_a.add(['file', 'file_2'])
 
316
        self.build_tree_contents([('tree_a/file', 'content_a\ncontent_b\n')])
 
317
        tree_a.add('file')
359
318
        tree_a.commit('message', rev_id='rev1')
360
319
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
361
320
        branch_c = tree_a.bzrdir.sprout('branch_c').open_branch()
362
321
        tree_b.commit('message', rev_id='rev2b')
363
 
        self.build_tree_contents([('tree_a/file', 'content_a\ncontent_c \n'),
364
 
                                  ('tree_a/file_2', 'content_x\rcontent_z\r')])
 
322
        self.build_tree_contents([('tree_a/file', 'content_a\ncontent_c \n')])
365
323
        tree_a.commit('Commit of rev2a', rev_id='rev2a')
366
324
        return tree_a, tree_b, branch_c
367
325
 
372
330
            tree_d.branch.base, patch_type='diff',
373
331
            public_branch=tree_a.branch.base)
374
332
 
375
 
    def test_disk_name(self):
376
 
        tree_a, tree_b, branch_c = self.make_trees()
377
 
        tree_a.branch.nick = 'fancy <name>'
378
 
        md = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 120,
379
 
            tree_b.branch.base)
380
 
        self.assertEqual('fancy-name-2', md.get_disk_name(tree_a.branch))
381
 
 
382
 
    def test_disk_name_old_revno(self):
383
 
        tree_a, tree_b, branch_c = self.make_trees()
384
 
        tree_a.branch.nick = 'fancy-name'
385
 
        md = self.from_objects(tree_a.branch.repository, 'rev1', 500, 120,
386
 
            tree_b.branch.base)
387
 
        self.assertEqual('fancy-name-1', md.get_disk_name(tree_a.branch))
388
 
 
389
333
    def test_generate_patch(self):
390
334
        tree_a, tree_b, branch_c = self.make_trees()
391
335
        md2 = self.from_objects(tree_a.branch.repository, 'rev2a', 500, 120,
567
511
        revision = md.install_revisions(tree_b.branch.repository)
568
512
        self.assertEqual('rev2a', revision)
569
513
 
570
 
    def test_use_submit_for_missing_dependency(self):
571
 
        tree_a, tree_b, branch_c = self.make_trees()
572
 
        branch_c.pull(tree_a.branch)
573
 
        self.build_tree_contents([('tree_a/file', 'content_q\ncontent_r\n')])
574
 
        tree_a.commit('rev3a', rev_id='rev3a')
575
 
        md = self.from_objects(tree_a.branch.repository, 'rev3a', 500, 36,
576
 
            branch_c.base, base_revision_id='rev2a')
577
 
        revision = md.install_revisions(tree_b.branch.repository)
578
 
 
579
 
    def test_handle_target_not_a_branch(self):
580
 
        tree_a, tree_b, branch_c = self.make_trees()
581
 
        branch_c.pull(tree_a.branch)
582
 
        self.build_tree_contents([('tree_a/file', 'content_q\ncontent_r\n')])
583
 
        tree_a.commit('rev3a', rev_id='rev3a')
584
 
        md = self.from_objects(tree_a.branch.repository, 'rev3a', 500, 36,
585
 
            branch_c.base, base_revision_id='rev2a')
586
 
        md.target_branch = self.get_url('not-a-branch')
587
 
        self.assertRaises(errors.TargetNotBranch, md.install_revisions,
588
 
                tree_b.branch.repository)
589
 
 
590
514
 
591
515
class TestMergeDirective1Branch(tests.TestCaseWithTransport,
592
516
    TestMergeDirectiveBranch):
598
522
 
599
523
    def from_objects(self, repository, revision_id, time, timezone,
600
524
        target_branch, patch_type='bundle', local_target_branch=None,
601
 
        public_branch=None, message=None, base_revision_id=None):
602
 
        if base_revision_id is not None:
603
 
            raise tests.TestNotApplicable('This format does not support'
604
 
                                          ' explicit bases.')
605
 
        repository.lock_write()
606
 
        try:
607
 
            return merge_directive.MergeDirective.from_objects( repository,
608
 
                revision_id, time, timezone, target_branch, patch_type,
609
 
                local_target_branch, public_branch, message)
610
 
        finally:
611
 
            repository.unlock()
 
525
        public_branch=None, message=None):
 
526
        return merge_directive.MergeDirective.from_objects(
 
527
            repository, revision_id, time, timezone, target_branch,
 
528
            patch_type, local_target_branch, public_branch, message)
612
529
 
613
530
    def make_merge_directive(self, revision_id, testament_sha1, time, timezone,
614
531
                 target_branch, patch=None, patch_type=None,
631
548
        public_branch=None, message=None, base_revision_id=None):
632
549
        include_patch = (patch_type in ('bundle', 'diff'))
633
550
        include_bundle = (patch_type == 'bundle')
634
 
        self.assertTrue(patch_type in ('bundle', 'diff', None))
 
551
        assert patch_type in ('bundle', 'diff', None)
635
552
        return merge_directive.MergeDirective2.from_objects(
636
553
            repository, revision_id, time, timezone, target_branch,
637
554
            include_patch, include_bundle, local_target_branch, public_branch,
671
588
        lines = md.to_lines()
672
589
        md2 = merge_directive.MergeDirective.from_lines(lines)
673
590
        md2._verify_patch(tree_a.branch.repository)
674
 
        # Strip trailing whitespace
 
591
        # Stript trailing whitespace
675
592
        md2.patch = md2.patch.replace(' \n', '\n')
676
593
        md2._verify_patch(tree_a.branch.repository)
677
594
        # Convert to Mac line-endings
678
 
        md2.patch = re.sub('(\r\n|\r|\n)', '\r', md2.patch)
 
595
        md2.patch = md2.patch.replace('\n', '\r')
679
596
        self.assertTrue(md2._verify_patch(tree_a.branch.repository))
680
597
        # Convert to DOS line-endings
681
 
        md2.patch = re.sub('(\r\n|\r|\n)', '\r\n', md2.patch)
 
598
        md2.patch = md2.patch.replace('\r', '\r\n')
682
599
        self.assertTrue(md2._verify_patch(tree_a.branch.repository))
683
600
        md2.patch = md2.patch.replace('content_c', 'content_d')
684
601
        self.assertFalse(md2._verify_patch(tree_a.branch.repository))
685
 
 
686
 
 
687
 
class TestParseOldMergeDirective2(tests.TestCase):
688
 
 
689
 
    def test_parse_old_merge_directive(self):
690
 
        md = merge_directive.MergeDirective.from_lines(INPUT1_2_OLD)
691
 
        self.assertEqual('example:', md.revision_id)
692
 
        self.assertEqual('sha', md.testament_sha1)
693
 
        self.assertEqual('http://example.com', md.target_branch)
694
 
        self.assertEqual('http://example.org', md.source_branch)
695
 
        self.assertEqual(453, md.time)
696
 
        self.assertEqual(120, md.timezone)
697
 
        self.assertEqual('booga', md.patch)
698
 
        self.assertEqual('diff', md.patch_type)
699
 
        self.assertEqual('Hi mom!', md.message)