summaryrefslogtreecommitdiff
path: root/echo.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-06-02 13:25:15 +0300
committerLars Wirzenius <liw@liw.fi>2019-06-02 13:25:15 +0300
commitcd91e959daa2c21787c5fe878f1a4072d89b18d1 (patch)
tree79125b3d45316677602d5e135090549269459727 /echo.py
parent05a197f96867a1b41dc8446d3bbcd9c0f5cdfc08 (diff)
downloadfable-poc-cd91e959daa2c21787c5fe878f1a4072d89b18d1.tar.gz
Add: fable.py scaffolding for running scenarios
Diffstat (limited to 'echo.py')
-rw-r--r--echo.py40
1 files changed, 16 insertions, 24 deletions
diff --git a/echo.py b/echo.py
index abc0e52..7a5f186 100644
--- a/echo.py
+++ b/echo.py
@@ -1,43 +1,35 @@
import subprocess
-context = {}
-
-def _save(name, value):
- context[name] = value
-
-def _get(name):
- return context[name]
-
def assertEqual(a, b):
if a != b:
raise Exception(
'expected {!r} == {!r}, but was disappointed'.format(a, b))
-def _run_echo(args):
+def _run_echo(ctx, args):
cmd = '/bin/echo'
p = subprocess.Popen(
[cmd] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
text=True)
out, err = p.communicate()
- context["stdout"] = out
- context["stderr"] = err
- context["exit_code"] = p.returncode
+ ctx["stdout"] = out
+ ctx["stderr"] = err
+ ctx["exit_code"] = p.returncode
-def run_echo_without_args():
- _run_echo([])
+def run_echo_without_args(ctx):
+ _run_echo(ctx, [])
-def run_echo_with_args(args=None):
- _run_echo(args.split())
+def run_echo_with_args(ctx, args=None):
+ _run_echo(ctx, args.split())
-def exit_code_is_zero(exit_code=None):
+def exit_code_is_zero(ctx, exit_code=None):
exit_code = int(exit_code)
- assertEqual(_get("exit_code"), exit_code)
+ assertEqual(ctx['exit_code'], exit_code)
-def stdout_is_a_newline():
- assertEqual(_get('stdout'), '\n')
+def stdout_is_a_newline(ctx):
+ assertEqual(ctx['stdout'], '\n')
-def stdout_is_text(text=None):
- assertEqual(_get('stdout'), text + '\n')
+def stdout_is_text(ctx, text=None):
+ assertEqual(ctx['stdout'], text + '\n')
-def stderr_is_empty():
- assertEqual(_get('stderr'), '')
+def stderr_is_empty(ctx):
+ assertEqual(ctx['stderr'], '')