def test_to_lower(self): recipe_parser = Parser() assert(recipe_parser.to_lower("MASH") == "mash") assert(recipe_parser.to_lower("") == "") assert(recipe_parser.to_lower(10) == "") assert(recipe_parser.to_lower(None) == "")
def test_to_lower(self): recipe_parser = Parser() assert (recipe_parser.to_lower("MASH") == "mash") assert (recipe_parser.to_lower("") == "") assert (recipe_parser.to_lower(10) == "") assert (recipe_parser.to_lower(None) == "")
def test_parse_recipe_2(self): recipe_parser = Parser() recipes = recipe_parser.parse(RECIPE_PATH_2) "should have at least one recipe" assert (len(recipes) > 0) recipe = recipes[0] "should be of type Recipe" assert (type(recipe) is Recipe) "should have the correct amount of ingredients" assert (len(recipe.hops) == 1) assert (len(recipe.yeasts) == 1) assert (len(recipe.fermentables) == 5) "should have mashing steps" assert (len(recipe.mash.steps) == 2) assert (recipe.mash.steps[0].name == "Mash step") assert (recipe.mash.steps[0].step_time == 60) assert (recipe.mash.steps[0].step_temp == 68) "should have the correctly calculated properties" assert (round(recipe.og, 4) == 1.0556) assert (round(recipe.og_plato, 4) == 13.7108) assert (round(recipe.fg, 4) == 1.0139) assert (round(recipe.fg_plato, 4) == 3.5467) assert (floor(recipe.ibu) == 32) assert (round(recipe.abv, 2) == 5.47) "should have the correct recipe metadata" assert (recipe.name == "Oatmeal Stout no. 1") assert (recipe.brewer == "Niels Kjøller") # Python 2 Problem? assert (recipe.efficiency == 75.0) assert (recipe.batch_size == 25) assert (recipe.ibu == 32.21660448470247) assert (round(recipe.color, 2) == 40.16) "should have the correct style metadata" assert (recipe.style.name == "Oatmeal Stout") "should have misc ingredients" assert (len(recipe.miscs) == 1) assert (recipe.miscs[0].name == "Protafloc") assert (recipe.miscs[0].use == "Boil") assert (recipe.miscs[0].use_for == None) assert (recipe.miscs[0].amount == 0.0016) assert (recipe.miscs[0].amount_is_weight == True) assert (recipe.miscs[0].time == 15) assert (recipe.miscs[0].notes == "Half a tablet @ 15 minutes")
def test_parse_recipe_3(self): recipe_parser = Parser() recipes = recipe_parser.parse(RECIPE_PATH_3) "should have at least one recipe" assert(len(recipes) > 0) recipe = recipes[0] "should be of type Recipe" assert(type(recipe) is Recipe) "should have the correct amount of ingredients" assert(len(recipe.hops) == 2) assert(len(recipe.yeasts) == 1) assert(len(recipe.fermentables) == 4) "should have mashing steps" assert(len(recipe.mash.steps) == 2) assert(recipe.mash.steps[0].name == "Conversion") assert(recipe.mash.steps[0].step_time == 60) assert(recipe.mash.steps[0].step_temp == 66.66666667) "should have the correctly calculated properties" assert(round(recipe.og, 4) == 1.0594) assert(round(recipe.og_plato, 4) == 14.6092) assert(round(recipe.fg, 4) == 1.0184) assert(round(recipe.fg_plato, 4) == 4.684) assert(floor(recipe.ibu) == 25) assert(round(recipe.abv, 2) == 5.35) "should have the correct recipe metadata" assert(recipe.name == "Coffee Stout") assert(recipe.brewer == None) # https://github.com/jwjulien assert(recipe.efficiency == 70.0) assert(recipe.batch_size == 20.82) assert(round(recipe.ibu, 2) == 25.97) assert(round(recipe.color, 2) == 35.01) "should have the correct style metadata" assert(recipe.style.name == "Dry Stout") "should have misc ingredients" assert(len(recipe.miscs) == 1) assert(recipe.miscs[0].name == "Coffee, Dark Roast") assert(recipe.miscs[0].use == "Boil") assert(recipe.miscs[0].use_for == "Adding coffee notes.") assert(recipe.miscs[0].amount == 0.11339809) assert(recipe.miscs[0].amount_is_weight == True) assert(recipe.miscs[0].time == 0) assert(recipe.miscs[0].notes == "Use a coarse grind, add at flameout, steep 20 minutes.")
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 test_parse_recipe(self): recipe_parser = Parser() recipes = recipe_parser.parse(RECIPE_PATH) "should have at least one recipe" assert (len(recipes) > 0) recipe = recipes[0] "should be of type Recipe" assert (type(recipe) is Recipe) "should have the correct amount of ingredients" assert (len(recipe.hops) == 3) assert (len(recipe.yeasts) == 1) assert (len(recipe.fermentables) == 2) "should have mashing steps" # TODO "should have the correctly calculated properties" assert (round(recipe.og, 4) == 1.0338) assert (round(recipe.og_plato, 4) == 8.4815) assert (round(recipe.fg, 4) == 1.0047) assert (round(recipe.fg_plato, 4) == 1.2156) assert (floor(recipe.ibu) == 99) assert (round(recipe.abv, 2) == 3.84) "should have the correct recipe metadata" assert (recipe.name == "Simcoe IPA") assert (recipe.brewer == "Tom Herold") assert (recipe.efficiency == 76.0) assert (recipe.batch_size == 14.9902306488) assert (recipe.boil_time == 30.0) assert (round(recipe.color, 2) == 6.27) "should have the correct style metadata" assert (recipe.style.name == "American IPA")
def convert_runner(fname, origin, recipe_id): """Meant to be run on a single recipe file.""" try: parser = Parser() recipes = parser.parse(fname) except ParseError as e: print(f"Failed to parse {fname}:", file=sys.stderr) print(e, file=sys.stderr) return None try: recipe = recipes[0] except IndexError: print(f"No recipe in {fname}", file=sys.stderr) return None try: core_vals, ingredients = recipe_to_dicts(recipe, fname, recipe_id, origin) except Exception as e: print(f"Failed {fname}:", file=sys.stderr) print(e, file=sys.stderr) core_vals, ingredients = {}, [] return (core_vals, ingredients)
def test_parse(self): recipe_parser = Parser() recipes = recipe_parser.parse(RECIPE_PATH) "should have at least one recipe" assert(len(recipes) > 0) recipe = recipes[0] "should be of type Recipe" assert(type(recipe) is Recipe) "should have the correct amount of ingriedients" assert(len(recipe.hops) == 3) assert(len(recipe.yeasts) == 1) assert(len(recipe.fermentables) == 2) "should habe mashing steps" # TODO "should have the correctly calculated properties" assert(round(recipe.og, 4) == 1.0338) assert(round(recipe.og_plato, 4) == 8.4815) assert(round(recipe.fg, 4) == 1.0047) assert(round(recipe.fg_plato, 4) == 1.2156) assert(floor(recipe.ibu) == 99) assert(round(recipe.abv, 2) == 3.84) "should have the correct recipe metadata" assert(recipe.name == "Simcoe IPA") assert(recipe.brewer == "Tom Herold") assert(recipe.efficiency == 76.0) assert(recipe.batch_size == 14.9902306488) assert(recipe.boil_time == 30.0) "should have the correct style metadata" assert(recipe.style.name == "American IPA")
# -*- coding: utf-8 -*- import sys reload(sys) sys.setdefaultencoding("utf-8") from pybeerxml import Parser import json import os path_to_beerxml_file = "SimcoeIPA.xml" #path_to_beerxml_file = "rojo-chango.xml" parser = Parser() recipes = parser.parse(path_to_beerxml_file) test = recipes[0] print json.dumps(test, default=lambda o: o.__dict__) # for recipe in recipes: # # # # # some general recipe properties # print "Name: " + str(recipe.name) # print "Brewer: " + str(recipe.brewer) # # print "Style: " + str(recipe.style) # print "og_plato: " + str(recipe.og_plato) # print "fg_plato: " + str(recipe.fg_plato)
import csv from pybeerxml import Parser path_to_beerxml_file = "cloudsafe.bsmx" #/Users/sosinski/Documents/BeerSmith3/Cloud.bsmx" parser = Parser() recipes = parser.parse(path_to_beerxml_file) og_eff = {} #for recipe in recipes: # some general recipe properties #print(recipe.name) #recipe.stats_pretty() with open("session_data.csv", 'w', newline='') as csvfile: spamwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) header = True for recipe in recipes: print("Writing %s" % recipe.name) spamwriter.writerows(recipe.stats_csv2(header=header)) header = False #if recipe.name == "Rings of Light - BIAB - BnW - 3/13/20": # recipe.stats_pretty()