Files
recon-pipeline/tests/utils.py
Ryan Good 1ad3adca82 Uninstall command (#66)
* Add do_uninstall function

* uninstall f/ amass/aqua/go

* uninstall functional on all tools

* Add in missed fixes from rebase

* solve permission issue

* Removes un-needed vars from yaml

* Resolves go test issues

* adds framework for uninstall tests

* Fixes uninstall tests for Go tools

* Adds uninstall testing for luigi and improves uninstall

* Adds uninstall testing for searchsploit

* Update installation documentation
2020-06-26 19:04:43 -05:00

44 lines
1.2 KiB
Python

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()
print(out)
print(err)
return normalize(out), normalize(err)