def test_subrecipe_header(self) -> None: assert (render_cell( Cell(SubRecipe(Ingredient(SVS("spam")), (SVS("foo"), )))) == '<td class="rg-sub-recipe-header">foo</td>')
def test_reference(self) -> None: assert (render_cell( Cell( Reference(SubRecipe(Ingredient(SVS("spam")), (SVS("foo"), )), 0)) ) == '<td class="rg-reference"><a href="#sub-recipe-foo">foo</a></td>')
def test_step(self) -> None: assert (render_cell(Cell(Step( SVS("fry"), (Ingredient(SVS("spam")), )))) == '<td class="rg-step">fry</td>')
def test_render_sub_recipe_header() -> None: assert (render_sub_recipe_header( SubRecipe(Ingredient(SVS("spam")), (SVS("foo"), ))) == "foo")
def test_ingredient(self) -> None: assert (render_cell(Cell(Ingredient( SVS("spam")))) == '<td class="rg-ingredient">spam</td>')
def test_reference_to_sub_recipe_later_in_recipe(self) -> None: later_sr = SubRecipe(Ingredient(SVS("eggs")), (SVS("foo"), )) ref = Reference(later_sr) with pytest.raises(ReferenceToInvalidSubRecipeError): Recipe((ref, later_sr))
def test_render_step() -> None: assert render_step(Step(SVS("fry"), (Ingredient(SVS("spam")), ))) == "fry"
def test_step_with_multiple_inputs_has_no_inferred_name(self) -> None: assert compile(["fry(spam, eggs)"]) == [ Recipe( (Step(SVS("fry"), (Ingredient(SVS("spam")), Ingredient(SVS("eggs")))), )), ]
def test_normalise_output_name() -> None: # Just a sanity check assert normalise_output_name(SVS(" Foo ")) == normalise_output_name( SVS("fOo")) assert normalise_output_name(SVS(" Foo ")) != normalise_output_name( SVS("bAr"))
def test_ingredient_with_implied_output_name(self) -> None: assert compile(["spam"]) == [ Recipe((SubRecipe(Ingredient(SVS("spam")), (SVS("spam"), ), False), )) ]
def test_multiple_outputs(self) -> None: assert compile(["foo, bar = spam"]) == [ Recipe((SubRecipe(Ingredient(SVS("spam")), (SVS("foo"), SVS("bar")), True), )) ]
) def test_normalise_output_name() -> None: # Just a sanity check assert normalise_output_name(SVS(" Foo ")) == normalise_output_name( SVS("fOo")) assert normalise_output_name(SVS(" Foo ")) != normalise_output_name( SVS("bAr")) @pytest.mark.parametrize( "recipe_tree, exp", [ # Workable cases (Ingredient(SVS("spam")), SVS("spam")), (Step(SVS("fry"), (Ingredient(SVS("spam")), )), SVS("spam")), # Can't name step with several inputs (Step(SVS("fry"), (Ingredient(SVS("spam")), Ingredient(SVS("eggs")))), None), # Can't name references (Reference(SubRecipe(Ingredient(SVS("spam")), (SVS("spam"), )), 0), None), # Can't name sub recipes (they're already named!) (SubRecipe(Ingredient(SVS("spam")), (SVS("spam"), )), None), ], ) def test_infer_output_name(recipe_tree: RecipeTreeNode, exp: Optional[SVS]) -> None: assert infer_output_name(recipe_tree) == exp
def test_reference() -> None: sub_recipe = SubRecipe(Ingredient(SVS("spam")), (SVS("out"), )) reference = Reference(sub_recipe, 0) assert recipe_tree_to_table(reference) == set_border_around_table( Table.from_dict({(0, 0): Cell(reference)}), BorderType.sub_recipe)
def test_ingredient() -> None: ingredient = Ingredient(SVS("spam")) assert recipe_tree_to_table(ingredient) == set_border_around_table( Table.from_dict({(0, 0): Cell(ingredient)}), BorderType.sub_recipe)
def test_colspan(self) -> None: assert (render_cell(Cell( Ingredient(SVS("spam")), columns=3, ), ) == '<td class="rg-ingredient" colspan="3">spam</td>')
# Quantity (percentage) ( Proportion(0.5, preposition="% of", percentage=True), '<span class="rg-proportion">50% of</span>', ), ], ) def test_render_proportion(proportion: Proportion, exp: str) -> None: assert render_proportion(proportion) == exp @pytest.mark.parametrize( "string, exp", [ # Pure string (SVS("Hello"), "Hello"), # HTML special chars in string (SVS("<Hello>"), "<Hello>"), # Scaled values formatted and spanned ( SVS([1.2345, " < ", Fraction(5, 3)]), ('<span class="rg-scaled-value">1.23</span>' " < " '<span class="rg-scaled-value">1 <sup>2</sup>⁄<sub>3</sub></span>' ), ), ], ) def test_render_scaled_value_string(string: SVS, exp: str) -> None: assert render_scaled_value_string(string) == exp
def test_rowspan(self) -> None: assert (render_cell( Cell( Step(SVS("fry"), (Ingredient(SVS("spam")), )), rows=3, ), ) == '<td class="rg-step" rowspan="3">fry</td>')
def test_at_least_one_output(self) -> None: with pytest.raises(ZeroOutputSubRecipeError): SubRecipe(Ingredient(SVS("spam")), ())