~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge_directive.py

  • Committer: Vincent Ladeuil
  • Date: 2007-07-22 15:44:59 UTC
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070722154459-520ws2gnifghkpgy
From review comments, use a private scheme for testing.

* bzrlib/transport/__init__.py:
(_unregister_urlparse_netloc_protocol): New function.

* bzrlib/tests/transport_util.py:
(InstrumentedTransport.__init__): Use a dedicated scheme.
(TestCaseWithConnectionHookedTransport.setUp): Reworked to
register the new transport.
(TestCaseWithConnectionHookedTransport.get_url): Use our dedicated
scheme.
(TestCaseWithConnectionHookedTransport.install_hooks,
TestCaseWithConnectionHookedTransport.reset_hooks): Registering
transport is setUp job.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
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
 
630
588
        lines = md.to_lines()
631
589
        md2 = merge_directive.MergeDirective.from_lines(lines)
632
590
        md2._verify_patch(tree_a.branch.repository)
633
 
        # Strip trailing whitespace
 
591
        # Stript trailing whitespace
634
592
        md2.patch = md2.patch.replace(' \n', '\n')
635
593
        md2._verify_patch(tree_a.branch.repository)
636
594
        # Convert to Mac line-endings
637
 
        md2.patch = re.sub('(\r\n|\r|\n)', '\r', md2.patch)
 
595
        md2.patch = md2.patch.replace('\n', '\r')
638
596
        self.assertTrue(md2._verify_patch(tree_a.branch.repository))
639
597
        # Convert to DOS line-endings
640
 
        md2.patch = re.sub('(\r\n|\r|\n)', '\r\n', md2.patch)
 
598
        md2.patch = md2.patch.replace('\r', '\r\n')
641
599
        self.assertTrue(md2._verify_patch(tree_a.branch.repository))
642
600
        md2.patch = md2.patch.replace('content_c', 'content_d')
643
601
        self.assertFalse(md2._verify_patch(tree_a.branch.repository))
644
 
 
645
 
 
646
 
class TestParseOldMergeDirective2(tests.TestCase):
647
 
 
648
 
    def test_parse_old_merge_directive(self):
649
 
        md = merge_directive.MergeDirective.from_lines(INPUT1_2_OLD)
650
 
        self.assertEqual('example:', md.revision_id)
651
 
        self.assertEqual('sha', md.testament_sha1)
652
 
        self.assertEqual('http://example.com', md.target_branch)
653
 
        self.assertEqual('http://example.org', md.source_branch)
654
 
        self.assertEqual(453, md.time)
655
 
        self.assertEqual(120, md.timezone)
656
 
        self.assertEqual('booga', md.patch)
657
 
        self.assertEqual('diff', md.patch_type)
658
 
        self.assertEqual('Hi mom!', md.message)