~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Patch Queue Manager
  • Date: 2011-12-19 17:14:34 UTC
  • mfrom: (6378.1.5 config-si-unit)
  • Revision ID: pqm@pqm.ubuntu.com-20111219171434-i0b4ir0invs9il2v
(vila) Migrate add.maximum_file_size configuration option. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
537
537
 
538
538
    def test_log_format_default(self):
539
539
        my_config = config.Config()
540
 
        self.assertEqual('long', my_config.log_format())
 
540
        self.assertEqual('long',
 
541
                         self.applyDeprecated(deprecated_in((2, 5, 0)),
 
542
                                              my_config.log_format))
541
543
 
542
544
    def test_acceptable_keys_default(self):
543
545
        my_config = config.Config()
1069
1071
si_g = 5g,
1070
1072
si_gb = 5gB,
1071
1073
""")
1072
 
        get_si = conf.get_user_option_as_int_from_SI
 
1074
        def get_si(s, default=None):
 
1075
            return self.applyDeprecated(
 
1076
                deprecated_in((2, 5, 0)),
 
1077
                conf.get_user_option_as_int_from_SI, s, default)
1073
1078
        self.assertEqual(100, get_si('plain'))
1074
1079
        self.assertEqual(5000, get_si('si_k'))
1075
1080
        self.assertEqual(5000, get_si('si_kb'))
1080
1085
        self.assertEqual(None, get_si('non-exist'))
1081
1086
        self.assertEqual(42, get_si('non-exist-with-default',  42))
1082
1087
 
 
1088
 
1083
1089
class TestSupressWarning(TestIniConfig):
1084
1090
 
1085
1091
    def make_warnings_config(self, s):
1317
1323
 
1318
1324
    def test_configured_logformat(self):
1319
1325
        my_config = self._get_sample_config()
1320
 
        self.assertEqual("short", my_config.log_format())
 
1326
        self.assertEqual("short",
 
1327
                         self.applyDeprecated(deprecated_in((2, 5, 0)),
 
1328
                                              my_config.log_format))
1321
1329
 
1322
1330
    def test_configured_acceptable_keys(self):
1323
1331
        my_config = self._get_sample_config()
2358
2366
class TestOptionConverterMixin(object):
2359
2367
 
2360
2368
    def assertConverted(self, expected, opt, value):
2361
 
        self.assertEquals(expected, opt.convert_from_unicode(value))
 
2369
        self.assertEquals(expected, opt.convert_from_unicode(value),
 
2370
                          'Expecting %s, got %s' % (expected, value,))
2362
2371
 
2363
2372
    def assertWarns(self, opt, value):
2364
2373
        warnings = []
2377
2386
 
2378
2387
    def assertConvertInvalid(self, opt, invalid_value):
2379
2388
        opt.invalid = None
2380
 
        self.assertEquals(None, opt.convert_from_unicode(invalid_value))
 
2389
        self.assertEquals(None, opt.convert_from_unicode(invalid_value),
 
2390
                          '%s is not None' % (invalid_value,))
2381
2391
        opt.invalid = 'warning'
2382
2392
        self.assertWarns(opt, invalid_value)
2383
2393
        opt.invalid = 'error'
2422
2432
        self.assertConverted(16, opt, u'16')
2423
2433
 
2424
2434
 
 
2435
class TestOptionWithSIUnitConverter(tests.TestCase, TestOptionConverterMixin):
 
2436
 
 
2437
    def get_option(self):
 
2438
        return config.Option('foo', help='An integer in SI units.',
 
2439
                             from_unicode=config.int_SI_from_store)
 
2440
 
 
2441
    def test_convert_invalid(self):
 
2442
        opt = self.get_option()
 
2443
        self.assertConvertInvalid(opt, u'not-a-unit')
 
2444
        self.assertConvertInvalid(opt, u'Gb') # Forgot the int
 
2445
        self.assertConvertInvalid(opt, u'1b') # Forgot the unit
 
2446
        self.assertConvertInvalid(opt, u'1GG')
 
2447
        self.assertConvertInvalid(opt, u'1Mbb')
 
2448
        self.assertConvertInvalid(opt, u'1MM')
 
2449
 
 
2450
    def test_convert_valid(self):
 
2451
        opt = self.get_option()
 
2452
        self.assertConverted(int(5e3), opt, u'5kb')
 
2453
        self.assertConverted(int(5e6), opt, u'5M')
 
2454
        self.assertConverted(int(5e6), opt, u'5MB')
 
2455
        self.assertConverted(int(5e9), opt, u'5g')
 
2456
        self.assertConverted(int(5e9), opt, u'5gB')
 
2457
        self.assertConverted(100, opt, u'100')
 
2458
 
 
2459
 
2425
2460
class TestOptionWithListConverter(tests.TestCase, TestOptionConverterMixin):
2426
2461
 
2427
2462
    def get_option(self):