コード例 #1
0
ファイル: test-loop.py プロジェクト: nikhilm/preserve
from preserve import run, interpret, parse, Environment

recipe_simple_loop = """
Fruity Loops 1.

Ingredients.
10 g flour
1 teaspoon honey

Method.
Sift the flour.
  Put honey into mixing bowl.
Shake the flour until sifted.
"""

simple_loop = run(recipe_simple_loop)

assert simple_loop.ingredients['flour'].value == 0
assert len(simple_loop.mixing_bowls[1]) == 10

recipe_nesting = """
Fruity Loops Nesting.

Ingredients.
10 g flour
5 g cheese
1 teaspoon honey

Method.
Sift the flour.
  Put honey into mixing bowl.
コード例 #2
0
ファイル: test-simple.py プロジェクト: nikhilm/preserve
Divide fig into mixing bowl.

Serves 1.

"""

stdin = sys.stdin
stdout = sys.stdout

sys.stdin = StringIO()
sys.stdout = StringIO()

sys.stdin.write('1\n')
sys.stdin.seek(0)

result = run(recipe)
sys.stdin.close()

sys.stdout.seek(0)
out = sys.stdout.read()

sys.stdin = stdin
sys.stdout = stdout

assert result
assert len(result.ingredients) == 3
assert result.ingredients['apricot jam'].value == 3
assert result.ingredients['beans'].value == 2
assert result.mixing_bowls[1][-1].value == 3
assert len(result.mixing_bowls[2]) == 0