def test_outputs_removal(): def test_function(arg1): import os file1 = os.path.join(os.getcwd(), 'file1.txt') file2 = os.path.join(os.getcwd(), 'file2.txt') fp = open(file1, 'wt') fp.write('%d' % arg1) fp.close() fp = open(file2, 'wt') fp.write('%d' % arg1) fp.close() return file1, file2 out_dir = mkdtemp() n1 = pe.Node(niu.Function(input_names=['arg1'], output_names=['file1', 'file2'], function=test_function), base_dir=out_dir, name='testoutputs') n1.inputs.arg1 = 1 n1.config = {'execution': {'remove_unnecessary_outputs': True}} n1.config = merge_dict(deepcopy(config._sections), n1.config) n1.run() yield assert_true, os.path.exists(os.path.join(out_dir, n1.name, 'file1.txt')) yield assert_true, os.path.exists(os.path.join(out_dir, n1.name, 'file2.txt')) n1.needed_outputs = ['file2'] n1.run() yield assert_false, os.path.exists(os.path.join(out_dir, n1.name, 'file1.txt')) yield assert_true, os.path.exists(os.path.join(out_dir, n1.name, 'file2.txt')) rmtree(out_dir)
def run(self, plugin_args=None, updatehash=False): """ Execute the workflow XNAT-modified Linear runner only plugin_args : dictionary containing arguments to be sent to plugin constructor. see individual plugin doc strings for details. """ runner = LinearPlugin(plugin_args=plugin_args) flatgraph = self._create_flat_graph() self.config = merge_dict(deepcopy(config._sections), self.config) logger.info(str(sorted(self.config))) self._set_needed_outputs(flatgraph) execgraph = generate_expanded_graph(deepcopy(flatgraph)) for index, node in enumerate(execgraph.nodes()): node.config = self.config node.base_dir = self.base_dir node.index = index if isinstance(node, MapNode): node.use_plugin = (plugin, plugin_args) self._configure_exec_nodes(execgraph) self._write_report_info(self.base_dir, self.name, execgraph) runner.run(execgraph, updatehash=updatehash, config=self.config) return execgraph