From bff6f54a403411e7730b405fa7ff0de81caf9f44 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 9 Oct 2020 10:21:24 +0300 Subject: refactor: move Subplot bindings, functions files to subplot/ This makes the source tree a little cleaner, I find. --- jt.md | 8 +++--- jt.py | 28 ------------------- jt.yaml | 16 ----------- runcmd.py | 77 ----------------------------------------------------- runcmd.yaml | 13 --------- subplot/jt.py | 28 +++++++++++++++++++ subplot/jt.yaml | 16 +++++++++++ subplot/runcmd.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ subplot/runcmd.yaml | 13 +++++++++ 9 files changed, 138 insertions(+), 138 deletions(-) delete mode 100644 jt.py delete mode 100644 jt.yaml delete mode 100644 runcmd.py delete mode 100644 runcmd.yaml create mode 100644 subplot/jt.py create mode 100644 subplot/jt.yaml create mode 100644 subplot/runcmd.py create mode 100644 subplot/runcmd.yaml diff --git a/jt.md b/jt.md index c8beace..fd867db 100644 --- a/jt.md +++ b/jt.md @@ -62,9 +62,9 @@ author: - Lars Wirzenius - Daniel Silverstone bindings: -- jt.yaml -- runcmd.yaml +- subplot/jt.yaml +- subplot/runcmd.yaml functions: -- jt.py -- runcmd.py +- subplot/jt.py +- subplot/runcmd.py ... diff --git a/jt.py b/jt.py deleted file mode 100644 index 2c5a4fc..0000000 --- a/jt.py +++ /dev/null @@ -1,28 +0,0 @@ -import logging -import os - - -def run_jt_init(ctx, dirname=None, journalname=None, title=None): - runcmd(ctx, [_binary("jt"), "init", dirname, journalname, title]) - - -def run_jt_list_journals(ctx): - runcmd(ctx, [_binary("jt"), "list-journals"]) - - -def run_jt_is_journal(ctx, dirname=None): - runcmd(ctx, [_binary("jt"), "is-journal", dirname]) - - -def _binary(name): - return os.path.join(srcdir, "target", "debug", "jt2") - - -def is_directory(ctx, dirname=None): - logging.debug("checking if %r is a directory", dirname) - assert_eq(os.path.isdir(dirname), True) - - -def output_contains(ctx, pattern=None): - logging.debug("checking if %r contains", ctx["stdout"], pattern) - assert_eq(pattern in ctx["stdout"], True) diff --git a/jt.yaml b/jt.yaml deleted file mode 100644 index 863dbeb..0000000 --- a/jt.yaml +++ /dev/null @@ -1,16 +0,0 @@ -- when: I run jt init (?P\S+) (?P\S+) "(?P.*)" - regex: true - function: run_jt_init - -- when: I run jt list-journals - function: run_jt_list_journals - -- when: I run jt is-journal {dirname} - function: run_jt_is_journal - -- then: directory {dirname} exists - function: is_directory - -- then: output contains "(?P<pattern>.*)" - regex: true - function: output_contains diff --git a/runcmd.py b/runcmd.py deleted file mode 100644 index 7193c15..0000000 --- a/runcmd.py +++ /dev/null @@ -1,77 +0,0 @@ -# Some step implementations for running commands and capturing the result. - -import subprocess - - -# Run a command, capture its stdout, stderr, and exit code in context. -def runcmd(ctx, argv, **kwargs): - p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs) - stdout, stderr = p.communicate("") - ctx["argv"] = argv - ctx["stdout"] = stdout.decode("utf-8") - ctx["stderr"] = stderr.decode("utf-8") - ctx["exit"] = p.returncode - - -# Check that latest exit code captured by runcmd was a specific one. -def exit_code_is(ctx, wanted): - if ctx.get("exit") != wanted: - print("context:", ctx.as_dict()) - assert_eq(ctx.get("exit"), wanted) - - -# Check that latest exit code captured by runcmd was not a specific one. -def exit_code_is_not(ctx, unwanted): - if ctx.get("exit") == unwanted: - print("context:", ctx.as_dict()) - assert_ne(ctx.get("exit"), unwanted) - - -# Check that latest exit code captured by runcmd was zero. -def exit_code_zero(ctx): - exit_code_is(ctx, 0) - - -# Check that latest exit code captured by runcmd was not zero. -def exit_code_nonzero(ctx): - exit_code_is_not(ctx, 0) - - -# Check that stdout of latest runcmd contains a specific string. -def stdout_contains(ctx, pattern=None): - stdout = ctx.get("stdout", "") - if pattern not in stdout: - print("pattern:", repr(pattern)) - print("stdout:", repr(stdout)) - print("ctx:", ctx.as_dict()) - assert_eq(pattern in stdout, True) - - -# Check that stdout of latest runcmd does not contain a specific string. -def stdout_does_not_contain(ctx, pattern=None): - stdout = ctx.get("stdout", "") - if pattern in stdout: - print("pattern:", repr(pattern)) - print("stdout:", repr(stdout)) - print("ctx:", ctx.as_dict()) - assert_eq(pattern not in stdout, True) - - -# Check that stderr of latest runcmd does contains a specific string. -def stderr_contains(ctx, pattern=None): - stderr = ctx.get("stderr", "") - if pattern not in stderr: - print("pattern:", repr(pattern)) - print("stderr:", repr(stderr)) - print("ctx:", ctx.as_dict()) - assert_eq(pattern in stderr, True) - - -# Check that stderr of latest runcmd does not contain a specific string. -def stderr_does_not_contain(ctx, pattern=None): - stderr = ctx.get("stderr", "") - if pattern not in stderr: - print("pattern:", repr(pattern)) - print("stderr:", repr(stderr)) - print("ctx:", ctx.as_dict()) - assert_eq(pattern not in stderr, True) diff --git a/runcmd.yaml b/runcmd.yaml deleted file mode 100644 index 02e5ee1..0000000 --- a/runcmd.yaml +++ /dev/null @@ -1,13 +0,0 @@ -- then: exit code is non-zero - function: exit_code_nonzero - -- then: output matches /(?P<pattern>.+)/ - function: stdout_contains - regex: true - -- then: stderr matches /(?P<pattern>.+)/ - function: stderr_contains - regex: true - -- then: program finished successfully - function: exit_code_zero diff --git a/subplot/jt.py b/subplot/jt.py new file mode 100644 index 0000000..2c5a4fc --- /dev/null +++ b/subplot/jt.py @@ -0,0 +1,28 @@ +import logging +import os + + +def run_jt_init(ctx, dirname=None, journalname=None, title=None): + runcmd(ctx, [_binary("jt"), "init", dirname, journalname, title]) + + +def run_jt_list_journals(ctx): + runcmd(ctx, [_binary("jt"), "list-journals"]) + + +def run_jt_is_journal(ctx, dirname=None): + runcmd(ctx, [_binary("jt"), "is-journal", dirname]) + + +def _binary(name): + return os.path.join(srcdir, "target", "debug", "jt2") + + +def is_directory(ctx, dirname=None): + logging.debug("checking if %r is a directory", dirname) + assert_eq(os.path.isdir(dirname), True) + + +def output_contains(ctx, pattern=None): + logging.debug("checking if %r contains", ctx["stdout"], pattern) + assert_eq(pattern in ctx["stdout"], True) diff --git a/subplot/jt.yaml b/subplot/jt.yaml new file mode 100644 index 0000000..863dbeb --- /dev/null +++ b/subplot/jt.yaml @@ -0,0 +1,16 @@ +- when: I run jt init (?P<dirname>\S+) (?P<journalname>\S+) "(?P<title>.*)" + regex: true + function: run_jt_init + +- when: I run jt list-journals + function: run_jt_list_journals + +- when: I run jt is-journal {dirname} + function: run_jt_is_journal + +- then: directory {dirname} exists + function: is_directory + +- then: output contains "(?P<pattern>.*)" + regex: true + function: output_contains diff --git a/subplot/runcmd.py b/subplot/runcmd.py new file mode 100644 index 0000000..7193c15 --- /dev/null +++ b/subplot/runcmd.py @@ -0,0 +1,77 @@ +# Some step implementations for running commands and capturing the result. + +import subprocess + + +# Run a command, capture its stdout, stderr, and exit code in context. +def runcmd(ctx, argv, **kwargs): + p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs) + stdout, stderr = p.communicate("") + ctx["argv"] = argv + ctx["stdout"] = stdout.decode("utf-8") + ctx["stderr"] = stderr.decode("utf-8") + ctx["exit"] = p.returncode + + +# Check that latest exit code captured by runcmd was a specific one. +def exit_code_is(ctx, wanted): + if ctx.get("exit") != wanted: + print("context:", ctx.as_dict()) + assert_eq(ctx.get("exit"), wanted) + + +# Check that latest exit code captured by runcmd was not a specific one. +def exit_code_is_not(ctx, unwanted): + if ctx.get("exit") == unwanted: + print("context:", ctx.as_dict()) + assert_ne(ctx.get("exit"), unwanted) + + +# Check that latest exit code captured by runcmd was zero. +def exit_code_zero(ctx): + exit_code_is(ctx, 0) + + +# Check that latest exit code captured by runcmd was not zero. +def exit_code_nonzero(ctx): + exit_code_is_not(ctx, 0) + + +# Check that stdout of latest runcmd contains a specific string. +def stdout_contains(ctx, pattern=None): + stdout = ctx.get("stdout", "") + if pattern not in stdout: + print("pattern:", repr(pattern)) + print("stdout:", repr(stdout)) + print("ctx:", ctx.as_dict()) + assert_eq(pattern in stdout, True) + + +# Check that stdout of latest runcmd does not contain a specific string. +def stdout_does_not_contain(ctx, pattern=None): + stdout = ctx.get("stdout", "") + if pattern in stdout: + print("pattern:", repr(pattern)) + print("stdout:", repr(stdout)) + print("ctx:", ctx.as_dict()) + assert_eq(pattern not in stdout, True) + + +# Check that stderr of latest runcmd does contains a specific string. +def stderr_contains(ctx, pattern=None): + stderr = ctx.get("stderr", "") + if pattern not in stderr: + print("pattern:", repr(pattern)) + print("stderr:", repr(stderr)) + print("ctx:", ctx.as_dict()) + assert_eq(pattern in stderr, True) + + +# Check that stderr of latest runcmd does not contain a specific string. +def stderr_does_not_contain(ctx, pattern=None): + stderr = ctx.get("stderr", "") + if pattern not in stderr: + print("pattern:", repr(pattern)) + print("stderr:", repr(stderr)) + print("ctx:", ctx.as_dict()) + assert_eq(pattern not in stderr, True) diff --git a/subplot/runcmd.yaml b/subplot/runcmd.yaml new file mode 100644 index 0000000..02e5ee1 --- /dev/null +++ b/subplot/runcmd.yaml @@ -0,0 +1,13 @@ +- then: exit code is non-zero + function: exit_code_nonzero + +- then: output matches /(?P<pattern>.+)/ + function: stdout_contains + regex: true + +- then: stderr matches /(?P<pattern>.+)/ + function: stderr_contains + regex: true + +- then: program finished successfully + function: exit_code_zero -- cgit v1.2.1 From 4332fb7fbc316b5a64c99e50cb6384bda656b136 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius <liw@liw.fi> Date: Fri, 9 Oct 2020 10:29:41 +0300 Subject: chore: update vendored copy of runcmd library from Subplot Since the library interface has change, make relevant changes elsewhere. --- jt.md | 12 +- subplot/jt.py | 6 +- subplot/jt.yaml | 6 +- subplot/runcmd.py | 312 ++++++++++++++++++++++++++++++++++++++++------------ subplot/runcmd.yaml | 86 +++++++++++++-- 5 files changed, 329 insertions(+), 93 deletions(-) diff --git a/jt.md b/jt.md index fd867db..6c2eb9b 100644 --- a/jt.md +++ b/jt.md @@ -43,15 +43,15 @@ verified using *scenarios* for the [Subplot][] tool. using the tool. ~~~scenario -when I run jt init jrnl default "My test journal" -then program finished successfully +when I invoke jt init jrnl default "My test journal" +then command is successful and directory jrnl exists -when I run jt is-journal jrnl -then program finished successfully +when I invoke jt is-journal jrnl +then command is successful -when I run jt is-journal bogus -then exit code is non-zero +when I invoke jt is-journal bogus +then command fails ~~~ diff --git a/subplot/jt.py b/subplot/jt.py index 2c5a4fc..d8bb7fc 100644 --- a/subplot/jt.py +++ b/subplot/jt.py @@ -3,15 +3,15 @@ import os def run_jt_init(ctx, dirname=None, journalname=None, title=None): - runcmd(ctx, [_binary("jt"), "init", dirname, journalname, title]) + runcmd_run(ctx, [_binary("jt"), "init", dirname, journalname, title]) def run_jt_list_journals(ctx): - runcmd(ctx, [_binary("jt"), "list-journals"]) + runcmd_run(ctx, [_binary("jt"), "list-journals"]) def run_jt_is_journal(ctx, dirname=None): - runcmd(ctx, [_binary("jt"), "is-journal", dirname]) + runcmd_run(ctx, [_binary("jt"), "is-journal", dirname]) def _binary(name): diff --git a/subplot/jt.yaml b/subplot/jt.yaml index 863dbeb..77b8c82 100644 --- a/subplot/jt.yaml +++ b/subplot/jt.yaml @@ -1,11 +1,11 @@ -- when: I run jt init (?P<dirname>\S+) (?P<journalname>\S+) "(?P<title>.*)" +- when: I invoke jt init (?P<dirname>\S+) (?P<journalname>\S+) "(?P<title>.*)" regex: true function: run_jt_init -- when: I run jt list-journals +- when: I invoke jt list-journals function: run_jt_list_journals -- when: I run jt is-journal {dirname} +- when: I invoke jt is-journal {dirname} function: run_jt_is_journal - then: directory {dirname} exists diff --git a/subplot/runcmd.py b/subplot/runcmd.py index 7193c15..532b60b 100644 --- a/subplot/runcmd.py +++ b/subplot/runcmd.py @@ -1,77 +1,243 @@ -# Some step implementations for running commands and capturing the result. - +import logging +import os +import re +import shlex import subprocess -# Run a command, capture its stdout, stderr, and exit code in context. -def runcmd(ctx, argv, **kwargs): - p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs) +# +# Helper functions. +# + +# Get exit code or other stored data about the latest command run by +# runcmd_run. + + +def _runcmd_get(ctx, name): + ns = ctx.declare("_runcmd") + return ns[name] + + +def runcmd_get_exit_code(ctx): + return _runcmd_get(ctx, "exit") + + +def runcmd_get_stdout(ctx): + return _runcmd_get(ctx, "stdout") + + +def runcmd_get_stdout_raw(ctx): + return _runcmd_get(ctx, "stdout.raw") + + +def runcmd_get_stderr(ctx): + return _runcmd_get(ctx, "stderr") + + +def runcmd_get_stderr_raw(ctx): + return _runcmd_get(ctx, "stderr.raw") + + +def runcmd_get_argv(ctx): + return _runcmd_get(ctx, "argv") + + +# Run a command, given an argv and other arguments for subprocess.Popen. +# +# This is meant to be a helper function, not bound directly to a step. The +# stdout, stderr, and exit code are stored in the "_runcmd" namespace in the +# ctx context. +def runcmd_run(ctx, argv, **kwargs): + ns = ctx.declare("_runcmd") + env = dict(os.environ) + pp = ns.get("path-prefix") + if pp: + env["PATH"] = pp + ":" + env["PATH"] + + logging.debug(f"runcmd_run") + logging.debug(f" argv: {argv}") + logging.debug(f" env: {env}") + p = subprocess.Popen( + argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env, **kwargs + ) stdout, stderr = p.communicate("") - ctx["argv"] = argv - ctx["stdout"] = stdout.decode("utf-8") - ctx["stderr"] = stderr.decode("utf-8") - ctx["exit"] = p.returncode - - -# Check that latest exit code captured by runcmd was a specific one. -def exit_code_is(ctx, wanted): - if ctx.get("exit") != wanted: - print("context:", ctx.as_dict()) - assert_eq(ctx.get("exit"), wanted) - - -# Check that latest exit code captured by runcmd was not a specific one. -def exit_code_is_not(ctx, unwanted): - if ctx.get("exit") == unwanted: - print("context:", ctx.as_dict()) - assert_ne(ctx.get("exit"), unwanted) - - -# Check that latest exit code captured by runcmd was zero. -def exit_code_zero(ctx): - exit_code_is(ctx, 0) - - -# Check that latest exit code captured by runcmd was not zero. -def exit_code_nonzero(ctx): - exit_code_is_not(ctx, 0) - - -# Check that stdout of latest runcmd contains a specific string. -def stdout_contains(ctx, pattern=None): - stdout = ctx.get("stdout", "") - if pattern not in stdout: - print("pattern:", repr(pattern)) - print("stdout:", repr(stdout)) - print("ctx:", ctx.as_dict()) - assert_eq(pattern in stdout, True) - - -# Check that stdout of latest runcmd does not contain a specific string. -def stdout_does_not_contain(ctx, pattern=None): - stdout = ctx.get("stdout", "") - if pattern in stdout: - print("pattern:", repr(pattern)) - print("stdout:", repr(stdout)) - print("ctx:", ctx.as_dict()) - assert_eq(pattern not in stdout, True) - - -# Check that stderr of latest runcmd does contains a specific string. -def stderr_contains(ctx, pattern=None): - stderr = ctx.get("stderr", "") - if pattern not in stderr: - print("pattern:", repr(pattern)) - print("stderr:", repr(stderr)) - print("ctx:", ctx.as_dict()) - assert_eq(pattern in stderr, True) - - -# Check that stderr of latest runcmd does not contain a specific string. -def stderr_does_not_contain(ctx, pattern=None): - stderr = ctx.get("stderr", "") - if pattern not in stderr: - print("pattern:", repr(pattern)) - print("stderr:", repr(stderr)) - print("ctx:", ctx.as_dict()) - assert_eq(pattern not in stderr, True) + ns["argv"] = argv + ns["stdout.raw"] = stdout + ns["stderr.raw"] = stderr + ns["stdout"] = stdout.decode("utf-8") + ns["stderr"] = stderr.decode("utf-8") + ns["exit"] = p.returncode + logging.debug(f" ctx: {ctx}") + logging.debug(f" ns: {ns}") + + +# Step: prepend srcdir to PATH whenever runcmd runs a command. +def runcmd_helper_srcdir_path(ctx): + srcdir = globals()["srcdir"] + runcmd_prepend_to_path(ctx, srcdir) + + +# Step: This creates a helper script. +def runcmd_helper_script(ctx, filename=None): + get_file = globals()["get_file"] + with open(filename, "wb") as f: + f.write(get_file(filename)) + + +# +# Step functions for running commands. +# + + +def runcmd_prepend_to_path(ctx, dirname=None): + ns = ctx.declare("_runcmd") + pp = ns.get("path-prefix", "") + if pp: + pp = f"{pp}:{dirname}" + else: + pp = dirname + ns["path-prefix"] = pp + + +def runcmd_step(ctx, argv0=None, args=None): + runcmd_try_to_run(ctx, argv0=argv0, args=args) + runcmd_exit_code_is_zero(ctx) + + +def runcmd_try_to_run(ctx, argv0=None, args=None): + argv = [shlex.quote(argv0)] + shlex.split(args) + runcmd_run(ctx, argv) + + +# +# Step functions for examining exit codes. +# + + +def runcmd_exit_code_is_zero(ctx): + runcmd_exit_code_is(ctx, exit=0) + + +def runcmd_exit_code_is(ctx, exit=None): + assert_eq = globals()["assert_eq"] + assert_eq(runcmd_get_exit_code(ctx), int(exit)) + + +def runcmd_exit_code_is_nonzero(ctx): + runcmd_exit_code_is_not(ctx, exit=0) + + +def runcmd_exit_code_is_not(ctx, exit=None): + assert_ne = globals()["assert_ne"] + assert_ne(runcmd_get_exit_code(ctx), int(exit)) + + +# +# Step functions and helpers for examining output in various ways. +# + + +def runcmd_stdout_is(ctx, text=None): + _runcmd_output_is(runcmd_get_stdout(ctx), text) + + +def runcmd_stdout_isnt(ctx, text=None): + _runcmd_output_isnt(runcmd_get_stdout(ctx), text) + + +def runcmd_stderr_is(ctx, text=None): + _runcmd_output_is(runcmd_get_stderr(ctx), text) + + +def runcmd_stderr_isnt(ctx, text=None): + _runcmd_output_isnt(runcmd_get_stderr(ctx), text) + + +def _runcmd_output_is(actual, wanted): + assert_eq = globals()["assert_eq"] + wanted = bytes(wanted, "utf8").decode("unicode_escape") + logging.debug("_runcmd_output_is:") + logging.debug(f" actual: {actual!r}") + logging.debug(f" wanted: {wanted!r}") + assert_eq(actual, wanted) + + +def _runcmd_output_isnt(actual, wanted): + assert_ne = globals()["assert_ne"] + wanted = bytes(wanted, "utf8").decode("unicode_escape") + logging.debug("_runcmd_output_isnt:") + logging.debug(f" actual: {actual!r}") + logging.debug(f" wanted: {wanted!r}") + assert_ne(actual, wanted) + + +def runcmd_stdout_contains(ctx, text=None): + _runcmd_output_contains(runcmd_get_stdout(ctx), text) + + +def runcmd_stdout_doesnt_contain(ctx, text=None): + _runcmd_output_doesnt_contain(runcmd_get_stdout(ctx), text) + + +def runcmd_stderr_contains(ctx, text=None): + _runcmd_output_contains(runcmd_get_stderr(ctx), text) + + +def runcmd_stderr_doesnt_contain(ctx, text=None): + _runcmd_output_doesnt_contain(runcmd_get_stderr(ctx), text) + + +def _runcmd_output_contains(actual, wanted): + assert_eq = globals()["assert_eq"] + wanted = bytes(wanted, "utf8").decode("unicode_escape") + logging.debug("_runcmd_output_contains:") + logging.debug(f" actual: {actual!r}") + logging.debug(f" wanted: {wanted!r}") + assert_eq(wanted in actual, True) + + +def _runcmd_output_doesnt_contain(actual, wanted): + assert_ne = globals()["assert_ne"] + wanted = bytes(wanted, "utf8").decode("unicode_escape") + logging.debug("_runcmd_output_doesnt_contain:") + logging.debug(f" actual: {actual!r}") + logging.debug(f" wanted: {wanted!r}") + assert_ne(wanted in actual, True) + + +def runcmd_stdout_matches_regex(ctx, regex=None): + _runcmd_output_matches_regex(runcmd_get_stdout(ctx), regex) + + +def runcmd_stdout_doesnt_match_regex(ctx, regex=None): + _runcmd_output_doesnt_match_regex(runcmd_get_stdout(ctx), regex) + + +def runcmd_stderr_matches_regex(ctx, regex=None): + _runcmd_output_matches_regex(runcmd_get_stderr(ctx), regex) + + +def runcmd_stderr_doesnt_match_regex(ctx, regex=None): + _runcmd_output_doesnt_match_regex(runcmd_get_stderr(ctx), regex) + + +def _runcmd_output_matches_regex(actual, regex): + assert_ne = globals()["assert_ne"] + r = re.compile(regex) + m = r.search(actual) + logging.debug("_runcmd_output_matches_regex:") + logging.debug(f" actual: {actual!r}") + logging.debug(f" regex: {regex!r}") + logging.debug(f" match: {m}") + assert_ne(m, None) + + +def _runcmd_output_doesnt_match_regex(actual, regex): + assert_eq = globals()["assert_eq"] + r = re.compile(regex) + m = r.search(actual) + logging.debug("_runcmd_output_doesnt_match_regex:") + logging.debug(f" actual: {actual!r}") + logging.debug(f" regex: {regex!r}") + logging.debug(f" match: {m}") + assert_eq(m, None) diff --git a/subplot/runcmd.yaml b/subplot/runcmd.yaml index 02e5ee1..48dde90 100644 --- a/subplot/runcmd.yaml +++ b/subplot/runcmd.yaml @@ -1,13 +1,83 @@ -- then: exit code is non-zero - function: exit_code_nonzero +# Steps to run commands. -- then: output matches /(?P<pattern>.+)/ - function: stdout_contains +- given: helper script {filename} for runcmd + function: runcmd_helper_script + +- given: srcdir is in the PATH + function: runcmd_helper_srcdir_path + +- when: I run (?P<argv0>\S+)(?P<args>.*) regex: true + function: runcmd_step -- then: stderr matches /(?P<pattern>.+)/ - function: stderr_contains +- when: I try to run (?P<argv0>\S+)(?P<args>.*) regex: true + function: runcmd_try_to_run + +# Steps to examine exit code of latest command. + +- then: exit code is {exit} + function: runcmd_exit_code_is + +- then: exit code is not {exit} + function: runcmd_exit_code_is_not + +- then: command is successful + function: runcmd_exit_code_is_zero + +- then: command fails + function: runcmd_exit_code_is_nonzero + +# Steps to examine stdout/stderr for exact content. + +- then: stdout is exactly "(?P<text>.*)" + regex: true + function: runcmd_stdout_is + +- then: "stdout isn't exactly \"(?P<text>.*)\"" + regex: true + function: runcmd_stdout_isnt + +- then: stderr is exactly "(?P<text>.*)" + regex: true + function: runcmd_stderr_is + +- then: "stderr isn't exactly \"(?P<text>.*)\"" + regex: true + function: runcmd_stderr_isnt + +# Steps to examine stdout/stderr for sub-strings. -- then: program finished successfully - function: exit_code_zero +- then: stdout contains "(?P<text>.*)" + regex: true + function: runcmd_stdout_contains + +- then: "stdout doesn't contain \"(?P<text>.*)\"" + regex: true + function: runcmd_stdout_doesnt_contain + +- then: stderr contains "(?P<text>.*)" + regex: true + function: runcmd_stderr_contains + +- then: "stderr doesn't contain \"(?P<text>.*)\"" + regex: true + function: runcmd_stderr_doesnt_contain + +# Steps to match stdout/stderr against regular expressions. + +- then: stdout matches regex (?P<regex>.*) + regex: true + function: runcmd_stdout_matches_regex + +- then: stdout doesn't match regex (?P<regex>.*) + regex: true + function: runcmd_stdout_doesnt_match_regex + +- then: stderr matches regex (?P<regex>.*) + regex: true + function: runcmd_stderr_matches_regex + +- then: stderr doesn't match regex (?P<regex>.*) + regex: true + function: runcmd_stderr_doesnt_match_regex -- cgit v1.2.1 From e8a9639a00cf4ccd2665fd3b6fe499cf77b88c14 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius <liw@liw.fi> Date: Fri, 9 Oct 2020 10:30:54 +0300 Subject: fix(subplot/jt.py): get global symbols via global() This is to make jt.py be lintable on its own. The symbols are available in the generated test program, when jt.py gets embedded within that, but linters don't know about that. --- subplot/jt.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/subplot/jt.py b/subplot/jt.py index d8bb7fc..1b46b0b 100644 --- a/subplot/jt.py +++ b/subplot/jt.py @@ -3,26 +3,32 @@ import os def run_jt_init(ctx, dirname=None, journalname=None, title=None): + runcmd_run = globals()["runcmd_run"] runcmd_run(ctx, [_binary("jt"), "init", dirname, journalname, title]) def run_jt_list_journals(ctx): + runcmd_run = globals()["runcmd_run"] runcmd_run(ctx, [_binary("jt"), "list-journals"]) def run_jt_is_journal(ctx, dirname=None): + runcmd_run = globals()["runcmd_run"] runcmd_run(ctx, [_binary("jt"), "is-journal", dirname]) def _binary(name): + srcdir = globals()["srcdir"] return os.path.join(srcdir, "target", "debug", "jt2") def is_directory(ctx, dirname=None): + assert_eq = globals()["assert_eq"] logging.debug("checking if %r is a directory", dirname) assert_eq(os.path.isdir(dirname), True) def output_contains(ctx, pattern=None): + assert_eq = globals()["assert_eq"] logging.debug("checking if %r contains", ctx["stdout"], pattern) assert_eq(pattern in ctx["stdout"], True) -- cgit v1.2.1