~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-12-16 16:20:01 UTC
  • mto: This revision was merged to the branch mainline in revision 6387.
  • Revision ID: v.ladeuil+lp@free.fr-20111216162001-qe39b3khelh34u1v
Add int_SI_from_store as a config option helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
1080
1080
        self.assertEqual(None, get_si('non-exist'))
1081
1081
        self.assertEqual(42, get_si('non-exist-with-default',  42))
1082
1082
 
 
1083
 
1083
1084
class TestSupressWarning(TestIniConfig):
1084
1085
 
1085
1086
    def make_warnings_config(self, s):
2358
2359
class TestOptionConverterMixin(object):
2359
2360
 
2360
2361
    def assertConverted(self, expected, opt, value):
2361
 
        self.assertEquals(expected, opt.convert_from_unicode(value))
 
2362
        self.assertEquals(expected, opt.convert_from_unicode(value),
 
2363
                          'Expecting %s, got %s' % (expected, value,))
2362
2364
 
2363
2365
    def assertWarns(self, opt, value):
2364
2366
        warnings = []
2377
2379
 
2378
2380
    def assertConvertInvalid(self, opt, invalid_value):
2379
2381
        opt.invalid = None
2380
 
        self.assertEquals(None, opt.convert_from_unicode(invalid_value))
 
2382
        self.assertEquals(None, opt.convert_from_unicode(invalid_value),
 
2383
                          '%s is not None' % (invalid_value,))
2381
2384
        opt.invalid = 'warning'
2382
2385
        self.assertWarns(opt, invalid_value)
2383
2386
        opt.invalid = 'error'
2422
2425
        self.assertConverted(16, opt, u'16')
2423
2426
 
2424
2427
 
 
2428
class TestOptionWithSIUnitConverter(tests.TestCase, TestOptionConverterMixin):
 
2429
 
 
2430
    def get_option(self):
 
2431
        return config.Option('foo', help='An integer in SI units.',
 
2432
                             from_unicode=config.int_SI_from_store)
 
2433
 
 
2434
    def test_convert_invalid(self):
 
2435
        opt = self.get_option()
 
2436
        self.assertConvertInvalid(opt, u'not-a-unit')
 
2437
        self.assertConvertInvalid(opt, u'Gb') # Forgot the int
 
2438
        self.assertConvertInvalid(opt, u'1b') # Forgot the unit
 
2439
        self.assertConvertInvalid(opt, u'1GG')
 
2440
        self.assertConvertInvalid(opt, u'1Mbb')
 
2441
        self.assertConvertInvalid(opt, u'1MM')
 
2442
 
 
2443
    def test_convert_valid(self):
 
2444
        opt = self.get_option()
 
2445
        self.assertConverted(int(5e3), opt, u'5kb')
 
2446
        self.assertConverted(int(5e6), opt, u'5M')
 
2447
        self.assertConverted(int(5e6), opt, u'5MB')
 
2448
        self.assertConverted(int(5e9), opt, u'5g')
 
2449
        self.assertConverted(int(5e9), opt, u'5gB')
 
2450
        self.assertConverted(100, opt, u'100')
 
2451
 
 
2452
 
2425
2453
class TestOptionWithListConverter(tests.TestCase, TestOptionConverterMixin):
2426
2454
 
2427
2455
    def get_option(self):