1
0
Fork 0
mirror of https://github.com/shouptech/humulus.git synced 2026-02-03 19:49:44 +00:00
humulus/tests/test_filters.py

123 lines
4.3 KiB
Python

# Copyright 2019 Mike Shoup
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from decimal import Decimal
from humulus.filters import (
recipe_abv,
recipe_fg,
recipe_ibu,
sort_hops,
recipe_ibu_ratio,
recipe_og,
recipe_srm,
ferm_pct,
)
from humulus.recipes import HopForm
def test_recipe_og(sample_recipes):
assert recipe_og(sample_recipes["lager"]) == "1.054"
assert recipe_og(sample_recipes["sweetstout"]) == "1.038"
# Remove fermentables, verify 0 is returned
sample_recipes["lager"].pop("fermentables")
assert recipe_og(sample_recipes["lager"]) == "0.000"
def test_recipe_fg(sample_recipes):
assert recipe_fg(sample_recipes["lager"]) == "1.014"
assert recipe_fg(sample_recipes["sweetstout"]) == "1.015"
# Remove fermentables, verify 0 is returned
sample_recipes["lager"].pop("fermentables")
assert recipe_fg(sample_recipes["lager"]) == "0.000"
# Remove yeast, verify 0 is returned
sample_recipes["sweetstout"].pop("yeast")
assert recipe_fg(sample_recipes["sweetstout"]) == "0.000"
def test_recipe_ibu(sample_recipes):
assert recipe_ibu(sample_recipes["lager"]) == "24"
assert recipe_ibu(sample_recipes["sweetstout"]) == "34"
# Remove hops, verify 0 is returned
sample_recipes["lager"].pop("hops")
assert recipe_ibu(sample_recipes["lager"]) == "0"
def test_recipe_ibu_ratio(sample_recipes):
assert recipe_ibu_ratio(sample_recipes["lager"]) == "0.44"
assert recipe_ibu_ratio(sample_recipes["sweetstout"]) == "0.89"
# Remove fermentables, verify 0 is returned
sample_recipes["lager"].pop("fermentables")
assert recipe_ibu_ratio(sample_recipes["lager"]) == "0"
# Remove hops, verify 0 is returned
sample_recipes["sweetstout"].pop("hops")
assert recipe_ibu_ratio(sample_recipes["sweetstout"]) == "0"
def test_recipe_abv(sample_recipes):
assert recipe_abv(sample_recipes["lager"]) == "5.3"
assert recipe_abv(sample_recipes["sweetstout"]) == "3.0"
# Remove fermentables, verify 0 is returned
sample_recipes["lager"].pop("fermentables")
assert recipe_abv(sample_recipes["lager"]) == "0"
# Remove yeast, verify 0 is returned
sample_recipes["sweetstout"].pop("yeast")
assert recipe_abv(sample_recipes["sweetstout"]) == "0"
def test_recipe_srm(sample_recipes):
assert recipe_srm(sample_recipes["lager"]) == "3"
assert recipe_srm(sample_recipes["sweetstout"]) == "21"
# Remove fermentables, verify 0 is returned
sample_recipes["lager"].pop("fermentables")
assert recipe_srm(sample_recipes["lager"]) == "0"
def test_sort_hops():
# Test with no form
hops = [
{"name": "4", "use": "Dry-Hop", "duration": "5"},
{"name": "3", "use": "Whirlpool", "duration": "10"},
{"name": "2", "use": "Boil", "duration": "5"},
{"name": "1", "use": "Boil", "duration": "15"},
{"name": "0", "use": "FWH", "duration": "60"},
]
assert sort_hops(hops) == [
{"name": "0", "use": "FWH", "duration": "60"},
{"name": "1", "use": "Boil", "duration": "15"},
{"name": "2", "use": "Boil", "duration": "5"},
{"name": "3", "use": "Whirlpool", "duration": "10"},
{"name": "4", "use": "Dry-Hop", "duration": "5"},
]
# Test with form
hop_forms = []
for hop in hops:
form = HopForm()
form.name.data = hop["name"]
form.use.data = hop["use"]
form.duration.data = Decimal(hop["duration"])
hop_forms.append(form)
for num, hop in enumerate(sort_hops(hop_forms, form=True)):
assert hop.name.data == str(num)
def test_ferm_pct():
ferms = [{"amount": "4"}, {"amount": "2"}, {"amount": "2"}]
assert ferm_pct(ferms) == [
{"amount": "4", "pct": 50.0},
{"amount": "2", "pct": 25.0},
{"amount": "2", "pct": 25.0},
]