diff --git a/src/synthale/recipes.py b/src/synthale/recipes.py index 28b4a7e..86d5ee7 100644 --- a/src/synthale/recipes.py +++ b/src/synthale/recipes.py @@ -63,7 +63,7 @@ class MarkdownRecipe: @property def markdown(self): """Return generated markdown for the recipe.""" - return '\n'.join(( + md = '\n'.join(( self.name, '', self.style, @@ -76,12 +76,16 @@ class MarkdownRecipe: '', self.yeast, '', - self.miscs, - '', - self.mash, - '', )) + if len(self.miscs) > 0: + md += '\n'.join(('', self.miscs, '',)) + + if len(self.mash) > 0: + md += '\n'.join(('', self.mash, '',)) + + return md + @property def name(self): """Return markdown for the recipe's name.""" @@ -211,6 +215,9 @@ class MarkdownRecipe: @property def miscs(self): """Return the markdown to represent the recipe's other ingredients.""" + if len(self.recipe.miscs) == 0: + return '' + headers = ('Name', 'Use', 'Amount') rows = [] for misc in self.recipe.miscs: @@ -235,6 +242,9 @@ class MarkdownRecipe: @property def mash(self): """Return the markdown to represent the recipe's mash steps.""" + if self.recipe.mash is None: + return '' + headers = ('Name', 'Type', 'Temperature', 'Time', 'Amount') rows = [] for step in self.recipe.mash.steps: diff --git a/tests/recipes/weizen.xml b/tests/recipes/weizen.xml index fba75dd..03885bd 100644 --- a/tests/recipes/weizen.xml +++ b/tests/recipes/weizen.xml @@ -87,21 +87,6 @@ - - Single Step Infusion, 148 F - 1 - 22.0 - - - Infusion - 1 - Infusion - 64.4444 - 60.0 - 17.0344 - - - All Grain Mike Shoup 20.81976479 diff --git a/tests/test_recipes.py b/tests/test_recipes.py index 42221d3..1f0e608 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -140,7 +140,7 @@ def test_recipe_yeast(md_weizen): ) -def test_recipe_miscs(md_coffee_stout): +def test_recipe_miscs(md_coffee_stout, md_weizen): """Test valid miscellaneous ingredient table is generated.""" assert md_coffee_stout.miscs == ( 'Other Ingredients\n' @@ -168,17 +168,39 @@ def test_recipe_miscs(md_coffee_stout): '| Coffee (Brewed) | Keg | 0.71 kg |' ) + assert md_weizen.miscs == '' -def test_recipe_mash(md_coffee_stout): + +def test_recipe_mash(md_coffee_stout, md_weizen): """Test valid recipe mash table.""" assert md_coffee_stout.mash == ( 'Mash\n' '----\n' - '| Name | Type | Temperature | Time | Amount |\n' - '| -------- | -------- | ----------- | ------ | -------- |\n' - '| Infusion | Infusion | 152.0 °F | 60 min | 37.55 lb |' + '| Name | Type | Temperature | Time | Amount |\n' + '| -------- | -------- | ----------- | ------ | ------- |\n' + '| Infusion | Infusion | 152.0 °F | 60 min | 4.5 gal |' ) + md_coffee_stout.temp_unit = 'celsius' + assert md_coffee_stout.mash == ( + 'Mash\n' + '----\n' + '| Name | Type | Temperature | Time | Amount |\n' + '| -------- | -------- | ----------- | ------ | ------- |\n' + '| Infusion | Infusion | 66.7 °C | 60 min | 4.5 gal |' + ) + + md_coffee_stout.vol_unit = 'liters' + assert md_coffee_stout.mash == ( + 'Mash\n' + '----\n' + '| Name | Type | Temperature | Time | Amount |\n' + '| -------- | -------- | ----------- | ------ | ------ |\n' + '| Infusion | Infusion | 66.7 °C | 60 min | 17.0 L |' + ) + + assert md_weizen.mash == '' + def test_write_recipes(md_recipes, tmpdir): """Test write_recipes function."""