~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#
15
15
# You should have received a copy of the GNU General Public License
16
16
# along with this program; if not, write to the Free Software
17
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 
19
19
"""Tests for the formatting and construction of errors."""
20
20
 
87
87
            "reason: reason for foo",
88
88
            str(error))
89
89
 
90
 
    def test_inconsistent_delta_delta(self):
91
 
        error = errors.InconsistentDeltaDelta([], 'reason')
92
 
        self.assertEqualDiff(
93
 
            "An inconsistent delta was supplied: []\nreason: reason",
94
 
            str(error))
95
 
 
96
90
    def test_in_process_transport(self):
97
91
        error = errors.InProcessTransport('fpp')
98
92
        self.assertEqualDiff(
120
114
            "read without data loss.",
121
115
            str(error))
122
116
 
123
 
    def test_jail_break(self):
124
 
        error = errors.JailBreak("some url")
125
 
        self.assertEqualDiff("An attempt to access a url outside the server"
126
 
            " jail was made: 'some url'.",
127
 
            str(error))
 
117
    def test_install_failed(self):
 
118
        error = errors.InstallFailed(['rev-one'])
 
119
        self.assertEqual("Could not install revisions:\nrev-one", str(error))
 
120
        error = errors.InstallFailed(['rev-one', 'rev-two'])
 
121
        self.assertEqual("Could not install revisions:\nrev-one, rev-two",
 
122
                         str(error))
 
123
        error = errors.InstallFailed([None])
 
124
        self.assertEqual("Could not install revisions:\nNone", str(error))
128
125
 
129
126
    def test_lock_active(self):
130
127
        error = errors.LockActive("lock description")
161
158
        error = errors.MediumNotConnected("a medium")
162
159
        self.assertEqualDiff(
163
160
            "The medium 'a medium' is not connected.", str(error))
164
 
 
 
161
 
165
162
    def test_no_public_branch(self):
166
163
        b = self.make_branch('.')
167
164
        error = errors.NoPublicBranch(b)
174
171
        error = errors.NoRepositoryPresent(dir)
175
172
        self.assertNotEqual(-1, str(error).find((dir.transport.clone('..').base)))
176
173
        self.assertEqual(-1, str(error).find((dir.transport.base)))
177
 
 
 
174
        
178
175
    def test_no_smart_medium(self):
179
176
        error = errors.NoSmartMedium("a transport")
180
177
        self.assertEqualDiff("The transport 'a transport' cannot tunnel the "
248
245
            "You will need to upgrade the branch to permit branch stacking.",
249
246
            str(error))
250
247
 
251
 
    def test_unstackable_location(self):
252
 
        error = errors.UnstackableLocationError('foo', 'bar')
253
 
        self.assertEqualDiff("The branch 'foo' cannot be stacked on 'bar'.",
254
 
            str(error))
255
 
 
256
248
    def test_unstackable_repository_format(self):
257
249
        format = u'foo'
258
250
        url = "/foo"
264
256
 
265
257
    def test_up_to_date(self):
266
258
        error = errors.UpToDateFormat(bzrdir.BzrDirFormat4())
267
 
        self.assertEqualDiff("The branch format All-in-one "
268
 
                             "format 4 is already at the most "
 
259
        self.assertEqualDiff("The branch format Bazaar-NG branch, "
 
260
                             "format 0.0.4 is already at the most "
269
261
                             "recent format.",
270
262
                             str(error))
271
263
 
412
404
        """Test the formatting of MalformedBugIdentifier."""
413
405
        error = errors.MalformedBugIdentifier('bogus', 'reason for bogosity')
414
406
        self.assertEqual(
415
 
            'Did not understand bug identifier bogus: reason for bogosity. '
416
 
            'See "bzr help bugs" for more information on this feature.',
 
407
            "Did not understand bug identifier bogus: reason for bogosity",
417
408
            str(error))
418
409
 
419
410
    def test_unknown_bug_tracker_abbreviation(self):
470
461
        self.assertEqual(
471
462
            "Container has multiple records with the same name: n\xc3\xa5me",
472
463
            str(e))
473
 
 
 
464
        
474
465
    def test_check_error(self):
475
466
        # This has a member called 'message', which is problematic in
476
467
        # python2.5 because that is a slot on the base Exception class
557
548
            'Tip change rejected: Unicode message\xe2\x80\xbd',
558
549
            str(err))
