~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-08 17:09:38 UTC
  • mfrom: (3287.20.5 non_utf8_77657)
  • Revision ID: pqm@pqm.ubuntu.com-20080708170938-gt3lvh2xejc4w8vf
(jam) Give a better error when encountering a bad filename (bug
        #77657)

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
                              'a test message\n')
104
104
 
105
105
 
 
106
class TestUnicodeFilename(TestCase):
 
107
 
 
108
    def test_probe_passes(self):
 
109
        """UnicodeFilename._probe passes."""
 
110
        # We can't test much more than that because the behaviour depends
 
111
        # on the platform.
 
112
        tests.UnicodeFilename._probe()
 
113
 
 
114
 
106
115
class TestTreeShape(TestCaseInTempDir):
107
116
 
108
117
    def test_unicode_paths(self):
 
118
        self.requireFeature(tests.UnicodeFilename)
 
119
 
109
120
        filename = u'hell\u00d8'
110
 
        try:
111
 
            self.build_tree_contents([(filename, 'contents of hello')])
112
 
        except UnicodeEncodeError:
113
 
            raise TestSkipped("can't build unicode working tree in "
114
 
                "filesystem encoding %s" % sys.getfilesystemencoding())
 
121
        self.build_tree_contents([(filename, 'contents of hello')])
115
122
        self.failUnlessExists(filename)
116
123
 
117
124
 
1283
1290
    def _test_pass(self):
1284
1291
        pass
1285
1292
 
 
1293
class _TestException(Exception):
 
1294
    pass
1286
1295
 
1287
1296
class TestTestCase(TestCase):
1288
1297
    """Tests that test the core bzrlib TestCase."""
1446
1455
            ],
1447
1456
            result.calls)
1448
1457
 
 
1458
    def test_assert_list_raises_on_generator(self):
 
1459
        def generator_which_will_raise():
 
1460
            # This will not raise until after the first yield
 
1461
            yield 1
 
1462
            raise _TestException()
 
1463
 
 
1464
        e = self.assertListRaises(_TestException, generator_which_will_raise)
 
1465
        self.assertIsInstance(e, _TestException)
 
1466
 
 
1467
        e = self.assertListRaises(Exception, generator_which_will_raise)
 
1468
        self.assertIsInstance(e, _TestException)
 
1469
 
 
1470
    def test_assert_list_raises_on_plain(self):
 
1471
        def plain_exception():
 
1472
            raise _TestException()
 
1473
            return []
 
1474
 
 
1475
        e = self.assertListRaises(_TestException, plain_exception)
 
1476
        self.assertIsInstance(e, _TestException)
 
1477
 
 
1478
        e = self.assertListRaises(Exception, plain_exception)
 
1479
        self.assertIsInstance(e, _TestException)
 
1480
 
 
1481
    def test_assert_list_raises_assert_wrong_exception(self):
 
1482
        class _NotTestException(Exception):
 
1483
            pass
 
1484
 
 
1485
        def wrong_exception():
 
1486
            raise _NotTestException()
 
1487
 
 
1488
        def wrong_exception_generator():
 
1489
            yield 1
 
1490
            yield 2
 
1491
            raise _NotTestException()
 
1492
 
 
1493
        # Wrong exceptions are not intercepted
 
1494
        self.assertRaises(_NotTestException,
 
1495
            self.assertListRaises, _TestException, wrong_exception)
 
1496
        self.assertRaises(_NotTestException,
 
1497
            self.assertListRaises, _TestException, wrong_exception_generator)
 
1498
 
 
1499
    def test_assert_list_raises_no_exception(self):
 
1500
        def success():
 
1501
            return []
 
1502
 
 
1503
        def success_generator():
 
1504
            yield 1
 
1505
            yield 2
 
1506
 
 
1507
        self.assertRaises(AssertionError,
 
1508
            self.assertListRaises, _TestException, success)
 
1509
 
 
1510
        self.assertRaises(AssertionError,
 
1511
            self.assertListRaises, _TestException, success_generator)
 
1512
 
1449
1513
 
1450
1514
@symbol_versioning.deprecated_function(zero_eleven)
1451
1515
def sample_deprecated_function():