def getint(self, *args, **kwargs): """A convenience method which coerces the configparser option in the specified section to an integer. This method will also convert a byte-descriptive string (e.g. '20KiB') to the integer value representing the number of bytes (20480). :param string section: the section to get the option from. :param string option: the option to be fetched. :param args: See :func:`configparser.ConfigParser.get` for documentation of additional arguments. :param kwargs: See :func:`configparser.ConfigParser.get` for additional keyword arguments. :raises ConfigNotInitialisedError: raised if self.config has not been been successfully intialised. :raises configparser.NoSectionError: raised if the specified section does not exist. """ try: return self.config.getint(*args, **kwargs) except Exception as e: str_val = self.config.get(*args, **kwargs) try: return conversions.unit_of_information_in_bytes(str_val) # If byte conversion fails, maybe this is just a # 'normal' string - raise the original exception. except conversions.UnitOfInformationConversionError: raise e
def test_1TB_value(self): """FIXME""" byte = 1 kb = 1000 * byte mb = 1000 * kb gb = 1000 * mb tb = 1000 * gb result = conversions.unit_of_information_in_bytes("1TB") self.assertEqual(result, tb)
def test_1TIB_value(self): """FIXME""" byte = 1 kib = 1024 * byte mib = 1024 * kib gib = 1024 * mib tib = 1024 * gib result = conversions.unit_of_information_in_bytes("1TIB") self.assertEqual(result, tib)
def test_in_str_spacing(self): """FIXME""" result = conversions.unit_of_information_in_bytes("1 KB") self.assertEqual(result, 1000)
def test_1ki_value(self): """FIXME""" result = conversions.unit_of_information_in_bytes("1ki") self.assertEqual(result, 1024)
def test_unparsable(self): """FIXME""" with self.assertRaises(conversions.UnitOfInformationConversionError): conversions.unit_of_information_in_bytes("unparsable")
def test_suffixless_number(self): """FIXME""" result = conversions.unit_of_information_in_bytes("1") self.assertEqual(result, 1)