559
550
 
560
 
    def test_error_from_smart_server(self):
561
 
        error_tuple = ('error', 'tuple')
562
 
        err = errors.ErrorFromSmartServer(error_tuple)
563
 
        self.assertEquals(
564
 
            "Error received from smart server: ('error', 'tuple')", str(err))
565
 
 
566
 
    def test_untranslateable_error_from_smart_server(self):
567
 
        error_tuple = ('error', 'tuple')
568
 
        orig_err = errors.ErrorFromSmartServer(error_tuple)
569
 
        err = errors.UnknownErrorFromSmartServer(orig_err)
570
 
        self.assertEquals(
571
 
            "Server sent an unexpected error: ('error', 'tuple')", str(err))
572
 
 
573
 
    def test_smart_message_handler_error(self):
574
 
        # Make an exc_info tuple.
575
 
        try:
576
 
            raise Exception("example error")
577
 
        except Exception:
578
 
            exc_info = sys.exc_info()
579
 
        err = errors.SmartMessageHandlerError(exc_info)
580
 
        self.assertStartsWith(
581
 
            str(err), "The message handler raised an exception:\n")
582
 
        self.assertEndsWith(str(err), "Exception: example error\n")
583
 
 
584
 
    def test_must_have_working_tree(self):
585
 
        err = errors.MustHaveWorkingTree('foo', 'bar')
586
 
        self.assertEqual(str(err), "Branching 'bar'(foo) must create a"
587
 
                                   " working tree.")
588
 
 
589
 
    def test_no_such_view(self):
590
 
        err = errors.NoSuchView('foo')
591
 
        self.assertEquals("No such view: foo.", str(err))
592
 
 
593
 
    def test_views_not_supported(self):
594
 
        err = errors.ViewsNotSupported('atree')
595
 
        err_str = str(err)
596
 
        self.assertStartsWith(err_str, "Views are not supported by ")
597
 
        self.assertEndsWith(err_str, "; use 'bzr upgrade' to change your "
598
 
            "tree to a later format.")
599
 
 
600
 
    def test_file_outside_view(self):
601
 
        err = errors.FileOutsideView('baz', ['foo', 'bar'])
602
 
        self.assertEquals('Specified file "baz" is outside the current view: '
603
 
            'foo, bar', str(err))
604
 
 
605
 
    def test_invalid_shelf_id(self):
606
 
        invalid_id = "foo"
607
 
        err = errors.InvalidShelfId(invalid_id)
608
 
        self.assertEqual('"foo" is not a valid shelf id, '
609
 
            'try a number instead.', str(err))
610
 
 
611
 
    def test_unresumable_write_group(self):
612
 
        repo = "dummy repo"
613
 
        wg_tokens = ['token']
614
 
        reason = "a reason"
615
 
        err = errors.UnresumableWriteGroup(repo, wg_tokens, reason)
616
 
        self.assertEqual(
617
 
            "Repository dummy repo cannot resume write group "
618
 
            "['token']: a reason", str(err))
619
 
 
620
 
    def test_unsuspendable_write_group(self):
621
 
        repo = "dummy repo"
622
 
        err = errors.UnsuspendableWriteGroup(repo)
623
 
        self.assertEqual(
624
 
            'Repository dummy repo cannot suspend a write group.', str(err))
625
 
 
626
551
 
627
552
class PassThroughError(errors.BzrError):
628
 
 
 
553
    
629
554
    _fmt = """Pass through %(foo)s and %(bar)s"""
630
555
 
631
556
    def __init__(self, foo, bar):
642
567
 
643
568
 
644
569
class TestErrorFormatting(TestCase):
645
 
 
 
570
    
646
571
    def test_always_str(self):
647
572
        e = PassThroughError(u'\xb5', 'bar')
648
573
        self.assertIsInstance(e.__str__(), str)
659
584
                ['ErrorWithNoFormat uses its docstring as a format, it should use _fmt instead'],
660
585
                lambda x: str(x), e)
661
586
        ## s = str(e)
662
 
        self.assertEqual(s,
 
587
        self.assertEqual(s, 
663
588
                "This class has a docstring but no format string.")
664
589
 
665
590
    def test_mismatched_format_args(self):