/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_merge_directive.py

  • Committer: Aaron Bentley
  • Date: 2007-03-02 20:27:06 UTC
  • mto: (2323.6.9 0.15-integration)
  • mto: This revision was merged to the branch mainline in revision 2330.
  • Revision ID: abentley@panoramicfeedback.com-20070302202706-mriia2sdekme12af
Add RegistryOption.from_swargs to simplify simple registry options

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from bzrlib import (
 
2
    errors,
 
3
    gpg,
 
4
    merge_directive,
 
5
    tests,
 
6
    )
 
7
 
 
8
 
 
9
class TestMergeDirective(tests.TestCase):
 
10
 
 
11
    def test_init(self):
 
12
        time = 500.0
 
13
        timezone = 5
 
14
        self.assertRaises(errors.NoMergeSource, merge_directive.MergeDirective,
 
15
            'example:', 'sha', time, timezone, 'http://example.com')
 
16
        self.assertRaises(errors.NoMergeSource, merge_directive.MergeDirective,
 
17
            'example:', 'sha', time, timezone, 'http://example.com',
 
18
            patch_type='diff')
 
19
        md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
 
20
            'http://example.com', source_branch='http://example.org')
 
21
        self.assertRaises(errors.PatchMissing, merge_directive.MergeDirective,
 
22
            'example:', 'sha', time, timezone, 'http://example.com',
 
23
            patch_type='bundle')
 
24
        md = merge_directive.MergeDirective('null:', 'sha', time, timezone,
 
25
            'http://example.com', patch='blah', patch_type='bundle')
 
26
        self.assertRaises(errors.PatchMissing, merge_directive.MergeDirective,
 
27
            'example:', 'sha', time, timezone, 'http://example.com',
 
28
            source_branch="http://example.org", patch_type='diff')
 
29
        md = merge_directive.MergeDirective('example:', 'sha1', time, timezone,
 
30
            'http://example.com', source_branch="http://example.org",
 
31
            patch='', patch_type='diff')
 
32
 
 
33
    def test_serialization(self):
 
34
        time = 500.23
 
35
        timezone = 60
 
36
        md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
 
37
            'http://example.com', source_branch="http://example.org",
 
38
            patch='booga', patch_type='diff')
 
39
        md2 = merge_directive.MergeDirective.from_lines(md.to_lines())
 
40
        self.assertEqual('example:', md2.revision_id)
 
41
        self.assertEqual('sha', md2.testament_sha1)
 
42
        self.assertEqual('http://example.com', md2.target_branch)
 
43
        self.assertEqual('http://example.org', md2.source_branch)
 
44
        self.assertEqual(time, md2.time)
 
45
        self.assertEqual(timezone, md2.timezone)
 
46
        self.assertEqual('diff', md2.patch_type)
 
47
        self.assertEqual('booga', md2.patch)
 
48
        md.patch = "# Bazaar revision bundle v0.9\n#\n"
 
49
        md3 = merge_directive.MergeDirective.from_lines(md.to_lines())
 
50
        self.assertEqual("# Bazaar revision bundle v0.9\n#\n", md3.patch)
 
51
        self.assertEqual("bundle", md3.patch_type)
 
52
        self.assertContainsRe(md3.to_lines()[0],
 
53
            '^# Bazaar merge directive format ')
 
54
 
 
55
 
 
56
class TestMergeDirectiveBranch(tests.TestCaseWithTransport):
 
57
 
 
58
    def test_generate(self):
 
59
        tree_a = self.make_branch_and_tree('tree_a')
 
60
        self.build_tree_contents([('tree_a/file', 'content_a\ncontent_b\n')])
 
61
        tree_a.add('file')
 
62
        tree_a.commit('message', rev_id='rev1')
 
63
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
 
64
        branch_c = tree_a.bzrdir.sprout('branch_c').open_branch()
 
65
        tree_b.commit('message', rev_id='rev2b')
 
66
        self.build_tree_contents([('tree_a/file', 'content_a\ncontent_c\n')])
 
67
        tree_a.commit('message', rev_id='rev2a')
 
68
        self.assertRaises(errors.PublicBranchOutOfDate,
 
69
            merge_directive.MergeDirective.from_objects,
 
70
            tree_a.branch.repository, 'rev2a', 500, 120, tree_b.branch.base,
 
71
            public_branch=branch_c)
 
72
        md1 = merge_directive.MergeDirective.from_objects(
 
73
            tree_a.branch.repository, 'rev2a', 500.0, 120, tree_b.branch.base)
 
74
        self.assertContainsRe(md1.patch, 'Bazaar revision bundle')
 
75
        self.assertContainsRe(md1.patch, '\\+content_c')
 
76
        self.assertNotContainsRe(md1.patch, '\\+content_a')
 
77
        branch_c.pull(tree_a.branch)
 
78
        md2 = merge_directive.MergeDirective.from_objects(
 
79
            tree_a.branch.repository, 'rev2a', 500.0, 120, tree_b.branch.base,
 
80
            patch_type='diff', public_branch=branch_c)
 
81
        self.assertNotContainsRe(md2.patch, 'Bazaar revision bundle')
 
82
        self.assertContainsRe(md1.patch, '\\+content_c')
 
83
        self.assertNotContainsRe(md1.patch, '\\+content_a')
 
84
        md3 = merge_directive.MergeDirective.from_objects(
 
85
            tree_a.branch.repository, 'rev2a', 500.0, 120, tree_b.branch.base,
 
86
            patch_type=None, public_branch=branch_c)
 
87
        md3.to_lines()
 
88
        self.assertIs(None, md3.patch)
 
89
 
 
90
    def test_signing(self):
 
91
        time = 500.23
 
92
        timezone = 60
 
93
        class FakeBranch(object):
 
94
            def get_config(self):
 
95
                return self
 
96
            def gpg_signing_command(self):
 
97
                return 'loopback'
 
98
        md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
 
99
            'http://example.com', source_branch="http://example.org",
 
100
            patch='booga', patch_type='diff')
 
101
        old_strategy = gpg.GPGStrategy
 
102
        gpg.GPGStrategy = gpg.LoopbackGPGStrategy
 
103
        try:
 
104
            signed = md.to_signed(FakeBranch())
 
105
        finally:
 
106
            gpg.GPGStrategy = old_strategy
 
107
        self.assertContainsRe(signed, '^-----BEGIN PSEUDO-SIGNED CONTENT')
 
108
        self.assertContainsRe(signed, 'example.org')
 
109
        self.assertContainsRe(signed, 'booga')