示例#1
0
 def test_subrecipe_header(self) -> None:
     assert (render_cell(
         Cell(SubRecipe(Ingredient(SVS("spam")), (SVS("foo"), )))) ==
             '<td class="rg-sub-recipe-header">foo</td>')
示例#2
0
 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>')
示例#3
0
 def test_step(self) -> None:
     assert (render_cell(Cell(Step(
         SVS("fry"),
         (Ingredient(SVS("spam")), )))) == '<td class="rg-step">fry</td>')
示例#4
0
def test_render_sub_recipe_header() -> None:
    assert (render_sub_recipe_header(
        SubRecipe(Ingredient(SVS("spam")), (SVS("foo"), ))) == "foo")
示例#5
0
 def test_ingredient(self) -> None:
     assert (render_cell(Cell(Ingredient(
         SVS("spam")))) == '<td class="rg-ingredient">spam</td>')
示例#6
0
    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))
示例#7
0
def test_render_step() -> None:
    assert render_step(Step(SVS("fry"), (Ingredient(SVS("spam")), ))) == "fry"
示例#8
0
 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")))), )),
     ]
示例#9
0
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"))
示例#10
0
 def test_ingredient_with_implied_output_name(self) -> None:
     assert compile(["spam"]) == [
         Recipe((SubRecipe(Ingredient(SVS("spam")), (SVS("spam"), ),
                           False), ))
     ]
示例#11
0
 def test_multiple_outputs(self) -> None:
     assert compile(["foo, bar = spam"]) == [
         Recipe((SubRecipe(Ingredient(SVS("spam")),
                           (SVS("foo"), SVS("bar")), True), ))
     ]
示例#12
0
)


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
示例#13
0
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)
示例#14
0
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)
示例#15
0
 def test_colspan(self) -> None:
     assert (render_cell(Cell(
         Ingredient(SVS("spam")),
         columns=3,
     ), ) == '<td class="rg-ingredient" colspan="3">spam</td>')
示例#16
0
        # 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>"), "&lt;Hello&gt;"),
        # Scaled values formatted and spanned
        (
            SVS([1.2345, " < ", Fraction(5, 3)]),
            ('<span class="rg-scaled-value">1.23</span>'
             " &lt; "
             '<span class="rg-scaled-value">1 <sup>2</sup>&frasl;<sub>3</sub></span>'
             ),
        ),
    ],
)
def test_render_scaled_value_string(string: SVS, exp: str) -> None:
    assert render_scaled_value_string(string) == exp
示例#17
0
 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>')
示例#18
0
 def test_at_least_one_output(self) -> None:
     with pytest.raises(ZeroOutputSubRecipeError):
         SubRecipe(Ingredient(SVS("spam")), ())