def from_quantity_units(cls, quantity, information_unit, duration_unit): """ Initialise a new speed object from a quantity and unit string. :param quantity: The number of the unit. :param information_unit: The information part of the unit, e.g. 'GiB'. :param duration_unit: The duration part of the unit, e.g. 'week'. :return: A `Speed` object representing the quantity and unit. """ information = Information.from_quantity_unit(quantity, information_unit) duration = Duration.from_quantity_unit(1, duration_unit) return Speed(information, duration)
def p_speed_constructor(self, p): 'speed : NUMBER speed_unit' logger.debug('speed = number %s, speed unit %s', p[1], p[2]) information_unit, duration = p[2] information = Information.from_quantity_unit(p[1], information_unit) p[0] = information.in_duration(duration)
def p_information_constructor(self, p): 'information : NUMBER INFORMATION_UNIT' logger.debug('information = number %s, information unit %s', p[1], p[2]) p[0] = Information.from_quantity_unit(p[1], p[2])
def test_from_quantity_unit(self): self.assertEqual(Information.from_quantity_unit(10.842, 'Gib'), Information(10.842, Information.GIBIBITS))