Closed nicolocin closed 4 years ago
@dorota @satra - I'm not sure whether this is a bug or not. This is from running pytest -vvs --basetemp=/scratch/Thu/nlo/tmpdir2 pydra/engine/tests/test_shelltask.py
after I added tmpdir to the tests and updating results_function
in this commit ec3e92b1e
==================================================================================== FAILURES ====================================================================================
_____________________________________________________________ test_shell_cmd_inputspec_9[slurm-result_no_submitter] ______________________________________________________________
tmpdir = local('/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputspec_9_slu0'), plugin = 'slurm'
results_function = <function result_no_submitter at 0x2b2148cb3320>
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
def test_shell_cmd_inputspec_9(tmpdir, plugin, results_function):
"""
providing output name using input_spec (output_file_template in metadata),
the template has a suffix, the extension of the file will be moved to the end
"""
cmd = "cp"
file = tmpdir.mkdir("data_inp").join("file.txt")
file.write("content")
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"file_orig",
attr.ib(
type=File,
metadata={"position": 2, "help_string": "new file", "argstr": ""},
),
),
(
"file_copy",
attr.ib(
type=str,
metadata={
"output_file_template": "{file_orig}_copy",
"help_string": "output file",
"argstr": "",
},
),
),
],
bases=(ShellSpec,),
)
shelly = ShellCommandTask(
name="shelly", executable=cmd, input_spec=my_input_spec, file_orig=file
)
res = results_function(shelly, plugin, tmpdir)
assert res.output.stdout == ""
assert res.output.file_copy.exists()
> assert res.output.file_copy.name == "file_copy.txt"
E AssertionError: assert 'file.txt' == 'file_copy.txt'
E - file_copy.txt
E ? -----
E + file.txt
pydra/engine/tests/test_shelltask.py:1177: AssertionError
_______________________________________________________________ test_shell_cmd_inputspec_9[slurm-result_submitter] _______________________________________________________________
tmpdir = local('/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputspec_9_slu1'), plugin = 'slurm'
results_function = <function result_submitter at 0x2b2148cb3290>
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
def test_shell_cmd_inputspec_9(tmpdir, plugin, results_function):
"""
providing output name using input_spec (output_file_template in metadata),
the template has a suffix, the extension of the file will be moved to the end
"""
cmd = "cp"
file = tmpdir.mkdir("data_inp").join("file.txt")
file.write("content")
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"file_orig",
attr.ib(
type=File,
metadata={"position": 2, "help_string": "new file", "argstr": ""},
),
),
(
"file_copy",
attr.ib(
type=str,
metadata={
"output_file_template": "{file_orig}_copy",
"help_string": "output file",
"argstr": "",
},
),
),
],
bases=(ShellSpec,),
)
shelly = ShellCommandTask(
name="shelly", executable=cmd, input_spec=my_input_spec, file_orig=file
)
res = results_function(shelly, plugin, tmpdir)
assert res.output.stdout == ""
assert res.output.file_copy.exists()
> assert res.output.file_copy.name == "file_copy.txt"
E AssertionError: assert 'file.txt' == 'file_copy.txt'
E - file_copy.txt
E ? -----
E + file.txt
pydra/engine/tests/test_shelltask.py:1177: AssertionError
_____________________________________________________________ test_shell_cmd_inputspec_9a[slurm-result_no_submitter] _____________________________________________________________
tmpdir = local('/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputspec_9a_sl0'), plugin = 'slurm'
results_function = <function result_no_submitter at 0x2b2148cb3320>
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
def test_shell_cmd_inputspec_9a(tmpdir, plugin, results_function):
"""
providing output name using input_spec (output_file_template in metadata)
and the keep_extension is set to False, so the extension is removed completely.
"""
cmd = "cp"
file = tmpdir.join("file.txt")
file.write("content")
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"file_orig",
attr.ib(
type=File,
metadata={"position": 2, "help_string": "new file", "argstr": ""},
),
),
(
"file_copy",
attr.ib(
type=str,
metadata={
"output_file_template": "{file_orig}_copy",
"keep_extension": False,
"help_string": "output file",
"argstr": "",
},
),
),
],
bases=(ShellSpec,),
)
shelly = ShellCommandTask(
name="shelly", executable=cmd, input_spec=my_input_spec, file_orig=file
)
res = results_function(shelly, plugin, tmpdir)
assert res.output.stdout == ""
assert res.output.file_copy.exists()
> assert res.output.file_copy.name == "file_copy"
E AssertionError: assert 'vast-storage_copy' == 'file_copy'
E - file_copy
E + vast-storage_copy
pydra/engine/tests/test_shelltask.py:1225: AssertionError
______________________________________________________________ test_shell_cmd_inputspec_9a[slurm-result_submitter] _______________________________________________________________
tmpdir = local('/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputspec_9a_sl1'), plugin = 'slurm'
results_function = <function result_submitter at 0x2b2148cb3290>
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
def test_shell_cmd_inputspec_9a(tmpdir, plugin, results_function):
"""
providing output name using input_spec (output_file_template in metadata)
and the keep_extension is set to False, so the extension is removed completely.
"""
cmd = "cp"
file = tmpdir.join("file.txt")
file.write("content")
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"file_orig",
attr.ib(
type=File,
metadata={"position": 2, "help_string": "new file", "argstr": ""},
),
),
(
"file_copy",
attr.ib(
type=str,
metadata={
"output_file_template": "{file_orig}_copy",
"keep_extension": False,
"help_string": "output file",
"argstr": "",
},
),
),
],
bases=(ShellSpec,),
)
shelly = ShellCommandTask(
name="shelly", executable=cmd, input_spec=my_input_spec, file_orig=file
)
res = results_function(shelly, plugin, tmpdir)
assert res.output.stdout == ""
assert res.output.file_copy.exists()
> assert res.output.file_copy.name == "file_copy"
E AssertionError: assert 'vast-storage_copy' == 'file_copy'
E - file_copy
E + vast-storage_copy
pydra/engine/tests/test_shelltask.py:1225: AssertionError
_____________________________________________________________ test_shell_cmd_inputspec_9b[slurm-result_no_submitter] _____________________________________________________________
tmpdir = local('/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputspec_9b_sl0'), plugin = 'slurm'
results_function = <function result_no_submitter at 0x2b2148cb3320>
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
def test_shell_cmd_inputspec_9b(tmpdir, plugin, results_function):
"""
providing output name using input_spec (output_file_template in metadata)
and the keep_extension is set to False, so the extension is removed completely,
no suffix in the template.
"""
cmd = "cp"
file = tmpdir.join("file.txt")
file.write("content")
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"file_orig",
attr.ib(
type=File,
metadata={"position": 2, "help_string": "new file", "argstr": ""},
),
),
(
"file_copy",
attr.ib(
type=str,
metadata={
"output_file_template": "{file_orig}",
"keep_extension": False,
"help_string": "output file",
"argstr": "",
},
),
),
],
bases=(ShellSpec,),
)
shelly = ShellCommandTask(
name="shelly", executable=cmd, input_spec=my_input_spec, file_orig=file
)
res = results_function(shelly, plugin, tmpdir)
assert res.output.stdout == ""
assert res.output.file_copy.exists()
> assert res.output.file_copy.name == "file"
E AssertionError: assert 'vast-storage' == 'file'
E - file
E + vast-storage
pydra/engine/tests/test_shelltask.py:1272: AssertionError
______________________________________________________________ test_shell_cmd_inputspec_9b[slurm-result_submitter] _______________________________________________________________
tmpdir = local('/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputspec_9b_sl1'), plugin = 'slurm'
results_function = <function result_submitter at 0x2b2148cb3290>
@pytest.mark.parametrize("results_function", [result_no_submitter, result_submitter])
def test_shell_cmd_inputspec_9b(tmpdir, plugin, results_function):
"""
providing output name using input_spec (output_file_template in metadata)
and the keep_extension is set to False, so the extension is removed completely,
no suffix in the template.
"""
cmd = "cp"
file = tmpdir.join("file.txt")
file.write("content")
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"file_orig",
attr.ib(
type=File,
metadata={"position": 2, "help_string": "new file", "argstr": ""},
),
),
(
"file_copy",
attr.ib(
type=str,
metadata={
"output_file_template": "{file_orig}",
"keep_extension": False,
"help_string": "output file",
"argstr": "",
},
),
),
],
bases=(ShellSpec,),
)
shelly = ShellCommandTask(
name="shelly", executable=cmd, input_spec=my_input_spec, file_orig=file
)
res = results_function(shelly, plugin, tmpdir)
assert res.output.stdout == ""
assert res.output.file_copy.exists()
> assert res.output.file_copy.name == "file"
E AssertionError: assert 'vast-storage' == 'file'
E - file
E + vast-storage
pydra/engine/tests/test_shelltask.py:1272: AssertionError
============================================================================ short test summary info =============================================================================
FAILED pydra/engine/tests/test_shelltask.py::test_shell_cmd_inputspec_9[slurm-result_no_submitter] - AssertionError: assert 'file.txt' == 'file_copy.txt'
FAILED pydra/engine/tests/test_shelltask.py::test_shell_cmd_inputspec_9[slurm-result_submitter] - AssertionError: assert 'file.txt' == 'file_copy.txt'
FAILED pydra/engine/tests/test_shelltask.py::test_shell_cmd_inputspec_9a[slurm-result_no_submitter] - AssertionError: assert 'vast-storage_copy' == 'file_copy'
FAILED pydra/engine/tests/test_shelltask.py::test_shell_cmd_inputspec_9a[slurm-result_submitter] - AssertionError: assert 'vast-storage_copy' == 'file_copy'
FAILED pydra/engine/tests/test_shelltask.py::test_shell_cmd_inputspec_9b[slurm-result_no_submitter] - AssertionError: assert 'vast-storage' == 'file'
FAILED pydra/engine/tests/test_shelltask.py::test_shell_cmd_inputspec_9b[slurm-result_submitter] - AssertionError: assert 'vast-storage' == 'file'
======================================================== 6 failed, 109 passed, 1 skipped, 2 xfailed in 224.84s (0:03:44) =========================================================
yes, something is definitely wrong
@djarecka - I see, should I create a separate issue for this? Seems like the same issue with these tests
FAILED pydra/engine/tests/test_shelltask_inputspec.py::test_shell_cmd_inputs_template_7 - AssertionError: assert ('executable '\n '/net/vast-storage.ib.cluster/scratch/Thu/nlo...
FAILED pydra/engine/tests/test_shelltask_inputspec.py::test_shell_cmd_inputs_template_7a - AssertionError: assert ('executable '\n '/net/vast-storage.ib.cluster/scratch/Thu/nl...
FAILED pydra/engine/tests/test_shelltask_inputspec.py::test_shell_cmd_inputs_template_7b - AssertionError: assert ('executable '\n '/net/vast-storage.ib.cluster/scratch/Thu/nl...
FAILED pydra/engine/tests/test_shelltask_inputspec.py::test_shell_cmd_inputs_template_8 - AssertionError: assert ('executable '\n '/net/vast-storage.ib.cluster/scratch/Thu/nlo...
FAILED pydra/engine/tests/test_shelltask_inputspec.py::test_shell_cmd_inputs_di - AssertionError: assert ('DenoiseImage -i '\n '/net/vast-storage.ib.cluster/scratch/Thu/nlo/tm..
Sample error code:
_______________________________________________________________________ test_shell_cmd_inputs_template_7b ________________________________________________________________________
tmpdir = local('/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_template2')
def test_shell_cmd_inputs_template_7b(tmpdir):
""" additional inputs uses output_file_template with a suffix (no extension)
keep extension is False (so the extension is removed when creating the output)
"""
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"inpA",
attr.ib(
type=File,
metadata={
"position": 1,
"help_string": "inpA",
"argstr": "",
"mandatory": True,
},
),
),
(
"outA",
attr.ib(
type=str,
metadata={
"position": 2,
"help_string": "outA",
"argstr": "",
"keep_extension": False,
"output_file_template": "{inpA}_out",
},
),
),
],
bases=(ShellSpec,),
)
inpA_file = tmpdir.join("a_file.txt")
inpA_file.write("content")
shelly = ShellCommandTask(
executable="executable", input_spec=my_input_spec, inpA=inpA_file
)
# outA should be formatted in a way that that .txt goes to the end
> assert (
shelly.cmdline
== f"executable {tmpdir.join('a_file.txt')} {str(shelly.output_dir / 'a_file_out')}"
)
E AssertionError: assert ('executable '\n '/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_template2/a_file.txt '\n '/tmp/tmp0b_yq0ba/ShellCommandTask_667f839bced051cf9f8f00a8f4dfc7ec7e46e838d2778d9c6f47f47db3ef0860/vast-storage_out') == ('executable '\n '/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_template2/a_file.txt '\n '/tmp/tmp0b_yq0ba/ShellCommandTask_667f839bced051cf9f8f00a8f4dfc7ec7e46e838d2778d9c6f47f47db3ef0860/a_file_out')
E - executable /net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_template2/a_file.txt /tmp/tmp0b_yq0ba/ShellCommandTask_667f839bced051cf9f8f00a8f4dfc7ec7e46e838d2778d9c6f47f47db3ef0860/a_file_out
E ? ^^^^^^^^^^
E + executable /net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_template2/a_file.txt /tmp/tmp0b_yq0ba/ShellCommandTask_667f839bced051cf9f8f00a8f4dfc7ec7e46e838d2778d9c6f47f47db3ef0860/vast-storage_out
E ? ^^^^^^^^^^^^^^^^
pydra/engine/tests/test_shelltask_inputspec.py:1178: AssertionError
________________________________________________________________________ test_shell_cmd_inputs_template_8 ________________________________________________________________________
tmpdir = local('/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_template3')
def test_shell_cmd_inputs_template_8(tmpdir):
"""additional inputs uses output_file_template with a suffix and an extension"""
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"inpA",
attr.ib(
type=File,
metadata={
"position": 1,
"help_string": "inpA",
"argstr": "",
"mandatory": True,
},
),
),
(
"outA",
attr.ib(
type=str,
metadata={
"position": 2,
"help_string": "outA",
"argstr": "",
"output_file_template": "{inpA}_out.txt",
},
),
),
],
bases=(ShellSpec,),
)
inpA_file = tmpdir.join("a_file.t")
inpA_file.write("content")
shelly = ShellCommandTask(
executable="executable", input_spec=my_input_spec, inpA=inpA_file
)
# outA should be formatted in a way that inpA extension is removed and the template extension is used
> assert (
shelly.cmdline
== f"executable {tmpdir.join('a_file.t')} {str(shelly.output_dir / 'a_file_out.txt')}"
)
E AssertionError: assert ('executable '\n '/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_template3/a_file.t '\n '/tmp/tmp92b2a_ex/ShellCommandTask_667f839bced051cf9f8f00a8f4dfc7ec7e46e838d2778d9c6f47f47db3ef0860/vast-storage_out.txt') == ('executable '\n '/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_template3/a_file.t '\n '/tmp/tmp92b2a_ex/ShellCommandTask_667f839bced051cf9f8f00a8f4dfc7ec7e46e838d2778d9c6f47f47db3ef0860/a_file_out.txt')
E - executable /net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_template3/a_file.t /tmp/tmp92b2a_ex/ShellCommandTask_667f839bced051cf9f8f00a8f4dfc7ec7e46e838d2778d9c6f47f47db3ef0860/a_file_out.txt
E ? ^^^^^
E + executable /net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_template3/a_file.t /tmp/tmp92b2a_ex/ShellCommandTask_667f839bced051cf9f8f00a8f4dfc7ec7e46e838d2778d9c6f47f47db3ef0860/vast-storage_out.txt
E ? ^^^^^^^^^^^
pydra/engine/tests/test_shelltask_inputspec.py:1224: AssertionError
____________________________________________________________________________ test_shell_cmd_inputs_di ____________________________________________________________________________
tmpdir = local('/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_di0'), use_validator = None
def test_shell_cmd_inputs_di(tmpdir, use_validator):
""" example from #279 """
my_input_spec = SpecInfo(
name="Input",
fields=[
(
"image_dimensionality",
attr.ib(
type=int,
metadata={
"help_string": """
2/3/4
This option forces the image to be treated as a specified-dimensional image.
If not specified, the program tries to infer the dimensionality from
the input image.
""",
"allowed_values": [2, 3, 4],
"argstr": "-d",
},
),
),
(
"inputImageFilename",
attr.ib(
type=File,
metadata={
"help_string": "A scalar image is expected as input for noise correction.",
"argstr": "-i",
"mandatory": True,
},
),
),
(
"noise_model",
attr.ib(
type=str,
metadata={
"help_string": """
Rician/(Gaussian)
Employ a Rician or Gaussian noise model.
""",
"allowed_values": ["Rician", "Gaussian"],
"argstr": "-n",
},
),
),
(
"maskImageFilename",
attr.ib(
type=str,
metadata={
"help_string": "If a mask image is specified, denoising is only performed in the mask region.",
"argstr": "-x",
},
),
),
(
"shrink_factor",
attr.ib(
type=int,
default=1,
metadata={
"help_string": """
(1)/2/3/...
Running noise correction on large images can be time consuming.
To lessen computation time, the input image can be resampled.
The shrink factor, specified as a single integer, describes this
resampling. Shrink factor = 1 is the default.
""",
"argstr": "-s",
},
),
),
(
"patch_radius",
attr.ib(
type=int,
default=1,
metadata={
"help_string": "Patch radius. Default = 1x1x1",
"argstr": "-p",
},
),
),
(
"search_radius",
attr.ib(
type=int,
default=2,
metadata={
"help_string": "Search radius. Default = 2x2x2.",
"argstr": "-r",
},
),
),
(
"correctedImage",
attr.ib(
type=str,
metadata={
"help_string": """
The output consists of the noise corrected version of the input image.
Optionally, one can also output the estimated noise image.
""",
"output_file_template": "{inputImageFilename}_out",
},
),
),
(
"noiseImage",
attr.ib(
type=ty.Union[str, bool],
default=False,
metadata={
"help_string": """
The output consists of the noise corrected version of the input image.
Optionally, one can also output the estimated noise image.
""",
"output_file_template": "{inputImageFilename}_noise",
},
),
),
(
"output",
attr.ib(
type=str,
metadata={
"help_string": "Combined output",
"argstr": "-o [{correctedImage}, {noiseImage}]",
"position": -1,
"readonly": True,
},
),
),
(
"version",
attr.ib(
type=bool,
default=False,
metadata={
"help_string": "Get Version Information.",
"argstr": "--version",
},
),
),
(
"verbose",
attr.ib(
type=int,
default=0,
metadata={"help_string": "(0)/1. Verbose output. ", "argstr": "-v"},
),
),
(
"help_short",
attr.ib(
type=bool,
default=False,
metadata={
"help_string": "Print the help menu (short version)",
"argstr": "-h",
},
),
),
(
"help",
attr.ib(
type=int,
metadata={
"help_string": "Print the help menu.",
"argstr": "--help",
},
),
),
],
bases=(ShellSpec,),
)
my_input_file = tmpdir.join("a_file.ext")
my_input_file.write("content")
# no input provided
shelly = ShellCommandTask(executable="DenoiseImage", input_spec=my_input_spec)
with pytest.raises(Exception) as e:
shelly.cmdline
assert "mandatory" in str(e.value)
# input file name, noiseImage is not set, so using default value False
shelly = ShellCommandTask(
executable="DenoiseImage",
inputImageFilename=my_input_file,
input_spec=my_input_spec,
)
> assert (
shelly.cmdline
== f"DenoiseImage -i {tmpdir.join('a_file.ext')} -s 1 -p 1 -r 2 -o [{str(shelly.output_dir / 'a_file_out.ext')}]"
)
E AssertionError: assert ('DenoiseImage -i '\n '/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_di0/a_file.ext '\n '-s 1 -p 1 -r 2 -o '\n '[/tmp/tmp94sb2fnv/ShellCommandTask_73e97c2e37db10b0beab1524ba6041f9729fab3f4fa509464aede51b4105fd84/a_file.ext]') == ('DenoiseImage -i '\n '/net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_di0/a_file.ext '\n '-s 1 -p 1 -r 2 -o '\n '[/tmp/tmp94sb2fnv/ShellCommandTask_73e97c2e37db10b0beab1524ba6041f9729fab3f4fa509464aede51b4105fd84/a_file_out.ext]')
E - DenoiseImage -i /net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_di0/a_file.ext -s 1 -p 1 -r 2 -o [/tmp/tmp94sb2fnv/ShellCommandTask_73e97c2e37db10b0beab1524ba6041f9729fab3f4fa509464aede51b4105fd84/a_file_out.ext]
E ? ----
E + DenoiseImage -i /net/vast-storage.ib.cluster/scratch/Thu/nlo/tmpdir2/test_shell_cmd_inputs_di0/a_file.ext -s 1 -p 1 -r 2 -o [/tmp/tmp94sb2fnv/ShellCommandTask_73e97c2e37db10b0beab1524ba6041f9729fab3f4fa509464aede51b4105fd84/a_file.ext]
pydra/engine/tests/test_shelltask_inputspec.py:1424: AssertionError
I'm not completely sure if all the test have the same issue. Could you debug it a bit?
I'd start from testing the cmdline
first
Currently many pydra tests that doesn't specify cache dirs fail on Openmind. The github actions SLURM CI runs in a docker container which assumes everything runs on one node, which is not the case with distributed SLURM clusters. Adding
tmpdir
to tests helps with debugging