Esempio n. 1
0
 def printable_amount(self):
     unit = self.unit
     if self.amount == 0:
         unit = 'OUNCE'
     if getattr(self.recipe, 'unit_system', None) == 'METRIC':
         return UnitConvert.to_str(*to_metric(self.amount, unit))
     return UnitConvert.to_str(self.amount, unit)
Esempio n. 2
0
 def printable_amount(self):
     unit = self.unit
     if self.amount == 0:
         unit = 'OUNCE'
     if getattr(self.recipe, 'unit_system', None) == 'METRIC':
         return UnitConvert.to_str(*to_metric(self.amount, unit))
     return UnitConvert.to_str(self.amount, unit)
Esempio n. 3
0
    def test_opposites(self):
        original = '5 lb 4 oz'
        units = UnitConvert.from_str(original)
        assert original == UnitConvert.to_str(*units)

        original = (5.25, 'POUND')
        string = UnitConvert.to_str(*original)
        assert original == UnitConvert.from_str(string)
Esempio n. 4
0
    def test_opposites(self):
        original = '5 lb 4 oz'
        units = UnitConvert.from_str(original)
        assert original == UnitConvert.to_str(*units)

        original = (5.25, 'POUND')
        string = UnitConvert.to_str(*original)
        assert original == UnitConvert.from_str(string)
Esempio n. 5
0
    def test_pound_ounce_conversion(self):
        amount, unit = UnitConvert.from_str("2lb 8oz")
        assert (amount, unit) == (2.5, "POUND")

        amount, unit = UnitConvert.from_str("2.5lb 8oz")
        assert (amount, unit) == (3, "POUND")

        amount, unit = UnitConvert.from_str("2.5lb 8.5oz")
        assert (amount, unit) == (3.03125, "POUND")
Esempio n. 6
0
    def test_pound_ounce_conversion(self):
        amount, unit = UnitConvert.from_str('2lb 8oz')
        assert (amount, unit) == (2.5, 'POUND')

        amount, unit = UnitConvert.from_str('2.5lb 8oz')
        assert (amount, unit) == (3, 'POUND')

        amount, unit = UnitConvert.from_str('2.5lb 8.5oz')
        assert (amount, unit) == (3.03125, 'POUND')
Esempio n. 7
0
    def test_pound_ounce_conversion(self):
        amount, unit = UnitConvert.from_str('2lb 8oz')
        assert (amount, unit) == (2.5, 'POUND')

        amount, unit = UnitConvert.from_str('2.5lb 8oz')
        assert (amount, unit) == (3, 'POUND')

        amount, unit = UnitConvert.from_str('2.5lb 8.5oz')
        assert (amount, unit) == (3.03125, 'POUND')
Esempio n. 8
0
 def test_simple_conversion_decimal_format(self):
     assert UnitConvert.to_str(5.0, 'POUND') == '5 lb'
     assert UnitConvert.to_str(5.0, 'OUNCE') == '5 oz'
     assert UnitConvert.to_str(5.0, 'GRAM') == '5 g'
     assert UnitConvert.to_str(5.0, 'TEASPOON') == '5 t'
     assert UnitConvert.to_str(5.0, 'TABLESPOON') == '5 T'
     assert UnitConvert.to_str(5.0, 'GALLON') == '5 Gal'
     assert UnitConvert.to_str(5.0, 'LITER') == '5 L'
Esempio n. 9
0
 def test_simple_conversion_decimal_format(self):
     assert UnitConvert.to_str(5.0, "POUND") == "5 lb"
     assert UnitConvert.to_str(5.0, "OUNCE") == "5 oz"
     assert UnitConvert.to_str(5.0, "GRAM") == "5 g"
     assert UnitConvert.to_str(5.0, "TEASPOON") == "5 t"
     assert UnitConvert.to_str(5.0, "TABLESPOON") == "5 T"
     assert UnitConvert.to_str(5.0, "GALLON") == "5 Gal"
     assert UnitConvert.to_str(5.0, "LITER") == "5 L"
