Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test to demonstrate issue 13 is not an issue #20

Merged
merged 7 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wxflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/wxflow/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from typing import Any, List, Optional, Union

__all__ = ["Executable", "which", "CommandNotFoundError"]
__all__ = ["Executable", "which", "CommandNotFoundError", "ProcessError"]


class Executable:
Expand Down
30 changes: 29 additions & 1 deletion tests/test_executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from wxflow import CommandNotFoundError, Executable, which
from wxflow import CommandNotFoundError, Executable, ProcessError, which

script = """#!/bin/bash
echo ${USER}
Expand Down Expand Up @@ -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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is a planned future test, but if so, the Python string library provides an easy way to define alphabet strings (see the RTDs). Other than that, approved.