Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_pretend_command(caplog):
caplog.set_level(logging.INFO)
# When command runs under pretend flag,
name = uniqstr()
touch = shell.ShellCommand("touch")
touch(name, pretend=True)
# then nothing should be executed
assert not path_exists(name)
# but log should be displayed
logs = caplog.text
assert re.search(r"run.*touch\s" + name, logs)
def test_ShellCommand(tmpfolder):
echo = shell.ShellCommand("echo")
output = echo("Hello Echo!!!")
assert next(output).strip('"') == "Hello Echo!!!"
python = shell.ShellCommand("python")
output = python("-c", 'print("Hello World")')
assert list(output)[-1] == "Hello World"
touch = shell.ShellCommand("touch")
touch("my-file.txt")
assert path_exists("my-file.txt")
def func(_):
shell.ShellCommand("non_existing_cmd")("--wrong-args")
def test_ShellCommand(tmpfolder):
echo = shell.ShellCommand("echo")
output = echo("Hello Echo!!!")
assert next(output).strip('"') == "Hello Echo!!!"
python = shell.ShellCommand("python")
output = python("-c", 'print("Hello World")')
assert list(output)[-1] == "Hello World"
touch = shell.ShellCommand("touch")
touch("my-file.txt")
assert path_exists("my-file.txt")
import pytest
from pyscaffold import shell
from pyscaffold.cli import main as putup
from pyscaffold.shell import command_exists, git
from pyscaffold.utils import chdir
__location__ = path_join(
os.getcwd(), os.path.dirname(inspect.getfile(inspect.currentframe()))
)
pytestmark = pytest.mark.slow
untar = shell.ShellCommand(("gtar" if command_exists("gtar") else "tar") + " xvzkf")
# ^ BSD tar differs in options from GNU tar,
# so make sure to use the correct one...
# https://xkcd.com/1168/
@pytest.fixture
def demoapp(tmpfolder, venv):
return DemoApp(tmpfolder, venv)
@pytest.fixture
def demoapp_data(tmpfolder, venv):
return DemoApp(tmpfolder, venv, data=True)
class DemoApp(object):
def test_ShellCommand(tmpfolder):
echo = shell.ShellCommand("echo")
output = echo("Hello Echo!!!")
assert next(output).strip('"') == "Hello Echo!!!"
python = shell.ShellCommand("python")
output = python("-c", 'print("Hello World")')
assert list(output)[-1] == "Hello World"
touch = shell.ShellCommand("touch")
touch("my-file.txt")
assert path_exists("my-file.txt")