22import subprocess as sp
33import pytest
44import attr
5-
6- from ..task import ShellDef
75from ..submitter import Submitter
8- from ..specs import ShellOutputs , ShellDef
6+ from ..specs import ShellOutputs
7+ from pydra .design import shell
98from fileformats .generic import File
109from ..environments import Singularity
1110
@@ -30,19 +29,11 @@ def test_singularity_1_nosubm(tmp_path):
3029 """
3130 cmd = "pwd"
3231 image = "docker://alpine"
33- singu = ShellDef (
34- name = "singu" ,
35- executable = cmd ,
36- environment = Singularity (image = image ),
37- cache_dir = tmp_path ,
38- )
39- assert singu .environment .image == "docker://alpine"
40- assert isinstance (singu .environment , Singularity )
41- assert singu .cmdline == cmd
42-
43- res = singu ()
44- assert "/mnt/pydra" in res .output .stdout
45- assert res .output .return_code == 0
32+ Singu = shell .define (cmd )
33+ singu = Singu ()
34+ outputs = singu (environment = Singularity (image = image ), cache_dir = tmp_path )
35+ assert "/mnt/pydra" in outputs .stdout
36+ assert outputs .return_code == 0
4637
4738
4839@need_singularity
@@ -52,17 +43,16 @@ def test_singularity_2_nosubm(tmp_path):
5243 """
5344 cmd = ["echo" , "hail" , "pydra" ]
5445 image = "docker://alpine"
55- singu = ShellDef (
56- name = "singu" ,
57- executable = cmd ,
58- environment = Singularity (image = image ),
59- cache_dir = tmp_path ,
60- )
46+ Singu = shell .define (" " .join (cmd ))
47+ singu = Singu ()
6148 assert singu .cmdline == " " .join (cmd )
6249
63- res = singu ()
64- assert res .output .stdout .strip () == " " .join (cmd [1 :])
65- assert res .output .return_code == 0
50+ outputs = singu (
51+ Singularity (image = image ),
52+ cache_dir = tmp_path ,
53+ )
54+ assert outputs .stdout .strip () == " " .join (cmd [1 :])
55+ assert outputs .return_code == 0
6656
6757
6858@need_singularity
@@ -72,20 +62,17 @@ def test_singularity_2(plugin, tmp_path):
7262 """
7363 cmd = ["echo" , "hail" , "pydra" ]
7464 image = "docker://alpine"
65+ Singu = shell .define (" " .join (cmd ))
66+ singu = Singu ()
7567
76- singu = ShellDef (
77- name = "singu" ,
78- executable = cmd ,
79- environment = Singularity (image = image ),
80- cache_dir = tmp_path ,
81- )
8268 assert singu .cmdline == " " .join (cmd )
8369
84- with Submitter (worker = plugin ) as sub :
85- singu (submitter = sub )
86- res = singu .result ()
87- assert res .output .stdout .strip () == " " .join (cmd [1 :])
88- assert res .output .return_code == 0
70+ with Submitter (
71+ worker = plugin , environment = Singularity (image = image ), cache_dir = tmp_path
72+ ) as sub :
73+ res = sub (singu )
74+ assert res .outputs .stdout .strip () == " " .join (cmd [1 :])
75+ assert res .outputs .return_code == 0
8976
9077
9178@need_singularity
@@ -97,20 +84,19 @@ def test_singularity_2a(plugin, tmp_path):
9784 cmd_args = ["hail" , "pydra" ]
9885 # separate command into exec + args
9986 image = "docker://alpine"
100- singu = ShellDef (
101- name = "singu" ,
102- executable = cmd_exec ,
103- args = cmd_args ,
87+ Singu = shell .define (cmd_exec )
88+ singu = Singu (additional_args = cmd_args )
89+ assert singu .cmdline == f"{ cmd_exec } { ' ' .join (cmd_args )} "
90+
91+ with Submitter (
92+ worker = plugin ,
10493 environment = Singularity (image = image ),
10594 cache_dir = tmp_path ,
106- )
107- assert singu . cmdline == f" { cmd_exec } { ' ' . join ( cmd_args ) } "
95+ ) as sub :
96+ res = sub ( singu )
10897
109- with Submitter (worker = plugin ) as sub :
110- singu (submitter = sub )
111- res = singu .result ()
112- assert res .output .stdout .strip () == " " .join (cmd_args )
113- assert res .output .return_code == 0
98+ assert res .outputs .stdout .strip () == " " .join (cmd_args )
99+ assert res .outputs .return_code == 0
114100
115101
116102# tests with State
@@ -123,15 +109,15 @@ def test_singularity_st_1(plugin, tmp_path):
123109 """
124110 cmd = ["pwd" , "ls" ]
125111 image = "docker://alpine"
126- singu = ShellDef (
127- name = "singu" , environment = Singularity (image = image ), cache_dir = tmp_path
128- ).split ("executable" , executable = cmd )
129- assert singu .state .splitter == "singu.executable"
112+ Singu = shell .define ("dummy" )
113+ singu = Singu ().split ("executable" , executable = cmd )
130114
131- res = singu (plugin = plugin )
132- assert "/mnt/pydra" in res [0 ].output .stdout
133- assert res [1 ].output .stdout == ""
134- assert res [0 ].output .return_code == res [1 ].output .return_code == 0
115+ outputs = singu (
116+ plugin = plugin , environment = Singularity (image = image ), cache_dir = tmp_path
117+ )
118+ assert outputs .stdout [0 ] == "/mnt/pydra"
119+ assert outputs .stdout [1 ] == ""
120+ assert outputs .return_code == [0 , 0 ]
135121
136122
137123@need_singularity
0 commit comments