~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/repository_implementations/test_repository.py

  • Committer: abentley
  • Date: 2006-04-20 23:47:53 UTC
  • mfrom: (1681 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1683.
  • Revision ID: abentley@lappy-20060420234753-6a6874b76f09f86d
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for bzrdir implementations - tests a bzrdir format."""
18
18
 
19
19
import os
 
20
import re
20
21
import sys
21
22
 
22
23
import bzrlib
46
47
    def setUp(self):
47
48
        super(TestCaseWithRepository, self).setUp()
48
49
 
49
 
    def make_branch(self, relpath):
50
 
        repo = self.make_repository(relpath)
 
50
    def make_branch(self, relpath, format=None):
 
51
        repo = self.make_repository(relpath, format=None)
51
52
        return repo.bzrdir.create_branch()
52
53
 
53
 
    def make_bzrdir(self, relpath):
54
 
        try:
55
 
            url = self.get_url(relpath)
56
 
            segments = url.split('/')
57
 
            if segments and segments[-1] not in ('', '.'):
58
 
                parent = '/'.join(segments[:-1])
59
 
                t = get_transport(parent)
60
 
                try:
61
 
                    t.mkdir(segments[-1])
62
 
                except FileExists:
63
 
                    pass
64
 
            return self.bzrdir_format.initialize(url)
65
 
        except UninitializableFormat:
66
 
            raise TestSkipped("Format %s is not initializable.")
67
 
 
68
 
    def make_repository(self, relpath):
 
54
    def make_repository(self, relpath, format=None):
69
55
        made_control = self.make_bzrdir(relpath)
70
56
        return self.repository_format.initialize(made_control)
71
57
 
250
236
        repo.unlock()
251
237
        self.assertRaises(errors.OutSideTransaction, inv.add_lines, 'foo', [], [])
252
238
 
 
239
    def test_format_description(self):
 
240
        repo = self.make_repository('.')
 
241
        text = repo._format.get_format_description()
 
242
        self.failUnless(len(text))
 
243
 
 
244
    def assertMessageRoundtrips(self, message):
 
245
        """Assert that message roundtrips to a repository and back intact."""
 
246
        tree = self.make_branch_and_tree('.')
 
247
        tree.commit(message, rev_id='a', allow_pointless=True)
 
248
        rev = tree.branch.repository.get_revision('a')
 
249
        # we have to manually escape this as we dont try to
 
250
        # roundtrip xml invalid characters at this point.
 
251
        # when escaping is moved to the serialiser, this test
 
252
        # can check against the literal message rather than
 
253
        # this escaped version.
 
254
        escaped_message, escape_count = re.subn(
 
255
            u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]+',
 
256
            lambda match: match.group(0).encode('unicode_escape'),
 
257
            message)
 
258
        escaped_message= re.sub('\r', '\n', escaped_message)
 
259
        self.assertEqual(rev.message, escaped_message)
 
260
        # insist the class is unicode no matter what came in for 
 
261
        # consistency.
 
262
        self.assertIsInstance(rev.message, unicode)
 
263
 
 
264
    def test_commit_unicode_message(self):
 
265
        # a siple unicode message should be preserved
 
266
        self.assertMessageRoundtrips(u'foo bar gamm\xae plop')
 
267
 
 
268
    def test_commit_unicode_control_characters(self):
 
269
        # a unicode message with control characters should roundtrip too.
 
270
        self.assertMessageRoundtrips(
 
271
            "All 8-bit chars: " +  ''.join([unichr(x) for x in range(256)]))
253
272
 
254
273
class TestCaseWithComplexRepository(TestCaseWithRepository):
255
274