/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-01 04:14:36 UTC
  • mto: (2323.6.9 0.15-integration)
  • mto: This revision was merged to the branch mainline in revision 2330.
  • Revision ID: aaron.bentley@utoronto.ca-20070301041436-cyfzmqrtau2qs4fk
Get MergeDirective.from_objects working

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from bzrlib import (
 
2
    errors,
 
3
    merge_directive,
 
4
    tests,
 
5
    )
 
6
 
 
7
 
 
8
class TestMergeDirective(tests.TestCase):
 
9
 
 
10
    def test_init(self):
 
11
        time = 500.0
 
12
        timezone = 5
 
13
        self.assertRaises(errors.NoMergeSource, merge_directive.MergeDirective,
 
14
            'example:', 'sha', time, timezone, 'http://example.com')
 
15
        self.assertRaises(errors.NoMergeSource, merge_directive.MergeDirective,
 
16
            'example:', 'sha', time, timezone, 'http://example.com',
 
17
            patch_type='diff')
 
18
        md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
 
19
            'http://example.com', public_location='http://example.org')
 
20
        self.assertRaises(errors.PatchMissing, merge_directive.MergeDirective,
 
21
            'example:', 'sha', time, timezone, 'http://example.com',
 
22
            patch_type='bundle')
 
23
        md = merge_directive.MergeDirective('null:', 'sha', time, timezone,
 
24
            'http://example.com', patch='blah', patch_type='bundle')
 
25
        self.assertRaises(errors.PatchMissing, merge_directive.MergeDirective,
 
26
            'example:', 'http://example.com', 'sha', time, timezone,
 
27
            public_location="http://example.org", patch_type='diff')
 
28
        md = merge_directive.MergeDirective('example:', 'sha1', time, timezone,
 
29
            'http://example.com', public_location="http://example.org",
 
30
            patch='', patch_type='diff')
 
31
 
 
32
    def test_serialization(self):
 
33
        time = 500.23
 
34
        timezone = 60
 
35
        md = merge_directive.MergeDirective('example:', 'sha', time, timezone,
 
36
            'http://example.com', public_location="http://example.org",
 
37
            patch='booga', patch_type='diff')
 
38
        md2 = merge_directive.MergeDirective.from_lines(md.to_lines())
 
39
        self.assertEqual('example:', md2.revision_id)
 
40
        self.assertEqual('sha', md2.testament_sha1)
 
41
        self.assertEqual('http://example.com', md2.submit_location)
 
42
        self.assertEqual('http://example.org', md2.public_location)
 
43
        self.assertEqual(time, md2.time)
 
44
        self.assertEqual(timezone, md2.timezone)
 
45
        self.assertEqual('diff', md2.patch_type)
 
46
        self.assertEqual('booga', md2.patch)
 
47
        md.patch = "# Bazaar revision bundle v0.9\n#\n"
 
48
        md3 = merge_directive.MergeDirective.from_lines(md.to_lines())
 
49
        self.assertEqual("# Bazaar revision bundle v0.9\n#\n", md3.patch)
 
50
        self.assertEqual("bundle", md3.patch_type)
 
51
 
 
52
 
 
53
class TestMergeDirectiveBranch(tests.TestCaseWithTransport):
 
54
 
 
55
    def test_generate(self):
 
56
        tree_a = self.make_branch_and_tree('tree_a')
 
57
        self.build_tree_contents([('tree_a/file', 'content_a\ncontent_b\n')])
 
58
        tree_a.add('file')
 
59
        tree_a.commit('message', rev_id='rev1')
 
60
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
 
61
        branch_c = tree_a.bzrdir.sprout('branch_c').open_branch()
 
62
        tree_b.commit('message', rev_id='rev2b')
 
63
        self.build_tree_contents([('tree_a/file', 'content_a\ncontent_c\n')])
 
64
        tree_a.commit('message', rev_id='rev2a')
 
65
        self.assertRaises(errors.PublicBranchOutOfDate,
 
66
            merge_directive.MergeDirective.from_objects,
 
67
            tree_a.branch.repository, 'rev2a', 500, 120, tree_b.branch.base,
 
68
            public_branch=branch_c)
 
69
        md1 = merge_directive.MergeDirective.from_objects(
 
70
            tree_a.branch.repository, 'rev2a', 500, 120, tree_b.branch.base)
 
71
        self.assertContainsRe(md1.patch, 'Bazaar revision bundle')
 
72
        self.assertContainsRe(md1.patch, '\\+content_c')
 
73
        self.assertNotContainsRe(md1.patch, '\\+content_a')
 
74
        branch_c.pull(tree_a.branch)
 
75
        md2 = merge_directive.MergeDirective.from_objects(
 
76
            tree_a.branch.repository, 'rev2a', 500, 120, tree_b.branch.base,
 
77
            patch_type='diff', public_branch=branch_c)
 
78
        self.assertNotContainsRe(md2.patch, 'Bazaar revision bundle')
 
79
        self.assertContainsRe(md1.patch, '\\+content_c')
 
80
        self.assertNotContainsRe(md1.patch, '\\+content_a')
 
81
        md3 = merge_directive.MergeDirective.from_objects(
 
82
            tree_a.branch.repository, 'rev2a', 500, 120, tree_b.branch.base,
 
83
            patch_type=None, public_branch=branch_c)
 
84
        self.assertIs(None, md3.patch)