Skip to content

Commit 1f9e0df

Browse files
committed
starting to convert test_environments tests to new syntax
1 parent d306431 commit 1f9e0df

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

pydra/engine/tests/test_environments.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
2+
import typing as ty
33
from ..environments import Native, Docker, Singularity
44
from ..task import ShellDef
55
from ..submitter import Submitter
@@ -17,34 +17,37 @@ def makedir(path, name):
1717
return newdir
1818

1919

20+
def drop_stderr(dct: dict[str, ty.Any]):
21+
return {k: v for k, v in dct.items() if k != "stderror"}
22+
23+
2024
def test_native_1(tmp_path):
2125
"""simple command, no arguments"""
2226

2327
def newcache(x):
2428
return makedir(tmp_path, x)
2529

2630
cmd = "whoami"
27-
ShellDef = shell.define(cmd)
28-
29-
shelly = ShellDef()
31+
Shelly = shell.define(cmd)
32+
shelly = Shelly()
3033
assert shelly.cmdline == cmd
31-
shelly_task = Task(
34+
35+
shelly_job = Task(
3236
definition=shelly,
3337
submitter=Submitter(cache_dir=newcache("shelly-task")),
3438
name="shelly",
3539
)
40+
env_outputs = Native().execute(shelly_job)
3641

37-
# Up to here
38-
env_outputs = Native().execute(shelly_task)
3942
outputs = shelly(cache_dir=newcache("shelly-exec"))
40-
assert env_outputs == attrs_values(outputs)
43+
assert drop_stderr(env_outputs) == drop_stderr(attrs_values(outputs))
4144

4245
outputs = shelly(environment=Native())
4346
assert env_outputs == attrs_values(outputs)
4447

4548
with Submitter(cache_dir=newcache("shelly-submitter"), environment=Native()) as sub:
4649
result = sub(shelly)
47-
assert env_outputs == attrs_values(result.outputs)
50+
assert drop_stderr(env_outputs) == drop_stderr(attrs_values(result.outputs))
4851

4952

5053
@no_win
@@ -57,14 +60,16 @@ def newcache(x):
5760

5861
cmd = ["whoami"]
5962
docker = Docker(image="busybox")
60-
shell_def = shell.define(cmd)
61-
shelly = Task(
62-
definition=shell_def,
63+
Shelly = shell.define(cmd)
64+
shelly = Shelly()
65+
assert shelly.cmdline == " ".join(cmd)
66+
67+
shelly_job = Task(
68+
definition=shelly,
6369
submitter=Submitter(cache_dir=newcache("shelly")),
6470
name="shelly",
6571
)
66-
assert shell_def.cmdline == " ".join(cmd)
67-
env_res = docker.execute(shelly)
72+
env_res = docker.execute(shelly_job)
6873

6974
shelly_env = ShellDef(
7075
name="shelly",
@@ -100,24 +105,20 @@ def newcache(x):
100105

101106
cmd = "whoami"
102107
docker = Docker(image="busybox")
103-
shell_def = shell.define(cmd)()
104-
shelly = Task(
105-
definition=shell_def,
108+
shelly = shell.define(cmd)()
109+
shelly_job = Task(
110+
definition=shelly,
106111
submitter=Submitter(cache_dir=newcache("shelly")),
107112
name="shelly",
108113
)
109-
assert shell_def.cmdline == cmd
110-
env_res = docker.execute(shelly)
114+
assert shelly.cmdline == cmd
115+
env_res = docker.execute(shelly_job)
111116

112-
shelly_env = ShellDef(
113-
name="shelly",
114-
executable=cmd,
115-
cache_dir=newcache("shelly_env"),
116-
environment=docker,
117-
)
118-
with Submitter(worker="cf") as sub:
119-
shelly_env(submitter=sub)
120-
assert env_res == shelly_env.result().output.__dict__
117+
with Submitter(
118+
worker="cf", cache_dir=newcache("shelly_env"), environment=docker
119+
) as sub:
120+
result = sub(shelly)
121+
assert env_res == attrs_values(result.outputs)
121122

122123
shelly_call = ShellDef(
123124
name="shelly", executable=cmd, cache_dir=newcache("shelly_call")

0 commit comments

Comments
 (0)