Esempio n. 10
0
 def test_decimal_conversion(self):
     assert UnitConvert.to_str(5.1, 'POUND') == '5.1 lb'
     assert UnitConvert.to_str(5.1, 'OUNCE') == '5.1 oz'
     assert UnitConvert.to_str(5.1, 'GRAM') == '5.1 g'
     assert UnitConvert.to_str(5.1, 'TEASPOON') == '5.1 t'
     assert UnitConvert.to_str(5.1, 'TABLESPOON') == '5.1 T'
     assert UnitConvert.to_str(5.1, 'GALLON') == '5.1 Gal'
     assert UnitConvert.to_str(5.1, 'LITER') == '5.1 L'
Esempio n. 11
0
 def test_decimal_conversion(self):
     assert UnitConvert.to_str(5.1, 'POUND') == '5.1 lb'
     assert UnitConvert.to_str(5.1, 'OUNCE') == '5.1 oz'
     assert UnitConvert.to_str(5.1, 'GRAM') == '5.1 g'
     assert UnitConvert.to_str(5.1, 'TEASPOON') == '5.1 t'
     assert UnitConvert.to_str(5.1, 'TABLESPOON') == '5.1 T'
     assert UnitConvert.to_str(5.1, 'GALLON') == '5.1 Gal'
     assert UnitConvert.to_str(5.1, 'LITER') == '5.1 L'
Esempio n. 12
0
 def test_simple_conversion_decimal_format(self):
     assert UnitConvert.to_str(5.0, 'POUND') == '5 lb'
     assert UnitConvert.to_str(5.0, 'OUNCE') == '5 oz'
     assert UnitConvert.to_str(5.0, 'GRAM') == '5 g'
     assert UnitConvert.to_str(5.0, 'TEASPOON') == '5 t'
     assert UnitConvert.to_str(5.0, 'TABLESPOON') == '5 T'
     assert UnitConvert.to_str(5.0, 'GALLON') == '5 Gal'
     assert UnitConvert.to_str(5.0, 'LITER') == '5 L'
Esempio n. 13
0
 def test_decimal_conversion(self):
     assert UnitConvert.to_str(5.1, "POUND") == "5.1 lb"
     assert UnitConvert.to_str(5.1, "OUNCE") == "5.1 oz"
     assert UnitConvert.to_str(5.1, "GRAM") == "5.1 g"
     assert UnitConvert.to_str(5.1, "TEASPOON") == "5.1 t"
     assert UnitConvert.to_str(5.1, "TABLESPOON") == "5.1 T"
     assert UnitConvert.to_str(5.1, "GALLON") == "5.1 Gal"
     assert UnitConvert.to_str(5.1, "LITER") == "5.1 L"
Esempio n. 14
0
    def test_pound(self):
        amount, unit = UnitConvert.from_str('2lb')
        assert (amount, unit) == (2, 'POUND')

        amount, unit = UnitConvert.from_str('2Lb')
        assert (amount, unit) == (2, 'POUND')

        amount, unit = UnitConvert.from_str('2LB')
        assert (amount, unit) == (2, 'POUND')

        amount, unit = UnitConvert.from_str('2 lb')
        assert (amount, unit) == (2, 'POUND')

        amount, unit = UnitConvert.from_str('2 Lb')
        assert (amount, unit) == (2, 'POUND')

        amount, unit = UnitConvert.from_str('2 LB')
        assert (amount, unit) == (2, 'POUND')
Esempio n. 15
0
    def test_pound(self):
        amount, unit = UnitConvert.from_str("2lb")
        assert (amount, unit) == (2, "POUND")

        amount, unit = UnitConvert.from_str("2Lb")
        assert (amount, unit) == (2, "POUND")

        amount, unit = UnitConvert.from_str("2LB")
        assert (amount, unit) == (2, "POUND")

        amount, unit = UnitConvert.from_str("2 lb")
        assert (amount, unit) == (2, "POUND")

        amount, unit = UnitConvert.from_str("2 Lb")
        assert (amount, unit) == (2, "POUND")

        amount, unit = UnitConvert.from_str("2 LB")
        assert (amount, unit) == (2, "POUND")
