Skip to content

Commit cc9efc0

Browse files
committed
improve tests
1 parent 4ef9111 commit cc9efc0

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

Diff for: tests/echo-stderr.cwl

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: v1.0
3+
class: CommandLineTool
4+
inputs:
5+
message: string
6+
outputs:
7+
out:
8+
type: string
9+
outputBinding:
10+
glob: out.txt
11+
loadContents: true
12+
outputEval: $(self[0].contents)
13+
baseCommand: bash
14+
stderr: out.txt
15+
arguments:
16+
- "-c"
17+
- "echo $(inputs.message) 1>&2"

Diff for: tests/test_stdout_stderr_log_dir.py

+38-7
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ def test_log_dir_echo_output(tmp_path: Path) -> None:
1313
)
1414
assert "completed success" in stderr, stderr
1515
assert json.loads(stdout)["out"].strip("\n") == "hello"
16-
# and then check in `tmp_path` that there is no stdout log file, since `echo.cwl` uses `stdout` itself.
17-
# should there be an empty stderr log, though?
16+
assert len(list(tmp_path.iterdir())) == 1
17+
subdir = next(tmp_path.iterdir())
18+
assert subdir.is_dir()
19+
assert len(list(subdir.iterdir())) == 1
20+
result = next(subdir.iterdir())
21+
assert result.name == "out.txt"
22+
output = open(result).read()
23+
assert output == "hello\n"
1824

1925

2026
def test_log_dir_echo_no_output(tmp_path: Path) -> None:
@@ -27,8 +33,33 @@ def test_log_dir_echo_no_output(tmp_path: Path) -> None:
2733
"hello",
2834
]
2935
)
30-
for dir in os.listdir(tmp_path):
31-
for file in os.listdir(f"{tmp_path}/{dir}"):
32-
assert file == "out.txt"
33-
output = open(f"{tmp_path}/{dir}/{file}", "r").read()
34-
assert "hello" in output
36+
assert len(list(tmp_path.iterdir())) == 1
37+
subdir = next(tmp_path.iterdir())
38+
assert subdir.name == "echo"
39+
assert subdir.is_dir()
40+
assert len(list(subdir.iterdir())) == 1
41+
result = next(subdir.iterdir())
42+
assert result.name == "out.txt"
43+
output = open(result).read()
44+
assert output == "hello\n"
45+
46+
47+
def test_log_dir_echo_stderr(tmp_path: Path) -> None:
48+
_, stdout, stderr = get_main_output(
49+
[
50+
"--log-dir",
51+
str(tmp_path),
52+
get_data("tests/echo-stderr.cwl"),
53+
"--message",
54+
"hello",
55+
]
56+
)
57+
assert len(list(tmp_path.iterdir())) == 1
58+
subdir = next(tmp_path.iterdir())
59+
assert subdir.name == "echo-stderr.cwl"
60+
assert subdir.is_dir()
61+
assert len(list(subdir.iterdir())) == 1
62+
result = next(subdir.iterdir())
63+
assert result.name == "out.txt"
64+
output = open(result).read()
65+
assert output == "hello\n"

0 commit comments

Comments
 (0)