/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 breezy/tests/test_errors.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    tests,
29
29
    urlutils,
30
30
    )
 
31
from ..sixish import (
 
32
    PY3,
 
33
    text_type,
 
34
    )
31
35
 
32
36
 
33
37
class TestErrors(tests.TestCase):
45
49
            init = getattr(c, '__init__', None)
46
50
            fmt = getattr(c, '_fmt', None)
47
51
            if init:
48
 
                args = inspect.getfullargspec(init)[0]
 
52
                if PY3:
 
53
                    args = inspect.getfullargspec(init)[0]
 
54
                else:
 
55
                    args = inspect.getargspec(init)[0]
49
56
                self.assertFalse('message' in args,
50
57
                                 ('Argument name "message" not allowed for '
51
58
                                  '"errors.%s.__init__"' % c.__name__))
60
67
            "^Filename b?'bad/filen\\\\xe5me' is not valid in your current"
61
68
            " filesystem encoding UTF-8$")
62
69
 
 
70
    def test_duplicate_file_id(self):
 
71
        error = errors.DuplicateFileId('a_file_id', 'foo')
 
72
        self.assertEqualDiff('File id {a_file_id} already exists in inventory'
 
73
                             ' as foo', str(error))
 
74
 
63
75
    def test_duplicate_help_prefix(self):
64
76
        error = errors.DuplicateHelpPrefix('foo')
65
77
        self.assertEqualDiff('The prefix foo is in the help search path twice.',
113
125
        self.assertEqual("Invalid range access in path at 12: bad range",
114
126
                         str(error))
115
127
 
 
128
    def test_inventory_modified(self):
 
129
        error = errors.InventoryModified("a tree to be repred")
 
130
        self.assertEqualDiff("The current inventory for the tree 'a tree to "
 
131
                             "be repred' has been modified, so a clean inventory cannot be "
 
132
                             "read without data loss.",
 
133
                             str(error))
 
134
 
116
135
    def test_jail_break(self):
117
136
        error = errors.JailBreak("some url")
118
137
        self.assertEqualDiff("An attempt to access a url outside the server"
180
199
                             "the currently open request.",
181
200
                             str(error))
182
201
 
 
202
    def test_unavailable_representation(self):
 
203
        error = errors.UnavailableRepresentation(
 
204
            ('key',), "mpdiff", "fulltext")
 
205
        self.assertEqualDiff("The encoding 'mpdiff' is not available for key "
 
206
                             "('key',) which is encoded as 'fulltext'.",
 
207
                             str(error))
 
208
 
183
209
    def test_unstackable_location(self):
184
210
        error = errors.UnstackableLocationError('foo', 'bar')
185
211
        self.assertEqualDiff("The branch 'foo' cannot be stacked on 'bar'.",
339
365
        e = errors.DuplicateRecordNameError(b"n\xc3\xa5me")
340
366
        self.assertEqual(
341
367
            u"Container has multiple records with the same name: n\xe5me",
342
 
            str(e))
 
368
            text_type(e))
343
369
 
344
370
    def test_check_error(self):
345
371
        e = errors.BzrCheckError('example check failure')
362
388
            "you wish to keep, and delete it when you are done.",
363
389
            str(err))
364
390
 
 
391
    def test_unable_create_symlink(self):
 
392
        err = errors.UnableCreateSymlink()
 
393
        self.assertEqual(
 
394
            "Unable to create symlink on this platform",
 
395
            str(err))
 
396
        err = errors.UnableCreateSymlink(path=u'foo')
 
397
        self.assertEqual(
 
398
            "Unable to create symlink 'foo' on this platform",
 
399
            str(err))
 
400
        err = errors.UnableCreateSymlink(path=u'\xb5')
 
401
        self.assertEqual(
 
402
            "Unable to create symlink %s on this platform" % repr(u'\xb5'),
 
403
            str(err))
 
404
 
365
405
    def test_invalid_url_join(self):
366
406
        """Test the formatting of InvalidURLJoin."""
367
407
        e = urlutils.InvalidURLJoin('Reason', 'base path', ('args',))
383
423
        err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
384
424
        self.assertEqual(
385
425
            u'Tip change rejected: Unicode message\N{INTERROBANG}',
386
 
            str(err))
 
426
            text_type(err))
387
427
 
388
428
    def test_error_from_smart_server(self):
389
429
        error_tuple = ('error', 'tuple')
482
522
        # Unicode error, because it tries to call str() on the string
483
523
        # returned from e.__str__(), and it has non ascii characters
484
524
        s = str(e)
485
 
        self.assertEqual('Pass through \xb5 and bar', s)
 
525
        if PY3:
 
526
            self.assertEqual('Pass through \xb5 and bar', s)
 
527
        else:
 
528
            self.assertEqual('Pass through \xc2\xb5 and bar', s)
486
529
 
487
530
    def test_missing_format_string(self):
488
531
        e = ErrorWithNoFormat(param='randomvalue')
505
548
            str(e),
506
549
            r'Cannot bind address "example\.com:22":.*Permission denied')
507
550
 
 
551
    def test_transform_rename_failed(self):
 
552
        e = errors.TransformRenameFailed(u"from", u"to", "readonly file", 2)
 
553
        self.assertEqual(
 
554
            u"Failed to rename from to to: readonly file",
 
555
            str(e))
 
556
 
508
557
 
509
558
class TestErrorsUsingTransport(tests.TestCaseWithMemoryTransport):
510
559
    """Tests for errors that need to use a branch or repo."""