133
133
error = errors.InvalidHttpRange('path',
134
134
'Content-Range: potatoes 0-00/o0oo0',
136
self.assertEquals("Invalid http range"
137
" 'Content-Range: potatoes 0-00/o0oo0'"
138
" for path: bad range",
136
self.assertEqual("Invalid http range"
137
" 'Content-Range: potatoes 0-00/o0oo0'"
138
" for path: bad range",
141
141
def test_invalid_range(self):
142
142
error = errors.InvalidRange('path', 12, 'bad range')
143
self.assertEquals("Invalid range access in path at 12: bad range",
143
self.assertEqual("Invalid range access in path at 12: bad range",
146
146
def test_inventory_modified(self):
147
147
error = errors.InventoryModified("a tree to be repred")
207
207
'There is no public branch set for "%s".' % url, str(error))
209
209
def test_no_repo(self):
210
dir = bzrdir.BzrDir.create(self.get_url())
210
dir = controldir.ControlDir.create(self.get_url())
211
211
error = errors.NoRepositoryPresent(dir)
212
212
self.assertNotEqual(-1, str(error).find((dir.transport.clone('..').base)))
213
213
self.assertEqual(-1, str(error).find((dir.transport.base)))
349
349
self.assertEqual("The value 'foo' is not a valid value.",
352
def test_bzrnewerror_is_deprecated(self):
353
class DeprecatedError(errors.BzrNewError):
355
self.callDeprecated(['BzrNewError was deprecated in bzr 0.13; '
356
'please convert DeprecatedError to use BzrError instead'],
359
352
def test_bzrerror_from_literal_string(self):
360
353
# Some code constructs BzrError from a literal string, in which case
361
354
# no further formatting is done. (I'm not sure raising the base class
533
526
def test_unable_create_symlink(self):
534
527
err = errors.UnableCreateSymlink()
536
529
"Unable to create symlink on this platform",
538
531
err = errors.UnableCreateSymlink(path=u'foo')
540
533
"Unable to create symlink 'foo' on this platform",
542
535
err = errors.UnableCreateSymlink(path=u'\xb5')
544
537
"Unable to create symlink u'\\xb5' on this platform",
554
547
def test_incorrect_url(self):
555
548
err = errors.InvalidBugTrackerURL('foo', 'http://bug.com/')
557
550
("The URL for bug tracker \"foo\" doesn't contain {id}: "
558
551
"http://bug.com/"),
561
554
def test_unable_encode_path(self):
562
555
err = errors.UnableEncodePath('foo', 'executable')
563
self.assertEquals("Unable to encode executable path 'foo' in "
564
"user encoding " + osutils.get_user_encoding(),
556
self.assertEqual("Unable to encode executable path 'foo' in "
557
"user encoding " + osutils.get_user_encoding(),
567
560
def test_unknown_format(self):
568
561
err = errors.UnknownFormatError('bar', kind='foo')
569
self.assertEquals("Unknown foo format: 'bar'", str(err))
562
self.assertEqual("Unknown foo format: 'bar'", str(err))
571
564
def test_unknown_rules(self):
572
565
err = errors.UnknownRules(['foo', 'bar'])
573
self.assertEquals("Unknown rules detected: foo, bar.", str(err))
575
def test_hook_failed(self):
576
# Create an exc_info tuple by raising and catching an exception.
579
except ZeroDivisionError:
580
err = errors.HookFailed('hook stage', 'hook name', sys.exc_info(),
582
# GZ 2010-11-08: Should not store exc_info in exception instances, but
583
# HookFailed is deprecated anyway and could maybe go.
585
self.assertStartsWith(
586
str(err), 'Hook \'hook name\' during hook stage failed:\n')
588
str(err), 'integer division or modulo by zero')
566
self.assertEqual("Unknown rules detected: foo, bar.", str(err))
592
568
def test_tip_change_rejected(self):
593
569
err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
595
571
u'Tip change rejected: Unicode message\N{INTERROBANG}',
598
574
'Tip change rejected: Unicode message\xe2\x80\xbd',
601
577
def test_error_from_smart_server(self):
602
578
error_tuple = ('error', 'tuple')
603
579
err = errors.ErrorFromSmartServer(error_tuple)
605
581
"Error received from smart server: ('error', 'tuple')", str(err))
607
583
def test_untranslateable_error_from_smart_server(self):
608
584
error_tuple = ('error', 'tuple')
609
585
orig_err = errors.ErrorFromSmartServer(error_tuple)
610
586
err = errors.UnknownErrorFromSmartServer(orig_err)
612
588
"Server sent an unexpected error: ('error', 'tuple')", str(err))
614
590
def test_smart_message_handler_error(self):
644
620
def test_file_outside_view(self):
645
621
err = errors.FileOutsideView('baz', ['foo', 'bar'])
646
self.assertEquals('Specified file "baz" is outside the current view: '
647
'foo, bar', str(err))
622
self.assertEqual('Specified file "baz" is outside the current view: '
623
'foo, bar', str(err))
649
625
def test_invalid_shelf_id(self):
650
626
invalid_id = "foo"
651
627
err = errors.InvalidShelfId(invalid_id)
652
628
self.assertEqual('"foo" is not a valid shelf id, '
653
'try a number instead.', str(err))
629
'try a number instead.', str(err))
655
631
def test_unresumable_write_group(self):
656
632
repo = "dummy repo"
760
736
def test_missing_format_string(self):
761
737
e = ErrorWithNoFormat(param='randomvalue')
762
s = self.callDeprecated(
763
['ErrorWithNoFormat uses its docstring as a format, it should use _fmt instead'],
767
"This class has a docstring but no format string.")
738
self.assertStartsWith(str(e),
739
"Unprintable exception ErrorWithNoFormat")
769
741
def test_mismatched_format_args(self):
770
742
# Even though ErrorWithBadFormat's format string does not match the
777
749
def test_cannot_bind_address(self):
778
750
# see <https://bugs.launchpad.net/bzr/+bug/286871>
779
751
e = errors.CannotBindAddress('example.com', 22,
780
socket.error(13, 'Permission denied'))
781
self.assertContainsRe(str(e),
752
socket.error(13, 'Permission denied'))
753
self.assertContainsRe(
782
755
r'Cannot bind address "example\.com:22":.*Permission denied')
784
def test_file_timestamp_unavailable(self):
757
def test_file_timestamp_unavailable(self):
785
758
e = errors.FileTimestampUnavailable("/path/foo")
786
self.assertEquals("The filestamp for /path/foo is not available.",
759
self.assertEqual("The filestamp for /path/foo is not available.",
789
762
def test_transform_rename_failed(self):
790
763
e = errors.TransformRenameFailed(u"from", u"to", "readonly file", 2)
792
765
u"Failed to rename from to to: readonly file",