mirror of
https://github.com/shouptech/synthale.git
synced 2026-02-03 07:29:42 +00:00
Display miscellaneous ingredients.
This commit is contained in:
parent
398b488038
commit
3cd7d59e0d
4 changed files with 65 additions and 2 deletions
|
|
@ -69,6 +69,8 @@ class MarkdownRecipe:
|
|||
'',
|
||||
self.yeast,
|
||||
'',
|
||||
self.miscs,
|
||||
'',
|
||||
))
|
||||
|
||||
@property
|
||||
|
|
@ -197,6 +199,30 @@ class MarkdownRecipe:
|
|||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def miscs(self):
|
||||
"""Return the markdown to represent the recipe's other ingredients."""
|
||||
headers = ('Name', 'Use', 'Amount')
|
||||
rows = []
|
||||
for misc in self.recipe.miscs:
|
||||
if misc.display_amount is not None:
|
||||
amt = str(misc.display_amount)
|
||||
elif misc.amount_is_weight:
|
||||
amt = '{:.2f} kg'.format(misc.amount)
|
||||
else:
|
||||
amt = '{:.2f} L'.format(misc.amount)
|
||||
rows.append((
|
||||
misc.name,
|
||||
misc.use,
|
||||
amt
|
||||
))
|
||||
return (
|
||||
'{}\n{}'.format(
|
||||
markdown.setext_heading('Other Ingredients', level=2),
|
||||
markdown.table(headers, rows)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def load_file(path):
|
||||
"""Parse BeerXML file located at `path`.
|
||||
|
|
|
|||
|
|
@ -28,3 +28,11 @@ def md_weizen():
|
|||
return MarkdownRecipe(
|
||||
pybeerxml.Parser().parse('tests/recipes/weizen.xml')[0]
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def md_coffee_stout():
|
||||
"""Return the sample coffee stout recipe as a MarkdownRecipe object."""
|
||||
return MarkdownRecipe(
|
||||
pybeerxml.Parser().parse('tests/recipes/coffee-stout.xml')[0]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -157,10 +157,10 @@
|
|||
<NAME>Coffee (Brewed)</NAME>
|
||||
<USE>Keg</USE>
|
||||
<TIME>1.0</TIME>
|
||||
<AMOUNT>24.0</AMOUNT>
|
||||
<AMOUNT>0.709765</AMOUNT>
|
||||
<AMOUNT_IS_WEIGHT>false</AMOUNT_IS_WEIGHT>
|
||||
<NOTES></NOTES>
|
||||
<DISPLAY_AMOUNT>24.0 </DISPLAY_AMOUNT>
|
||||
<DISPLAY_AMOUNT>24.0 oz.</DISPLAY_AMOUNT>
|
||||
<DISPLAY_TIME>1.0 </DISPLAY_TIME>
|
||||
</MISC>
|
||||
</MISCS>
|
||||
|
|
|
|||
|
|
@ -140,6 +140,35 @@ def test_recipe_yeast(md_weizen):
|
|||
)
|
||||
|
||||
|
||||
def test_recipe_miscs(md_coffee_stout):
|
||||
"""Test valid miscellaneous ingredient table is generated."""
|
||||
assert md_coffee_stout.miscs == (
|
||||
'Other Ingredients\n'
|
||||
'-----------------\n'
|
||||
'| Name | Use | Amount |\n'
|
||||
'| --------------- | --- | -------- |\n'
|
||||
'| Coffee (Brewed) | Keg | 24.0 oz. |'
|
||||
)
|
||||
|
||||
md_coffee_stout.recipe.miscs[0].display_amount = None
|
||||
assert md_coffee_stout.miscs == (
|
||||
'Other Ingredients\n'
|
||||
'-----------------\n'
|
||||
'| Name | Use | Amount |\n'
|
||||
'| --------------- | --- | ------ |\n'
|
||||
'| Coffee (Brewed) | Keg | 0.71 L |'
|
||||
)
|
||||
|
||||
md_coffee_stout.recipe.miscs[0].amount_is_weight = True
|
||||
assert md_coffee_stout.miscs == (
|
||||
'Other Ingredients\n'
|
||||
'-----------------\n'
|
||||
'| Name | Use | Amount |\n'
|
||||
'| --------------- | --- | ------- |\n'
|
||||
'| Coffee (Brewed) | Keg | 0.71 kg |'
|
||||
)
|
||||
|
||||
|
||||
def test_write_recipes(md_recipes, tmpdir):
|
||||
"""Test write_recipes function."""
|
||||
write_recipes(md_recipes, str(tmpdir))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue