forked from rpm-software-management/mock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
behave: better sub-project structure
- Loading branch information
Showing
7 changed files
with
85 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
BDD for Mock | ||
============ | ||
|
||
This test-suite can destroy your system! Not intentionally, but some steps | ||
require us to use root (e.g. install or remove packages). **Never** execute | ||
this test suite on your host system, allocate some disposable machine. | ||
|
||
How to run the tests | ||
-------------------- | ||
|
||
1. Install the Mock RPM that you want to test. | ||
|
||
2. Run `$ behave` command in this directory, with `--tags tagname` if you want | ||
to test only subset of all provided scenarios. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
""" Helper library for Mock's BDD """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
""" | ||
Executing commands in Mock's behave test suite. | ||
""" | ||
|
||
from contextlib import contextmanager | ||
import io | ||
import shlex | ||
import subprocess | ||
import sys | ||
|
||
|
||
@contextmanager | ||
def no_output(): | ||
""" | ||
Suppress stdout/stderr when it is not captured by behave | ||
https://github.com/behave/behave/issues/863 | ||
""" | ||
real_out = sys.stdout, sys.stderr | ||
sys.stdout = io.StringIO() | ||
sys.stderr = io.StringIO() | ||
yield | ||
sys.stdout, sys.stderr = real_out | ||
|
||
|
||
def quoted_cmd(cmd): | ||
""" shell quoted cmd array as string """ | ||
return " ".join(shlex.quote(arg) for arg in cmd) | ||
|
||
|
||
def run(cmd): | ||
""" | ||
Return exitcode, stdout, stderr. It's bad there's no such thing in behave | ||
directly. | ||
""" | ||
try: | ||
process = subprocess.Popen( | ||
cmd, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
universal_newlines=True, | ||
) | ||
stdout, stderr = process.communicate() | ||
print(f"Command exit status {process.returncode} in: {quoted_cmd(cmd)}") | ||
if stdout: | ||
print("stdout:") | ||
print(stdout) | ||
if stderr: | ||
print("stderr:") | ||
print(stderr) | ||
return process.returncode, stdout, stderr | ||
except (FileNotFoundError, PermissionError) as e: | ||
print(f"Error running command {quoted_cmd(cmd)}: {e}") | ||
return -1, "", str(e) | ||
|
||
|
||
def run_check(cmd): | ||
""" run, but check nonzero exit status """ | ||
retcode, stdout, stderr = run(cmd) | ||
if retcode != 0: | ||
raise Exception(f"Command failed with return code {retcode}: {quoted_cmd(cmd)}\n{stderr}") | ||
return stdout, stderr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters