def test_output_directory_with_output_option(runner, client, run): """Test directory cleanup with the output option.""" base_sh = ['sh', '-c', 'mkdir -p "$0"; touch "$0/$1"'] assert 0 == run(args=['run'] + base_sh + ['output', 'foo']) assert (client.path / 'output' / 'foo').exists() # The output directory is wronly detected. assert 1 == run(args=['run'] + base_sh + ['output', 'foo']) assert 0 == run(args=['run', '--no-output'] + base_sh + ['output', 'foo']) # There should be two command line tools. tools = list(client.workflow_path.glob('*_sh.cwl')) assert 2 == len(tools) cwls = [] for tool_path in tools: with tool_path.open('r') as f: cwls.append(CWLClass.from_cwl(yaml.safe_load(f))) assert cwls[0].inputs != cwls[1].inputs assert cwls[0].outputs != cwls[1].outputs # The output directory is cleaned. assert 0 == run(args=['run', '--output', 'output'] + base_sh + ['output', 'bar']) assert not (client.path / 'output' / 'foo').exists() assert (client.path / 'output' / 'bar').exists()
def test_modified_tool(runner, project, capsys): """Test detection of modified tool.""" from renku.api import LocalClient client = LocalClient(project) repo = client.git greeting = client.path / 'greeting.txt' with capsys.disabled(): with greeting.open('wb') as stdout: try: old_stdout = sys.stdout sys.stdout = stdout try: cli.cli.main(args=('run', 'echo', 'hello'), ) except SystemExit as e: assert e.code in {None, 0} finally: sys.stdout = old_stdout cmd = ['status'] result = runner.invoke(cli.cli, cmd) assert result.exit_code == 0 # There should be only one command line tool. tools = list(client.workflow_path.glob('*_echo.cwl')) assert 1 == len(tools) tool_path = tools[0] with tool_path.open('r') as f: command_line_tool = CWLClass.from_cwl(yaml.load(f)) # Simulate a manual edit. command_line_tool.inputs[0].default = 'ahoj' command_line_tool.stdout = 'pozdrav.txt' with tool_path.open('w') as f: yaml.dump(ascwl( command_line_tool, filter=lambda _, x: x is not None, basedir=client.workflow_path, ), stream=f, default_flow_style=False) repo.git.add('--all') repo.index.commit('Modified tool', skip_hooks=True) assert 0 == _run_update(runner, capsys) output = client.path / 'pozdrav.txt' assert output.exists() with output.open('r') as f: assert 'ahoj\n' == f.read() cmd = ['status'] result = runner.invoke(cli.cli, cmd) assert 0 == result.exit_code
def renku_cli(*args): before_cwl_files = set(client.workflow_path.glob('*.cwl')) exit_code = run(args) after_cwl_files = set(client.workflow_path.glob('*.cwl')) new_files = after_cwl_files - before_cwl_files assert len(new_files) <= 1 if new_files: cwl_filepath = new_files.pop() with cwl_filepath.open('r') as f: content = CWLClass.from_cwl(yaml.safe_load(f)) else: content = None return exit_code, content
def test_with_an_output_option(runner, client, run): """Test detection of an output file with an output option.""" assert 0 == run(args=('run', 'touch', 'hello.txt')) assert 0 == run(args=('run', '--output', 'hello.txt', 'touch', 'hello.txt')) # There should be two command line tool. tools = list(client.workflow_path.glob('*_touch.cwl')) assert 2 == len(tools) cwls = [] for tool_path in tools: with tool_path.open('r') as f: cwls.append(CWLClass.from_cwl(yaml.safe_load(f))) assert cwls[0].inputs == cwls[1].inputs assert cwls[0].outputs == cwls[1].outputs
def test_output_directory_without_separate_outputs(runner, client, run): """Output files in directory are not listed as separate outputs. See https://github.com/SwissDataScienceCenter/renku-python/issues/387 """ base_sh = ['sh', '-c', 'mkdir -p "$0"; touch "$0/$1"'] assert 0 == run(args=['run'] + base_sh + ['output', 'foo']) assert (client.path / 'output' / 'foo').exists() # There should be only one command line tool. tools = list(client.workflow_path.glob('*_sh.cwl')) assert 1 == len(tools) with tools[0].open('r') as f: cwl = CWLClass.from_cwl(yaml.safe_load(f)) assert 1 == len(cwl.outputs) assert 'Directory' == cwl.outputs[0].type
def read_cwl_file(cwl_filepath): with cwl_filepath.open('r') as f: return CWLClass.from_cwl(yaml.safe_load(f))
def test_load_inputs_defined_as_type(): """Test loading of CWL definition with specific input parameters.""" assert CWLClass.from_cwl(yaml.load(LINK_CWL))