def test_best_prefix_identical_result(self):
        """NIST: instance.best_prefix returns the same type if nothing changes

Start with a NIST unit that is already prefectly sized, and apply
best_prefix() to it."""
        # This is our perfectly sized unit. No change was required
        should_be_EiB = bitmath.EiB(1).best_prefix()
        self.assertIs(type(should_be_EiB), bitmath.EiB)

        # Let's be thorough and do that one more time
        self.assertIs(type(should_be_EiB.best_prefix()), bitmath.EiB)
예제 #2
0
    def setUp(self):
        self.bit = bitmath.Bit(1)
        self.byte = bitmath.Byte(1)
        # NIST units
        self.kib = bitmath.KiB(1)
        self.mib = bitmath.MiB(1)
        self.gib = bitmath.GiB(1)
        self.tib = bitmath.TiB(1)
        self.pib = bitmath.PiB(1)
        self.eib = bitmath.EiB(1)

        # SI units
        self.kb = bitmath.kB(1)
        self.mb = bitmath.MB(1)
        self.gb = bitmath.GB(1)
        self.tb = bitmath.TB(1)
        self.pb = bitmath.PB(1)
        self.eb = bitmath.EB(1)
예제 #3
0
def size_to_bytes(human_size):
    PARSE_REGEXP = r"(\d+)([MGTPE]i)"
    parse = re.compile(PARSE_REGEXP)
    try:
        size, unit = re.match(parse, human_size).group(1, 2)
        size = int(size)
        assert size > 0

        if unit == 'Mi':
            return int(bitmath.MiB(size).to_Byte())
        elif unit == 'Gi':
            return int(bitmath.GiB(size).to_Byte())
        elif unit == 'Ti':
            return int(bitmath.TiB(size).to_Byte())
        elif unit == 'Pi':
            return int(bitmath.PiB(size).to_Byte())
        elif unit == 'Ei':
            return int(bitmath.EiB(size).to_Byte())
        else:
            return 0
    except Exception as e:
        return 0
 def test_extreme_oom_round_up(self):
     """NIST: 2048 EiB (as a KiB()) rounds up into an EiB()"""
     huge_KiB = bitmath.KiB.from_other(bitmath.EiB(1))
     self.assertIs(type(huge_KiB.best_prefix()), bitmath.EiB)
예제 #5
0
 def test_parse_Eio(self):
     """parse_string works on exbioctet strings"""
     self.assertEqual(
         bitmath.parse_string("654 Eio"),
         bitmath.EiB(654))