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_show_outputs_with_directory(runner, client, run):
"""Output files in directory are not shown as separate outputs."""
base_sh = [
'bash', '-c', 'DIR="$0"; mkdir -p "$DIR"; '
'for x in "$@"; do touch "$DIR/$x"; done'
]
assert 0 == run(args=['run'] + base_sh + ['output', 'foo', 'bar'])
assert (client.path / 'output' / 'foo').exists()
assert (client.path / 'output' / 'bar').exists()
cmd = ['show', 'outputs']
result = runner.invoke(cli, cmd)
assert 0 == result.exit_code
assert {'output'} == set(result.output.strip().split('\n'))
result = runner.invoke(cli, cmd + ['output'])
assert 0 == result.exit_code
assert {'output'} == set(result.output.strip().split('\n'))
result = runner.invoke(cli, cmd + ['output/foo'])
assert 0 == result.exit_code
assert {'output'} == set(result.output.strip().split('\n'))
result = runner.invoke(cli, cmd + ['output/foo', 'output/bar'])
assert 0 == result.exit_code
assert {'output'} == set(result.output.strip().split('\n'))
def test_run_simple(runner, project):
"""Test tracking of run command."""
cmd = ['echo', 'test']
result = runner.invoke(cli, ['run', '--no-output'] + cmd)
assert 0 == result.exit_code
# There are no output files.
result = runner.invoke(cli, ['log'])
assert 1 == len(result.output.strip().split('\n'))
# Display tools with no outputs.
result = runner.invoke(cli, ['log', '--no-output'])
assert '.renku/workflow/' in result.output
def test_status_with_old_repository(isolated_runner, old_project):
"""Test status on all old repositories created by old version of renku."""
runner = isolated_runner
result = runner.invoke(cli, ['status'])
assert 0 == result.exit_code
output = result.output.split('\n')
assert output.pop(0) == 'On branch master'
assert output.pop(0) == 'All files were generated from the latest inputs.'
data.write_text('data')
# Empty destination
destination = cwd / 'destination'
source_wc = cwd / 'destination_source.wc'
# Non empty destination
invalid_destination = cwd / 'invalid_destination'
invalid_destination.mkdir(parents=True)
(invalid_destination / 'non_empty').touch()
repo = git.Repo(project)
repo.git.add('--all')
repo.index.commit('Created source directory')
cmd = ['run', 'cp', '-LRf', str(source), str(destination)]
result = runner.invoke(cli, cmd, catch_exceptions=False)
assert 0 == result.exit_code
destination_source = destination / data.name
assert destination_source.exists()
# check that the output in subdir is added to LFS
with (cwd / '.gitattributes').open() as f:
gitattr = f.read()
assert str(destination.relative_to(cwd)) + '/**' in gitattr
assert destination_source.name in subprocess.check_output([
'git', 'lfs', 'ls-files'
]).decode()
cmd = ['run', 'wc']
assert 0 == run(args=cmd, stdin=destination_source, stdout=source_wc)
def test_remove_dataset_file(isolated_runner, client, tmpdir):
"""Test remove of a file that belongs to a dataset."""
runner = isolated_runner
# create a dataset
result = runner.invoke(cli, ['dataset', 'create', 'testing'])
assert 0 == result.exit_code
assert 'OK' in result.output
source = tmpdir.join('remove_dataset.file')
source.write('data')
result = runner.invoke(cli, ['dataset', 'add', 'testing', source.strpath])
assert 0 == result.exit_code
assert (client.path / client.datadir / 'testing' /
'remove_dataset.file').exists()
result = runner.invoke(cli, ['doctor'])
assert 0 == result.exit_code
result = runner.invoke(cli, ['rm', 'data'])
test_paths = []
for i in range(3):
new_file = tmpdir.join('file_{0}'.format(i))
new_file.write(str(i))
paths.append(str(new_file))
test_paths.append(str(new_file.relto(tmpdir.join('..'))))
# add data
result = runner.invoke(
cli,
['dataset', 'add', 'my-dataset'] + paths,
)
assert 0 == result.exit_code
result = runner.invoke(
cli, ['log', '--strict', '--format={}'.format(format)]
)
assert 0 == result.exit_code, result.output
assert all(p in result.output for p in test_paths)
def test_run_log_strict(runner, project, run_shell, format):
"""Test log output of run command."""
# Run a shell command with pipe.
result = run_shell('renku run echo "a" > output')
# Assert created output file.
result = runner.invoke(
cli, ['log', '--strict', '--format={}'.format(format)]
)
assert 0 == result.exit_code, result.output
assert '.renku/workflow/' in result.output
def test_git_hooks(runner, project):
"""Test detection of not-installed git hooks."""
# Initially, every thing is OK
result = runner.invoke(cli, ['doctor'])
assert 0 == result.exit_code
assert 'Everything seems to be ok.' in result.output
result = runner.invoke(cli, ['githooks', 'uninstall'])
assert 0 == result.exit_code
result = runner.invoke(cli, ['doctor'])
assert 1 == result.exit_code
assert 'Git hooks are not installed.' in result.output
def test_datasets_create_clean(runner, project, client):
"""Test creating a dataset in clean repository."""
# create a dataset
result = runner.invoke(cli, ['dataset', 'create', 'dataset'])
assert 0 == result.exit_code
assert 'OK' in result.output
dataset = client.load_dataset(name='dataset')
assert dataset
staged = client.repo.index.diff('HEAD')
for file_path in staged:
assert 'datasets' not in file_path
untracked = client.repo.untracked_files
for file_path in untracked:
assert 'datasets' not in file_path
def test_limit_log(runner, project, run):
"""Test naming of CWL tools and workflows."""
cwd = Path(project)
data = cwd / 'data.txt'
output = cwd / 'output.txt'
assert 0 == run(args=('run', 'echo', 'hello'), stdout=data)
assert data.exists()
assert 0 == run(args=('run', 'wc', '-c'), stdin=data, stdout=output)
assert output.exists()
cmd = ['log', '--revision', 'HEAD^..', output.name]
result = runner.invoke(cli, cmd)
assert 0 == result.exit_code
assert data.name not in result.output
assert output.name in result.output
cmd = ['log', '--revision', 'HEAD^']
result = runner.invoke(cli, cmd)
assert 0 == result.exit_code
assert data.name in result.output
assert output.name not in result.output