Skip to content

Commit

Permalink
_env just needs to be a Mapping. Fixes #527
Browse files Browse the repository at this point in the history
  • Loading branch information
EKC (Erik Cederstrand) committed May 12, 2020
1 parent fc06f41 commit fa4b1e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 3 additions & 4 deletions sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import tempfile
import warnings
import stat
from collections import deque
from collections import deque, Mapping
import glob as glob_module
import ast
from contextlib import contextmanager
Expand Down Expand Up @@ -110,7 +110,6 @@ def callable(ob):
import fcntl
import struct
import resource
from collections import deque
import logging
import weakref

Expand Down Expand Up @@ -1146,8 +1145,8 @@ def env_validator(passed_kwargs, merged_kwargs):
if env is None:
return invalid

if not isinstance(env, dict):
invalid.append(("env", "env must be a dict. Got {!r}".format(env)))
if not isinstance(env, Mapping):
invalid.append(("env", "env must be dict-like. Got {!r}".format(env)))
return invalid

for k, v in passed_kwargs["env"].items():
Expand Down
5 changes: 5 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@ def test_environment(self):
out = python(py.name, _env=env, _cwd=THIS_DIR).strip()
self.assertEqual(out, "{'HERP': 'DERP'}")

# Test that _env also accepts os.environ which is a mpping but not a dict.
os.environ["HERP"] = "DERP"
out = python(py.name, _env=os.environ, _cwd=THIS_DIR).strip()
self.assertEqual(out, "{'HERP': 'DERP'}")


def test_which(self):
from sh import which, ls
Expand Down

0 comments on commit fa4b1e3

Please sign in to comment.