1080
1080
self.assertEqual(None, get_si('non-exist'))
1081
1081
self.assertEqual(42, get_si('non-exist-with-default', 42))
1083
1084
class TestSupressWarning(TestIniConfig):
1085
1086
def make_warnings_config(self, s):
2358
2359
class TestOptionConverterMixin(object):
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,))
2363
2365
def assertWarns(self, opt, value):
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')
2428
class TestOptionWithSIUnitConverter(tests.TestCase, TestOptionConverterMixin):
2430
def get_option(self):
2431
return config.Option('foo', help='An integer in SI units.',
2432
from_unicode=config.int_SI_from_store)
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')
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')
2425
2453
class TestOptionWithListConverter(tests.TestCase, TestOptionConverterMixin):
2427
2455
def get_option(self):