diff --git a/brew/grains.py b/brew/grains.py index a221171..c268f18 100644 --- a/brew/grains.py +++ b/brew/grains.py @@ -180,13 +180,14 @@ def __repr__(self): out = "{0}, weight={1}".format(out, self.weight) if self.grain_type: out = "{0}, grain_type='{1}'".format(out, self.grain_type) + out = "{0}, units='{1}'".format(out, self.units) out = "{0})".format(out) return out def __eq__(self, other): if not isinstance(other, self.__class__): return False - if (self.weight == other.weight) and \ + if (round(self.weight, 2) == round(other.weight, 2)) and \ (self.grain_type == other.grain_type) and \ (self.units == other.units) and \ (self.grain == other.grain): diff --git a/brew/hops.py b/brew/hops.py index 7177a75..3b3f404 100644 --- a/brew/hops.py +++ b/brew/hops.py @@ -157,8 +157,7 @@ def __repr__(self): out = "{0}, utilization_cls={1}".format(out, type(self.utilization_cls).__name__) # nopep8 if self.utilization_cls_kwargs: out = "{0}, utilization_cls_kwargs={1}".format(out, self.utilization_cls_kwargs) # nopep8 - if self.units: - out = "{0}, units='{1}'".format(out, self.units) + out = "{0}, units='{1}'".format(out, self.units) out = "{0})".format(out) return out @@ -253,7 +252,7 @@ def get_hops_weight(self, sg, target_ibu, final_volume, :param float percent_contribution: The percent contribution of the hops to the total bitterness :return: The weight of hops :rtype: float - """ + """ # nopep8 validate_percentage(percent_contribution) hops_constant = HOPS_CONSTANT_IMPERIAL diff --git a/brew/recipes.py b/brew/recipes.py index aa24c74..40324d2 100644 --- a/brew/recipes.py +++ b/brew/recipes.py @@ -824,6 +824,6 @@ def get_grain_additions(self, percent_list): for index, grain in enumerate(self.grain_list): efficiency = self.percent_brew_house_yield weight = (percent_list[index] * total_points) / (getattr(grain, attr) * efficiency) # nopep8 - grain_add = GrainAddition(grain, weight=round(weight, 2)) + grain_add = GrainAddition(grain, weight=weight, units=self.units) grain_additions.append(grain_add) return grain_additions diff --git a/tests/test_grains.py b/tests/test_grains.py index c29a1f6..95f59c8 100644 --- a/tests/test_grains.py +++ b/tests/test_grains.py @@ -120,7 +120,7 @@ def test_str(self): def test_repr(self): out = repr(self.grain_add) - self.assertEquals(out, "GrainAddition(Grain('pale 2-row', color=2.0, hwe=308.78), weight=13.96, grain_type='cereal')") # nopep8 + self.assertEquals(out, "GrainAddition(Grain('pale 2-row', color=2.0, hwe=308.78), weight=13.96, grain_type='cereal', units='imperial')") # nopep8 def test_get_weight_cereal(self): grain_add = GrainAddition(pale, weight=13.96, diff --git a/tests/test_recipes.py b/tests/test_recipes.py index e509ace..c48c783 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -35,7 +35,7 @@ def test_str(self): def test_repr(self): out = repr(self.recipe) - self.assertEquals(out, "Recipe('pale ale', grain_additions=[GrainAddition(Grain('pale 2-row', color=2.0, hwe=308.78), weight=13.96, grain_type='cereal'), GrainAddition(Grain('crystal C20', color=20.0, hwe=292.09), weight=0.78, grain_type='cereal')], hop_additions=[HopAddition(Hop('centennial', percent_alpha_acids=0.14), weight=0.57, boil_time=60.0, hop_type='pellet', utilization_cls=HopsUtilizationGlennTinseth, units='imperial'), HopAddition(Hop('cascade', percent_alpha_acids=0.07), weight=0.76, boil_time=5.0, hop_type='pellet', utilization_cls=HopsUtilizationGlennTinseth, units='imperial')], yeast=Yeast('Wyeast 1056', percent_attenuation=0.75), percent_brew_house_yield=0.7, start_volume=7.0, final_volume=5.0, units=imperial)") # nopep8 + self.assertEquals(out, "Recipe('pale ale', grain_additions=[GrainAddition(Grain('pale 2-row', color=2.0, hwe=308.78), weight=13.96, grain_type='cereal', units='imperial'), GrainAddition(Grain('crystal C20', color=20.0, hwe=292.09), weight=0.78, grain_type='cereal', units='imperial')], hop_additions=[HopAddition(Hop('centennial', percent_alpha_acids=0.14), weight=0.57, boil_time=60.0, hop_type='pellet', utilization_cls=HopsUtilizationGlennTinseth, units='imperial'), HopAddition(Hop('cascade', percent_alpha_acids=0.07), weight=0.76, boil_time=5.0, hop_type='pellet', utilization_cls=HopsUtilizationGlennTinseth, units='imperial')], yeast=Yeast('Wyeast 1056', percent_attenuation=0.75), percent_brew_house_yield=0.7, start_volume=7.0, final_volume=5.0, units=imperial)") # nopep8 def test_eq(self): recipe1 = Recipe('pale ale') @@ -203,25 +203,3 @@ def test_set_units(self): def test_set_raises(self): with self.assertRaises(Exception): self.builder.set_units('bad') - - def test_change_units(self): - self.assertEquals(self.builder.units, IMPERIAL_UNITS) - builder = self.builder.change_units() - self.assertEquals(builder.units, SI_UNITS) - self.assertEquals(self.builder.units, IMPERIAL_UNITS) - - def test_get_grain_additions(self): - percent_list = [0.95, 0.05] - out = self.builder.get_grain_additions(percent_list) - expected = grain_additions - self.assertEquals(out, expected) - - def test_get_grain_additions_raises_sum_invalid(self): - percent_list = [0.90, 0.05] - with self.assertRaises(Exception): - self.builder.get_grain_additions(percent_list) - - def test_get_grain_additions_raises_length_mismatch(self): - percent_list = [0.90, 0.05, 0.05] - with self.assertRaises(Exception): - self.builder.get_grain_additions(percent_list) diff --git a/tests/test_recipes_imperial.py b/tests/test_recipes_imperial.py index fd20849..662cce9 100644 --- a/tests/test_recipes_imperial.py +++ b/tests/test_recipes_imperial.py @@ -8,7 +8,9 @@ from brew.constants import SUCROSE_PLATO from brew.grains import GrainAddition from brew.recipes import Recipe +from fixtures import builder from fixtures import grain_additions +from fixtures import grain_list from fixtures import hop_additions from fixtures import pale from fixtures import recipe @@ -310,3 +312,36 @@ def test_format(self): def test_validate(self): data = self.recipe.to_dict() Recipe.validate(data) + + +class TestRecipeBuilderImperialUnits(unittest.TestCase): + + def setUp(self): + # Define Grains + self.grain_list = grain_list + + # Define Recipes + self.builder = builder + self.assertEquals(self.builder.units, IMPERIAL_UNITS) + + def test_change_units(self): + self.assertEquals(self.builder.units, IMPERIAL_UNITS) + builder = self.builder.change_units() + self.assertEquals(builder.units, SI_UNITS) + self.assertEquals(self.builder.units, IMPERIAL_UNITS) + + def test_get_grain_additions(self): + percent_list = [0.95, 0.05] + out = self.builder.get_grain_additions(percent_list) + expected = grain_additions + self.assertEquals(out, expected) + + def test_get_grain_additions_raises_sum_invalid(self): + percent_list = [0.90, 0.05] + with self.assertRaises(Exception): + self.builder.get_grain_additions(percent_list) + + def test_get_grain_additions_raises_length_mismatch(self): + percent_list = [0.90, 0.05, 0.05] + with self.assertRaises(Exception): + self.builder.get_grain_additions(percent_list) diff --git a/tests/test_recipes_si.py b/tests/test_recipes_si.py index 82484c0..642b5f9 100644 --- a/tests/test_recipes_si.py +++ b/tests/test_recipes_si.py @@ -9,7 +9,9 @@ from brew.constants import SUCROSE_PLATO from brew.grains import GrainAddition from brew.recipes import Recipe +from fixtures import builder from fixtures import grain_additions +from fixtures import grain_list from fixtures import hop_additions from fixtures import pale from fixtures import recipe @@ -321,3 +323,36 @@ def test_format(self): def test_validate(self): data = self.recipe.to_dict() Recipe.validate(data) + + +class TestRecipeBuilderSIUnits(unittest.TestCase): + + def setUp(self): + # Define Grains + self.grain_list = grain_list + + # Define Recipes + self.builder = builder.change_units() + self.assertEquals(self.builder.units, SI_UNITS) + + def test_change_units(self): + self.assertEquals(self.builder.units, SI_UNITS) + builder = self.builder.change_units() + self.assertEquals(builder.units, IMPERIAL_UNITS) + self.assertEquals(self.builder.units, SI_UNITS) + + def test_get_grain_additions(self): + percent_list = [0.95, 0.05] + out = self.builder.get_grain_additions(percent_list) + expected = [ga.change_units() for ga in grain_additions] + self.assertEquals(out[0], expected[0]) + + def test_get_grain_additions_raises_sum_invalid(self): + percent_list = [0.90, 0.05] + with self.assertRaises(Exception): + self.builder.get_grain_additions(percent_list) + + def test_get_grain_additions_raises_length_mismatch(self): + percent_list = [0.90, 0.05, 0.05] + with self.assertRaises(Exception): + self.builder.get_grain_additions(percent_list)