Esempio n. 16
0
    def test_pound(self):
        amount, unit = UnitConvert.from_str('2lb')
        assert (amount, unit) == (2, 'POUND')

        amount, unit = UnitConvert.from_str('2Lb')
        assert (amount, unit) == (2, 'POUND')

        amount, unit = UnitConvert.from_str('2LB')
        assert (amount, unit) == (2, 'POUND')

        amount, unit = UnitConvert.from_str('2 lb')
        assert (amount, unit) == (2, 'POUND')

        amount, unit = UnitConvert.from_str('2 Lb')
        assert (amount, unit) == (2, 'POUND')

        amount, unit = UnitConvert.from_str('2 LB')
        assert (amount, unit) == (2, 'POUND')
Esempio n. 17
0
    def test_pair_detection(self):
        """
        Coverage for UnitConvert.__pairs__
        """

        # Simple
        pairs = UnitConvert.__pairs__("2lb")
        assert pairs == [(2.0, "POUND")]

        pairs = UnitConvert.__pairs__("2Lb")
        assert pairs == [(2.0, "POUND")]

        pairs = UnitConvert.__pairs__("2lb 5oz")
        assert pairs == [(2.0, "POUND"), (5.0, "OUNCE")]

        pairs = UnitConvert.__pairs__("2.5lb 5oz")
        assert pairs == [(2.5, "POUND"), (5.0, "OUNCE")]

        pairs = UnitConvert.__pairs__("2.5lb 5.5oz")
        assert pairs == [(2.5, "POUND"), (5.5, "OUNCE")]

        # Abbreviation (period)
        pairs = UnitConvert.__pairs__("2lb.")
        assert pairs == [(2.0, "POUND")]

        pairs = UnitConvert.__pairs__("2lb. 5oz.")
        assert pairs == [(2.0, "POUND"), (5.0, "OUNCE")]

        pairs = UnitConvert.__pairs__("2.5lb. 5oz.")
        assert pairs == [(2.5, "POUND"), (5.0, "OUNCE")]

        pairs = UnitConvert.__pairs__("2.5lb. 5.5oz.")
        assert pairs == [(2.5, "POUND"), (5.5, "OUNCE")]

        # Missing spacing
        pairs = UnitConvert.__pairs__("2lb5oz")
        assert pairs == [(2.0, "POUND"), (5.0, "OUNCE")]

        pairs = UnitConvert.__pairs__("2.5lb5oz")
        assert pairs == [(2.5, "POUND"), (5.0, "OUNCE")]

        pairs = UnitConvert.__pairs__("2.5lb5.5oz")
        assert pairs == [(2.5, "POUND"), (5.5, "OUNCE")]

        pairs = UnitConvert.__pairs__("2lb.5oz")
        assert pairs == [(2.0, "POUND"), (0.5, "OUNCE")]

        pairs = UnitConvert.__pairs__("2.5lb.5oz")
        assert pairs == [(2.5, "POUND"), (0.5, "OUNCE")]

        pairs = UnitConvert.__pairs__("2.5lb5.5oz")
        assert pairs == [(2.5, "POUND"), (5.5, "OUNCE")]

        pairs = UnitConvert.__pairs__("2lb.5oz.")
        assert pairs == [(2.0, "POUND"), (0.5, "OUNCE")]
Esempio n. 18
0
 def test_zero_amount(self):
     assert UnitConvert.to_str(0, "POUND") == "0 lb"
Esempio n. 19
0
 def test_pound_ounce_expansion(self):
     assert UnitConvert.to_str(5.25, "POUND") == "5 lb 4 oz"
     assert UnitConvert.to_str(0.25, "POUND") == "4 oz"
Esempio n. 20
0
 def test_unitless_amount(self):
     assert UnitConvert.to_str(5, None) == '5'
     assert UnitConvert.to_str(5.0, None) == '5'
     assert UnitConvert.to_str(5.25, None) == '5.25'
