From 398b488038452eba14f5f260ca413f5cad0b1941 Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Fri, 28 Dec 2018 17:13:13 -0700 Subject: [PATCH] Add table for yeast --- src/synthale/recipes.py | 21 +++++++++++++++++++++ tests/test_recipes.py | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/synthale/recipes.py b/src/synthale/recipes.py index 124055b..91b0af3 100644 --- a/src/synthale/recipes.py +++ b/src/synthale/recipes.py @@ -67,6 +67,8 @@ class MarkdownRecipe: '', self.hops, '', + self.yeast, + '', )) @property @@ -176,6 +178,25 @@ class MarkdownRecipe: ) ) + @property + def yeast(self): + """Return markdown to represent the recipe's yeast.""" + headers = ('Name', 'Lab', 'Type', 'Attenuation') + rows = [] + for yeast in self.recipe.yeasts: + rows.append(( + yeast.name, + yeast.laboratory, + yeast.type, + '{:.1f} %'.format(yeast.attenuation), + )) + return ( + '{}\n{}'.format( + markdown.setext_heading('Yeast', level=2), + markdown.table(headers, rows) + ) + ) + def load_file(path): """Parse BeerXML file located at `path`. diff --git a/tests/test_recipes.py b/tests/test_recipes.py index 2973ba2..f0af6de 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -129,6 +129,17 @@ def test_recipe_hops(md_weizen): assert '| 28.3 g |' in md_weizen.hops +def test_recipe_yeast(md_weizen): + """Test valid yeast table is generated.""" + assert md_weizen.yeast == ( + 'Yeast\n' + '-----\n' + '| Name | Lab | Type | Attenuation |\n' + '| ------------- | --------- | ---- | ----------- |\n' + '| Safbrew WB-06 | Fermentis | Ale | 70.0 % |' + ) + + def test_write_recipes(md_recipes, tmpdir): """Test write_recipes function.""" write_recipes(md_recipes, str(tmpdir))