Skip to content

Commit

Permalink
Merge pull request #6 from hotzenklotz/pr_feedback
Browse files Browse the repository at this point in the history
Fix Tests
  • Loading branch information
hotzenklotz authored Oct 26, 2018
2 parents f05f7c4 + ef4b6aa commit d4c7321
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 19 deletions.
1 change: 1 addition & 0 deletions pybeerxml/mash.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Mash(object):
def __init__(self):
self.name = None
self.grain_temp = None
self.sparge_temp = None
self.ph = None
Expand Down
1 change: 1 addition & 0 deletions pybeerxml/mash_step.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class MashStep(object):
def __init__(self):
self.name = None
self.type = None
self.infuse_amount = None
self.step_temp = None
Expand Down
8 changes: 6 additions & 2 deletions pybeerxml/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ def __init__(self):

@property
def amount_is_weight(self):
return bool(self._amount_is_weight)
if isinstance(self._amount_is_weight, str):
return self._amount_is_weight.lower() == "true"
elif isinstance(self._amount_is_weight, int) or isinstance(self._amount_is_weight, float):
return bool(self._amount_is_weight)
else:
return False

@amount_is_weight.setter
def amount_is_weight(self, value):
print(value)
self._amount_is_weight = value
91 changes: 74 additions & 17 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pytest
import os
from pybeerxml import Parser, Recipe
from pybeerxml.hop import Hop
from xml.etree import ElementTree
from xml.etree.ElementTree import Element, SubElement
from math import floor

RECIPE_PATH = os.path.join(os.path.dirname(__file__), "Simcoe IPA.xml")
RECIPE_PATH_2 = os.path.join(os.path.dirname(__file__), "Oatmeal Stout.xml")

class TestParser:

def test_parse(self):
def test_parse_recipe(self):

recipe_parser = Parser()
recipes = recipe_parser.parse(RECIPE_PATH)
Expand All @@ -22,12 +26,12 @@ def test_parse(self):
"should be of type Recipe"
assert(type(recipe) is Recipe)

"should have the correct amount of ingriedients"
"should have the correct amount of ingredients"
assert(len(recipe.hops) == 3)
assert(len(recipe.yeasts) == 1)
assert(len(recipe.fermentables) == 2)

"should habe mashing steps"
"should have mashing steps"
# TODO

"should have the correctly calculated properties"
Expand All @@ -49,27 +53,80 @@ def test_parse(self):
assert(recipe.style.name == "American IPA")


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)

"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_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
})
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.node_to_object(node, test_hop)
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)

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_to_lower(self):

Expand Down

0 comments on commit d4c7321

Please sign in to comment.