~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
 
158
158
        error = errors.MediumNotConnected("a medium")
159
159
        self.assertEqualDiff(
160
160
            "The medium 'a medium' is not connected.", str(error))
161
 
 
 
161
 
162
162
    def test_no_public_branch(self):
163
163
        b = self.make_branch('.')
164
164
        error = errors.NoPublicBranch(b)
171
171
        error = errors.NoRepositoryPresent(dir)
172
172
        self.assertNotEqual(-1, str(error).find((dir.transport.clone('..').base)))
173
173
        self.assertEqual(-1, str(error).find((dir.transport.base)))
174
 
 
 
174
        
175
175
    def test_no_smart_medium(self):
176
176
        error = errors.NoSmartMedium("a transport")
177
177
        self.assertEqualDiff("The transport 'a transport' cannot tunnel the "
256
256
 
257
257
    def test_up_to_date(self):
258
258
        error = errors.UpToDateFormat(bzrdir.BzrDirFormat4())
259
 
        self.assertEqualDiff("The branch format All-in-one "
260
 
                             "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 "
261
261
                             "recent format.",
262
262
                             str(error))
263
263
 
404
404
        """Test the formatting of MalformedBugIdentifier."""
405
405
        error = errors.MalformedBugIdentifier('bogus', 'reason for bogosity')
406
406
        self.assertEqual(
407
 
            'Did not understand bug identifier bogus: reason for bogosity. '
408
 
            'See "bzr help bugs" for more information on this feature.',
 
407
            "Did not understand bug identifier bogus: reason for bogosity",
409
408
            str(error))
410
409
 
411
410
    def test_unknown_bug_tracker_abbreviation(self):
462
461
        self.assertEqual(
463
462
            "Container has multiple records with the same name: n\xc3\xa5me",
464
463
            str(e))
465
 
 
 
464
        
466
465
    def test_check_error(self):
467
466
        # This has a member called 'message', which is problematic in
468
467
        # python2.5 because that is a slot on the base Exception class
549
548
            'Tip change rejected: Unicode message\xe2\x80\xbd',
550
549
            str(err))
551
550
 
552
 
    def test_error_from_smart_server(self):
553
 
        error_tuple = ('error', 'tuple')
554
 
        err = errors.ErrorFromSmartServer(error_tuple)
555
 
        self.assertEquals(
556
 
            "Error received from smart server: ('error', 'tuple')", str(err))
557
 
 
558
 
    def test_untranslateable_error_from_smart_server(self):
559
 
        error_tuple = ('error', 'tuple')
560
 
        orig_err = errors.ErrorFromSmartServer(error_tuple)
561
 
        err = errors.UnknownErrorFromSmartServer(orig_err)
562
 
        self.assertEquals(
563
 
            "Server sent an unexpected error: ('error', 'tuple')", str(err))
564
 
 
565
 
    def test_smart_message_handler_error(self):
566
 
        # Make an exc_info tuple.
567
 
        try:
568
 
            raise Exception("example error")
569
 
        except Exception:
570
 
            exc_info = sys.exc_info()
571
 
        err = errors.SmartMessageHandlerError(exc_info)
572
 
        self.assertStartsWith(
573
 
            str(err), "The message handler raised an exception:\n")
574
 
        self.assertEndsWith(str(err), "Exception: example error\n")
575
 
 
576
 
    def test_must_have_working_tree(self):
577
 
        err = errors.MustHaveWorkingTree('foo', 'bar')
578
 
        self.assertEqual(str(err), "Branching 'bar'(foo) must create a"
579
 
                                   " working tree.")
580
 
 
581
 
    def test_no_such_view(self):
582
 
        err = errors.NoSuchView('foo')
583
 
        self.assertEquals("No such view: foo.", str(err))
584
 
 
585
 
    def test_views_not_supported(self):
586
 
        err = errors.ViewsNotSupported('atree')
587
 
        err_str = str(err)
588
 
        self.assertStartsWith(err_str, "Views are not supported by ")
589
 
        self.assertEndsWith(err_str, "; use 'bzr upgrade' to change your "
590
 
            "tree to a later format.")
591
 
 
592
 
    def test_file_outside_view(self):
593
 
        err = errors.FileOutsideView('baz', ['foo', 'bar'])
594
 
        self.assertEquals('Specified file "baz" is outside the current view: '
595
 
            'foo, bar', str(err))
596
 
 
597
 
    def test_invalid_shelf_id(self):
598
 
        invalid_id = "foo"
599
 
        err = errors.InvalidShelfId(invalid_id)
600
 
        self.assertEqual('"foo" is not a valid shelf id, '
601
 
            'try a number instead.', str(err))
602
 
 
603
 
    def test_unresumable_write_group(self):
604
 
        repo = "dummy repo"
605
 
        wg_tokens = ['token']
606
 
        reason = "a reason"
607
 
        err = errors.UnresumableWriteGroup(repo, wg_tokens, reason)
608
 
        self.assertEqual(
609
 
            "Repository dummy repo cannot resume write group "
610
 
            "['token']: a reason", str(err))
611
 
 
612
 
    def test_unsuspendable_write_group(self):
613
 
        repo = "dummy repo"
614
 
        err = errors.UnsuspendableWriteGroup(repo)
615
 
        self.assertEqual(
616
 
            'Repository dummy repo cannot suspend a write group.', str(err))
617
 
 
618
551
 
619
552
class PassThroughError(errors.BzrError):
620
 
 
 
553
    
621
554
    _fmt = """Pass through %(foo)s and %(bar)s"""
622
555
 
623
556
    def __init__(self, foo, bar):
634
567
 
635
568
 
636
569
class TestErrorFormatting(TestCase):
637
 
 
 
570
    
638
571
    def test_always_str(self):
639
572
        e = PassThroughError(u'\xb5', 'bar')
640
573
        self.assertIsInstance(e.__str__(), str)
651
584
                ['ErrorWithNoFormat uses its docstring as a format, it should use _fmt instead'],
652
585
                lambda x: str(x), e)
653
586
        ## s = str(e)
654
 
        self.assertEqual(s,
 
587
        self.assertEqual(s, 
655
588
                "This class has a docstring but no format string.")
656
589
 
657
590
    def test_mismatched_format_args(self):