diff --git a/src/wxflow/__init__.py b/src/wxflow/__init__.py index 1f9efa3..f85da17 100644 --- a/src/wxflow/__init__.py +++ b/src/wxflow/__init__.py @@ -4,7 +4,7 @@ from .configuration import (Configuration, cast_as_dtype, cast_strdict_as_dtypedict) from .exceptions import WorkflowException, msg_except_handle -from .executable import CommandNotFoundError, Executable, which +from .executable import CommandNotFoundError, Executable, ProcessError, which from .factory import Factory from .file_utils import FileHandler from .fsutils import chdir, cp, mkdir, mkdir_p, rm_p, rmdir diff --git a/src/wxflow/executable.py b/src/wxflow/executable.py index b2e2388..f1ce0c7 100644 --- a/src/wxflow/executable.py +++ b/src/wxflow/executable.py @@ -4,7 +4,7 @@ import sys from typing import Any, List, Optional, Union -__all__ = ["Executable", "which", "CommandNotFoundError"] +__all__ = ["Executable", "which", "CommandNotFoundError", "ProcessError"] class Executable: diff --git a/tests/test_executable.py b/tests/test_executable.py index d137114..2bb734e 100644 --- a/tests/test_executable.py +++ b/tests/test_executable.py @@ -3,7 +3,7 @@ import pytest -from wxflow import CommandNotFoundError, Executable, which +from wxflow import CommandNotFoundError, Executable, ProcessError, which script = """#!/bin/bash echo ${USER} @@ -59,3 +59,31 @@ def test_which(tmpdir): exe = which("test.x") assert exe is not None assert exe.path == path + + +def test_stderr(tmp_path): + """ + Tests the `stderr` attribute of the `Executable` class + """ + + os.environ["PATH"] = "/usr/bin:/bin" + + cmd = which("ls", required=True) + + stdout_file = tmp_path / 'stdout' + stderr_file = tmp_path / 'stderr' + cmd("--myopt", output=str(stdout_file), error=str(stderr_file), fail_on_error=False) + + # Assert there is no stdout + with open(str(stdout_file)) as fh: + assert fh.read() == '' + + # Assert stderr is not empty, '--help' is an unrecognized option + with open(str(stderr_file)) as fh: + stderr = fh.read() + assert stderr != '' + print(stderr) + # Depending on the OS, the error message may vary + # This was seen on macOS + # assert stderr == "ls: unrecognized option `--myopt'" + '\n' + \ + # "usage: ls [-@ABCFGHILOPRSTUWabcdefghiklmnopqrstuvwxy1%,] [--color=when] [-D format] [file ...]" + '\n'