Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions nextflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ def full_path(self):
return Path(self.execution.path, "work", self.path)


def input_data(self, include_path=True):
def input_data(self, include_path=True, io=None):
"""A list of files passed to the process execution as inputs.

:param bool include_path: if ``False``, only filenames returned.
:param io: an optional custom io object to handle file operations.
:type: ``list``"""

inputs = []
if not self.path: return []
run = get_file_text(self.full_path / ".command.run")
run = get_file_text(self.full_path / ".command.run", io=io)
stage = re.search(r"nxf_stage\(\)((.|\n|\r)+?)}", run)
if not stage: return []
contents = stage[1]
Expand All @@ -135,7 +135,7 @@ def all_output_data(self, include_path=True, io=None):

outputs = []
if not self.path: return []
inputs = self.input_data(include_path=False)
inputs = self.input_data(include_path=False, io=io)
listdir = io.listdir if io else os.listdir
for f in listdir(self.full_path):
full_path = Path(f"{self.full_path}/{f}")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="nextflowpy",
version="0.12.1",
version="0.13.0",
description="A Python wrapper around Nextflow.",
long_description=long_description,
long_description_content_type="text/x-rst",
Expand Down
36 changes: 24 additions & 12 deletions tests/unit/test_process_executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def test_can_get_input_data(self, mock_text, mock_path):
self.process_execution.input_data(),
["/work/25/7eaa7786ca/file1.dat", "/work/fe/3b80569ba5/file2.dat"]
)
mock_text.assert_called_with(Path("/loc/.command.run"))
mock_text.assert_called_with(Path("/loc/.command.run"), io=None)


@patch("nextflow.models.ProcessExecution.full_path", new_callable=PropertyMock)
@patch("nextflow.models.get_file_text")
Expand All @@ -119,8 +119,8 @@ def test_can_get_input_data_filenames(self, mock_text, mock_path):
self.process_execution.input_data(include_path=False),
["file1.dat", "file2.dat"]
)
mock_text.assert_called_with(Path("/loc/.command.run"))
mock_text.assert_called_with(Path("/loc/.command.run"), io=None)


@patch("nextflow.models.ProcessExecution.full_path", new_callable=PropertyMock)
@patch("nextflow.models.get_file_text")
Expand All @@ -130,8 +130,8 @@ def test_can_handle_no_command_run_file(self, mock_text, mock_path):
self.assertEqual(
self.process_execution.input_data(include_path=False), []
)
mock_text.assert_called_with(Path("/loc/.command.run"))
mock_text.assert_called_with(Path("/loc/.command.run"), io=None)


@patch("nextflow.models.ProcessExecution.full_path", new_callable=PropertyMock)
@patch("nextflow.models.get_file_text")
Expand All @@ -141,7 +141,7 @@ def test_can_handle_no_staging(self, mock_text, mock_path):
self.assertEqual(
self.process_execution.input_data(include_path=False), []
)
mock_text.assert_called_with(Path("/loc/.command.run"))
mock_text.assert_called_with(Path("/loc/.command.run"), io=None)


@patch("nextflow.models.ProcessExecution.full_path", new_callable=PropertyMock)
Expand Down Expand Up @@ -178,7 +178,19 @@ def test_can_handle_staging_by_copying(self, mock_text, mock_path):
self.process_execution.input_data(),
["/work/25/7eaa7786ca/file1.dat", "/work/fe/3b80569ba5/file2.dat"]
)
mock_text.assert_called_with(Path("/loc/.command.run"))
mock_text.assert_called_with(Path("/loc/.command.run"), io=None)


@patch("nextflow.models.ProcessExecution.full_path", new_callable=PropertyMock)
def test_can_get_input_data_with_custom_io(self, mock_path):
mock_path.return_value = Path("/loc")
io = Mock()
io.read.return_value = self.text
self.assertEqual(
self.process_execution.input_data(io=io),
["/work/25/7eaa7786ca/file1.dat", "/work/fe/3b80569ba5/file2.dat"]
)
io.read.assert_called_with(Path("/loc/.command.run"))



Expand All @@ -195,9 +207,9 @@ def test_can_get_all_output_data(self, mock_dir, mock_path, mock_input):
self.make_process_execution().all_output_data(),
[str(Path("/loc/file1")), str(Path("/loc/file3"))]
)
mock_input.assert_called_with(include_path=False)
mock_input.assert_called_with(include_path=False, io=None)
mock_dir.assert_called_with(mock_path.return_value)


@patch("nextflow.models.ProcessExecution.input_data")
@patch("nextflow.models.ProcessExecution.full_path", new_callable=PropertyMock)
Expand All @@ -210,7 +222,7 @@ def test_can_get_all_output_filenames(self, mock_dir, mock_path, mock_input):
self.make_process_execution().all_output_data(include_path=False),
["file1", "file3"]
)
mock_input.assert_called_with(include_path=False)
mock_input.assert_called_with(include_path=False, io=None)
mock_dir.assert_called_with(mock_path.return_value)


Expand Down Expand Up @@ -239,4 +251,4 @@ def test_can_use_custom_io(self, mock_path, mock_input):
self.make_process_execution().all_output_data(io=io),
[str(Path("/loc/file1")), str(Path("/loc/file3"))]
)
mock_input.assert_called_with(include_path=False)
mock_input.assert_called_with(include_path=False, io=io)
Loading