Esempio n. 21
0
    def test_ounce_conversion(self):
        amount, unit = UnitConvert.from_str('8oz')
        assert (amount, unit) == (.5, 'POUND')

        amount, unit = UnitConvert.from_str('8.5oz')
        assert (amount, unit) == (.53125, 'POUND')
Esempio n. 22
0
 def test_coerce_amounts(self):
     assert UnitConvert.__coerce_amounts__(['525.75']) == [525.75]
Esempio n. 23
0
 def test_pound_ounce_expansion(self):
     assert UnitConvert.to_str(5.25, 'POUND') == '5 lb 4 oz'
     assert UnitConvert.to_str(.25, 'POUND') == '4 oz'
Esempio n. 24
0
 def test_basic_conversion(self):
     for abbr, value in UNIT_MAP.items():
         if value not in ('OUNCE', 'GRAM', 'KILOGRAM'):
             assert UnitConvert.from_str('5%s' % abbr) == (5,
                                                           UNIT_MAP[abbr])
Esempio n. 25
0
 def test_ounce_conversion(self):
     assert UnitConvert.from_str('8oz') == (.5, 'POUND')
Esempio n. 26
0
    def printable_amount(self):
        if getattr(self.recipe, 'unit_system', None) == 'METRIC':
            return UnitConvert.to_str(*to_metric(self.amount, self.unit))

        return UnitConvert.to_str(self.amount, self.unit)
