Exemplo n.º 1
0
def test_get_name_reduction():
    # Existing reduction
    reduction = UnitByte.get_name_reduction(UnitByte.megabyte)
    assert reduction is 'MB'
    # Non-existing reduction
    reduction = UnitByte.get_name_reduction('Non-existing reduction')
    assert reduction is None
Exemplo n.º 2
0
 def byte_value(value):
     formatted_value = ''
     if isinstance(value, (int, float)):
         value, unit = UnitByte.auto_convert(value)
         value = '{:.2f}'.format(value)
         unit = UnitByte.get_name_reduction(unit)
         formatted_value = value + unit
     return formatted_value
Exemplo n.º 3
0
 def _format_bytes(self, byte_value):
     try:
         if (byte_value is None) or (byte_value == 0):
             byte_value = '0'
         elif isinstance(byte_value, (int, float)):
             val, unit = UnitByte.auto_convert(byte_value)
             byte_value = '{:.2f}'.format(val) + \
                          UnitByte.get_name_reduction(unit)
     finally:
         return byte_value
Exemplo n.º 4
0
 def _format_bytes(self, byte_value):
     try:
         if (byte_value is None) or (byte_value == 0):
             byte_value = '0'
         elif isinstance(byte_value, (int, float)):
             val, unit = UnitByte.auto_convert(byte_value)
             byte_value = '{:.2f}'.format(val) + \
                          UnitByte.get_name_reduction(unit)
     finally:
         return byte_value