def test_prefix(self): val = NumberValue('test', default=1024, prefix='binary') self.assertEqual(val.get(), 1024) self.assertEqual(val.string(), '1Ki') self.assertEqual(val.prefix, 'binary') val.prefix = 'metric' self.assertEqual(val.get(), 1024) self.assertEqual(val.string(), '1.02k') self.assertEqual(val.prefix, 'metric') val.set(1000) self.assertEqual(val.get(), 1000) self.assertEqual(val.string(), '1k') self.assertEqual(val.prefix, 'metric') val.prefix = 'binary' self.assertEqual(val.get(), 1000) self.assertEqual(val.string(), '1000') self.assertEqual(val.prefix, 'binary')
def test___repr__(self): val = NumberValue(name='foo', default=42e3, unit='m', prefix='metric') self.assertEqual(repr(val), 'foo=42km') val.set(1024) val.prefix = 'binary' self.assertEqual(repr(val), 'foo=1Kim')