added tests for new ci stage; restructured go tool installs; closes #63; closes #46 (#64)

This commit is contained in:
epi052
2020-05-12 14:02:29 -05:00
committed by GitHub
parent 9a64f4c50b
commit fce38c22de
19 changed files with 427 additions and 97 deletions

39
tests/utils.py Normal file
View File

@@ -0,0 +1,39 @@
import sys
from contextlib import redirect_stdout, redirect_stderr
from cmd2.utils import StdSim
def normalize(block):
""" Normalize a block of text to perform comparison.
Strip newlines from the very beginning and very end Then split into separate lines and strip trailing whitespace
from each line.
"""
assert isinstance(block, str)
block = block.strip("\n")
return [line.rstrip() for line in block.splitlines()]
def run_cmd(app, cmd):
""" Clear out and err StdSim buffers, run the command, and return out and err """
saved_sysout = sys.stdout
sys.stdout = app.stdout
# This will be used to capture app.stdout and sys.stdout
copy_cmd_stdout = StdSim(app.stdout)
# This will be used to capture sys.stderr
copy_stderr = StdSim(sys.stderr)
try:
app.stdout = copy_cmd_stdout
with redirect_stdout(copy_cmd_stdout):
with redirect_stderr(copy_stderr):
app.onecmd_plus_hooks(cmd)
finally:
app.stdout = copy_cmd_stdout.inner_stream
sys.stdout = saved_sysout
out = copy_cmd_stdout.getvalue()
err = copy_stderr.getvalue()
return normalize(out), normalize(err)