Esempio n. 27
0
    def test_pair_detection(self):
        """
        Coverage for UnitConvert.__pairs__
        """

        # Simple
        pairs = UnitConvert.__pairs__('2lb')
        assert pairs == [(2.0, 'POUND')]

        pairs = UnitConvert.__pairs__('2Lb')
        assert pairs == [(2.0, 'POUND')]

        pairs = UnitConvert.__pairs__('2lb 5oz')
        assert pairs == [(2.0, 'POUND'), (5.0, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb 5oz')
        assert pairs == [(2.5, 'POUND'), (5.0, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb 5.5oz')
        assert pairs == [(2.5, 'POUND'), (5.5, 'OUNCE')]

        # Abbreviation (period)
        pairs = UnitConvert.__pairs__('2lb.')
        assert pairs == [(2.0, 'POUND')]

        pairs = UnitConvert.__pairs__('2lb. 5oz.')
        assert pairs == [(2.0, 'POUND'), (5.0, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb. 5oz.')
        assert pairs == [(2.5, 'POUND'), (5.0, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb. 5.5oz.')
        assert pairs == [(2.5, 'POUND'), (5.5, 'OUNCE')]

        # Missing spacing
        pairs = UnitConvert.__pairs__('2lb5oz')
        assert pairs == [(2.0, 'POUND'), (5.0, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb5oz')
        assert pairs == [(2.5, 'POUND'), (5.0, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb5.5oz')
        assert pairs == [(2.5, 'POUND'), (5.5, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2lb.5oz')
        assert pairs == [(2.0, 'POUND'), (.5, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb.5oz')
        assert pairs == [(2.5, 'POUND'), (.5, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb5.5oz')
        assert pairs == [(2.5, 'POUND'), (5.5, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2lb.5oz.')
        assert pairs == [(2.0, 'POUND'), (.5, 'OUNCE')]
Esempio n. 28
0
 def test_gram_conversion(self):
     assert UnitConvert.from_str('453.59237g') == (1, 'POUND')
Esempio n. 29
0
    def printable_amount(self):
        if getattr(self.recipe, 'unit_system', None) == 'METRIC':
            return UnitConvert.to_str(*to_metric(self.amount, self.unit))

        return UnitConvert.to_str(self.amount, self.unit)
Esempio n. 30
0
 def test_basic_conversion(self):
     for abbr, value in UNIT_MAP.items():
         if value not in ('OUNCE', 'GRAM', 'KILOGRAM'):
             assert UnitConvert.from_str('5%s' % abbr) == (5, UNIT_MAP[abbr])
Esempio n. 31
0
    def test_pound_conversion(self):
        amount, unit = UnitConvert.from_str('2lb')
        assert (amount, unit) == (2, 'POUND')

        amount, unit = UnitConvert.from_str('2.5lb')
        assert (amount, unit) == (2.5, 'POUND')
Esempio n. 32
0
 def test_gram_conversion(self):
     assert UnitConvert.from_str('453.59237g') == (1, 'POUND')
Esempio n. 33
0
    def test_coerce_units(self):
        assert UnitConvert.__coerce_units__(['lb']) == ['POUND']
        assert UnitConvert.__coerce_units__(['lbs']) == ['POUND']
        assert UnitConvert.__coerce_units__(['pound']) == ['POUND']
        assert UnitConvert.__coerce_units__(['Pound']) == ['POUND']
        assert UnitConvert.__coerce_units__(['pounds']) == ['POUND']
        assert UnitConvert.__coerce_units__(['Pounds']) == ['POUND']

        assert UnitConvert.__coerce_units__(['oz']) == ['OUNCE']
        assert UnitConvert.__coerce_units__(['ounce']) == ['OUNCE']
        assert UnitConvert.__coerce_units__(['ounces']) == ['OUNCE']
        assert UnitConvert.__coerce_units__(['Ounce']) == ['OUNCE']
        assert UnitConvert.__coerce_units__(['Ounces']) == ['OUNCE']

        assert UnitConvert.__coerce_units__(['g']) == ['GRAM']
        assert UnitConvert.__coerce_units__(['gram']) == ['GRAM']
        assert UnitConvert.__coerce_units__(['Gram']) == ['GRAM']
        assert UnitConvert.__coerce_units__(['grams']) == ['GRAM']
        assert UnitConvert.__coerce_units__(['Grams']) == ['GRAM']

        assert UnitConvert.__coerce_units__(['kg']) == ['KILOGRAM']
        assert UnitConvert.__coerce_units__(['kilogram']) == ['KILOGRAM']
        assert UnitConvert.__coerce_units__(['Kilogram']) == ['KILOGRAM']
        assert UnitConvert.__coerce_units__(['kilograms']) == ['KILOGRAM']
        assert UnitConvert.__coerce_units__(['Kilograms']) == ['KILOGRAM']

        assert UnitConvert.__coerce_units__(['t']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['ts']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['tsp']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['tspn']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['teaspoon']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['teaspoons']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['Teaspoon']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['Teaspoons']) == ['TEASPOON']

        assert UnitConvert.__coerce_units__(['T']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['tbs']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['tbsp']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['tblsp']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['tblspn']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['tablespoon']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['tablespoons']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['Tablespoon']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['Tablespoons']) == ['TABLESPOON']

        assert UnitConvert.__coerce_units__(['G']) == ['GALLON']
        assert UnitConvert.__coerce_units__(['gal']) == ['GALLON']
        assert UnitConvert.__coerce_units__(['Gal']) == ['GALLON']
        assert UnitConvert.__coerce_units__(['gallon']) == ['GALLON']
        assert UnitConvert.__coerce_units__(['Gallon']) == ['GALLON']
        assert UnitConvert.__coerce_units__(['gallons']) == ['GALLON']
        assert UnitConvert.__coerce_units__(['Gallons']) == ['GALLON']
        
        assert UnitConvert.__coerce_units__(['l']) == ['LITER']
        assert UnitConvert.__coerce_units__(['L']) == ['LITER']
        assert UnitConvert.__coerce_units__(['liter']) == ['LITER']
        assert UnitConvert.__coerce_units__(['Liter']) == ['LITER']
        assert UnitConvert.__coerce_units__(['liters']) == ['LITER']
        assert UnitConvert.__coerce_units__(['Liters']) == ['LITER']

        with raises(InvalidUnitException):
            UnitConvert.__coerce_units__(['Invalid'])
            UnitConvert.__coerce_units__([''])
Esempio n. 34
0
    def test_unitless_conversion(self):
        amount, unit = UnitConvert.from_str('5')
        assert (amount, unit) == (5, None)

        amount, unit = UnitConvert.from_str('5.25')
        assert (amount, unit) == (5.25, None)
Esempio n. 35
0
    def test_pound_conversion(self):
        amount, unit = UnitConvert.from_str('2lb')
        assert (amount, unit) == (2, 'POUND')

        amount, unit = UnitConvert.from_str('2.5lb')
        assert (amount, unit) == (2.5, 'POUND')
Esempio n. 36
0
    def test_unitless_conversion(self):
        amount, unit = UnitConvert.from_str('5')
        assert (amount, unit) == (5, None)

        amount, unit = UnitConvert.from_str('5.25')
        assert (amount, unit) == (5.25, None)
Esempio n. 37
0
 def test_zero_amount(self):
     assert UnitConvert.to_str(0, 'POUND') == '0 lb'
Esempio n. 38
0
 def test_zero_amount(self):
     assert UnitConvert.to_str(0, 'POUND') == '0 lb'
Esempio n. 39
0
 def test_ounce_conversion(self):
     assert UnitConvert.from_str('8oz') == (.5, 'POUND')
Esempio n. 40
0
    def test_ounce_conversion(self):
        amount, unit = UnitConvert.from_str('8oz')
        assert (amount, unit) == (.5, 'POUND')

        amount, unit = UnitConvert.from_str('8.5oz')
        assert (amount, unit) == (.53125, 'POUND')
Esempio n. 41
0
 def test_kilogram_conversion(self):
     assert UnitConvert.from_str('.45359237kg') == (1, 'POUND')
Esempio n. 42
0
    def test_coerce_units(self):
        assert UnitConvert.__coerce_units__(['lb']) == ['POUND']
        assert UnitConvert.__coerce_units__(['lbs']) == ['POUND']
        assert UnitConvert.__coerce_units__(['pound']) == ['POUND']
        assert UnitConvert.__coerce_units__(['Pound']) == ['POUND']
        assert UnitConvert.__coerce_units__(['pounds']) == ['POUND']
        assert UnitConvert.__coerce_units__(['Pounds']) == ['POUND']

        assert UnitConvert.__coerce_units__(['oz']) == ['OUNCE']
        assert UnitConvert.__coerce_units__(['ounce']) == ['OUNCE']
        assert UnitConvert.__coerce_units__(['ounces']) == ['OUNCE']
        assert UnitConvert.__coerce_units__(['Ounce']) == ['OUNCE']
        assert UnitConvert.__coerce_units__(['Ounces']) == ['OUNCE']

        assert UnitConvert.__coerce_units__(['g']) == ['GRAM']
        assert UnitConvert.__coerce_units__(['gram']) == ['GRAM']
        assert UnitConvert.__coerce_units__(['Gram']) == ['GRAM']
        assert UnitConvert.__coerce_units__(['grams']) == ['GRAM']
        assert UnitConvert.__coerce_units__(['Grams']) == ['GRAM']

        assert UnitConvert.__coerce_units__(['kg']) == ['KILOGRAM']
        assert UnitConvert.__coerce_units__(['kilogram']) == ['KILOGRAM']
        assert UnitConvert.__coerce_units__(['Kilogram']) == ['KILOGRAM']
        assert UnitConvert.__coerce_units__(['kilograms']) == ['KILOGRAM']
        assert UnitConvert.__coerce_units__(['Kilograms']) == ['KILOGRAM']

        assert UnitConvert.__coerce_units__(['t']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['ts']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['tsp']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['tspn']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['teaspoon']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['teaspoons']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['Teaspoon']) == ['TEASPOON']
        assert UnitConvert.__coerce_units__(['Teaspoons']) == ['TEASPOON']

        assert UnitConvert.__coerce_units__(['T']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['tbs']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['tbsp']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['tblsp']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['tblspn']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['tablespoon']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['tablespoons']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['Tablespoon']) == ['TABLESPOON']
        assert UnitConvert.__coerce_units__(['Tablespoons']) == ['TABLESPOON']

        assert UnitConvert.__coerce_units__(['G']) == ['GALLON']
        assert UnitConvert.__coerce_units__(['gal']) == ['GALLON']
        assert UnitConvert.__coerce_units__(['Gal']) == ['GALLON']
        assert UnitConvert.__coerce_units__(['gallon']) == ['GALLON']
        assert UnitConvert.__coerce_units__(['Gallon']) == ['GALLON']
        assert UnitConvert.__coerce_units__(['gallons']) == ['GALLON']
        assert UnitConvert.__coerce_units__(['Gallons']) == ['GALLON']

        assert UnitConvert.__coerce_units__(['l']) == ['LITER']
        assert UnitConvert.__coerce_units__(['L']) == ['LITER']
        assert UnitConvert.__coerce_units__(['liter']) == ['LITER']
        assert UnitConvert.__coerce_units__(['Liter']) == ['LITER']
        assert UnitConvert.__coerce_units__(['liters']) == ['LITER']
        assert UnitConvert.__coerce_units__(['Liters']) == ['LITER']

        with self.assertRaises(InvalidUnitException):
            UnitConvert.__coerce_units__(['Invalid'])
            UnitConvert.__coerce_units__([''])
Esempio n. 43
0
 def test_ounce_conversion(self):
     assert UnitConvert.from_str("8oz") == (0.5, "POUND")
Esempio n. 44
0
 def test_kilogram_conversion(self):
     assert UnitConvert.from_str('.45359237kg') == (1, 'POUND')
Esempio n. 45
0
 def test_pound_ounce_expansion(self):
     assert UnitConvert.to_str(5.25, 'POUND') == '5 lb 4 oz'
     assert UnitConvert.to_str(.25, 'POUND') == '4 oz'
Esempio n. 46
0
 def test_gram_conversion(self):
     assert UnitConvert.from_str("453.59237g") == (1, "POUND")
Esempio n. 47
0
 def test_unitless_amount(self):
     assert UnitConvert.to_str(5, None) == '5'
     assert UnitConvert.to_str(5.0, None) == '5'
     assert UnitConvert.to_str(5.25, None) == '5.25'
Esempio n. 48
0
 def test_kilogram_conversion(self):
     assert UnitConvert.from_str(".45359237kg") == (1, "POUND")
Esempio n. 49
0
    def test_pair_detection(self):
        """
        Coverage for UnitConvert.__pairs__
        """

        # Simple
        pairs = UnitConvert.__pairs__('2lb')
        assert pairs == [(2.0, 'POUND')]

        pairs = UnitConvert.__pairs__('2Lb')
        assert pairs == [(2.0, 'POUND')]

        pairs = UnitConvert.__pairs__('2lb 5oz')
        assert pairs == [(2.0, 'POUND'), (5.0, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb 5oz')
        assert pairs == [(2.5, 'POUND'), (5.0, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb 5.5oz')
        assert pairs == [(2.5, 'POUND'), (5.5, 'OUNCE')]

        # Abbreviation (period)
        pairs = UnitConvert.__pairs__('2lb.')
        assert pairs == [(2.0, 'POUND')]

        pairs = UnitConvert.__pairs__('2lb. 5oz.')
        assert pairs == [(2.0, 'POUND'), (5.0, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb. 5oz.')
        assert pairs == [(2.5, 'POUND'), (5.0, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb. 5.5oz.')
        assert pairs == [(2.5, 'POUND'), (5.5, 'OUNCE')]

        # Missing spacing
        pairs = UnitConvert.__pairs__('2lb5oz')
        assert pairs == [(2.0, 'POUND'), (5.0, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb5oz')
        assert pairs == [(2.5, 'POUND'), (5.0, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb5.5oz')
        assert pairs == [(2.5, 'POUND'), (5.5, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2lb.5oz')
        assert pairs == [(2.0, 'POUND'), (.5, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb.5oz')
        assert pairs == [(2.5, 'POUND'), (.5, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2.5lb5.5oz')
        assert pairs == [(2.5, 'POUND'), (5.5, 'OUNCE')]

        pairs = UnitConvert.__pairs__('2lb.5oz.')
        assert pairs == [(2.0, 'POUND'), (.5, 'OUNCE')]
Esempio n. 50
0
 def test_coerce_amounts(self):
     assert UnitConvert.__coerce_amounts__(['525.75']) == [525.75]