def test_utilization_factor(): hop = Hop() hop.form = "pellet" assert(hop.utilization_factor() == 1.15) hop.form = "whole" assert(hop.utilization_factor() == 1)
def test_bitterness(): hop = Hop() hop.time = 60 # Minutes hop.amount = 0.010 # KG hop.alpha = 10 original_gravity = 1.050 # OG batch_size = 5 # liter bitterness = hop.bitterness("tinseth", original_gravity, batch_size) assert (bitterness == 46.132815450219816) bitterness = hop.bitterness("rager", original_gravity, batch_size) assert (bitterness == 61.63901270302538) with pytest.raises(Exception): hop.bitterness("", original_gravity, batch_size)
def test_utilization_factor(): hop = Hop() hop.form = "pellet" assert (hop.utilization_factor() == 1.15) hop.form = "whole" assert (hop.utilization_factor() == 1)
def test_bitterness(): hop = Hop() hop.time = 60 # Minutes hop.amount = 0.010 # KG hop.alpha = 10 original_gravity = 1.050 # OG batch_size = 5 # liter bitterness = hop.bitterness("tinseth", original_gravity, batch_size) assert(bitterness == 46.132815450219816) bitterness = hop.bitterness("rager", original_gravity, batch_size) assert(bitterness == 61.63901270302538) with pytest.raises(Exception): hop.bitterness("", original_gravity, batch_size)
def test_node_to_object(self): "test XML node parsing to Python object" node = Element("hop") SubElement(node, "name").text = "Simcoe" SubElement(node, "alpha").text = 13 SubElement(node, "amount").text = 0.5 SubElement(node, "use").text = "boil" SubElement(node, "time").text = 30 test_hop = Hop() recipe_parser = Parser() recipe_parser.nodes_to_object(node, test_hop) assert (test_hop.name == "Simcoe") assert (test_hop.alpha == 13) assert (test_hop.amount == 0.5) assert (test_hop.use == "boil") assert (test_hop.time == 30)
def test_node_to_object(self): "test XML node parsing to Python object" node = ElementTree.Element("hop", { "name" : "Simcoe", "alpha" : 13, "amount" : 0.5, "use" : "boil", "time" : 30 }) test_hop = Hop() recipe_parser = Parser() recipe_parser.node_to_object(node, test_hop) assert(test_hop.name, "Simcoe") assert(test_hop.alpha, 13) assert(test_hop.amount, 0.5) assert(test_hop.use, "boil") assert(test_hop.time, 30)
def parse_recipe(self, recipe_node: Element) -> Recipe: recipe = Recipe() for recipe_property in list(recipe_node): tag_name = to_lower(recipe_property.tag) if tag_name == "fermentables": for fermentable_node in list(recipe_property): fermentable = Fermentable() self.nodes_to_object(fermentable_node, fermentable) recipe.fermentables.append(fermentable) elif tag_name == "yeasts": for yeast_node in list(recipe_property): yeast = Yeast() self.nodes_to_object(yeast_node, yeast) recipe.yeasts.append(yeast) elif tag_name == "hops": for hop_node in list(recipe_property): hop = Hop() self.nodes_to_object(hop_node, hop) recipe.hops.append(hop) elif tag_name == "miscs": for misc_node in list(recipe_property): misc = Misc() self.nodes_to_object(misc_node, misc) recipe.miscs.append(misc) elif tag_name == "style": style = Style() recipe.style = style self.nodes_to_object(recipe_property, style) elif tag_name == "waters": for water_node in list(recipe_property): water = Water() self.nodes_to_object(water_node, water) recipe.waters.append(water) elif tag_name == "equipment": equipment = Equipment() recipe.equipment = equipment self.nodes_to_object(recipe_property, equipment) elif tag_name == "mash": mash = Mash() recipe.mash = mash for mash_node in list(recipe_property): if to_lower(mash_node.tag) == "mash_steps": for mash_step_node in list(mash_node): mash_step = MashStep() self.nodes_to_object(mash_step_node, mash_step) mash.steps.append(mash_step) else: self.node_to_object(mash_node, mash) else: self.node_to_object(recipe_property, recipe) return recipe