summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2019-12-03 10:29:18 -0500
committerJeff Forcier <jeff@bitprophet.org>2019-12-03 10:50:46 -0500
commit1919964110333aa91df3e33424b763384bea127f (patch)
treeb8f2c51122707e018c05399820c89f90a9859931
parent6da063a1c9cdade5cd64675ecfe2cdfb5e8b17f7 (diff)
Never actually handled optional-ness of Invoke import
Was just silently failing, wahoops
-rw-r--r--paramiko/config.py4
-rw-r--r--tests/test_config.py9
2 files changed, 13 insertions, 0 deletions
diff --git a/paramiko/config.py b/paramiko/config.py
index e6663b71..bef42610 100644
--- a/paramiko/config.py
+++ b/paramiko/config.py
@@ -380,6 +380,10 @@ class SSHConfig(object):
exec_cmd = self._tokenize(
options, target_hostname, "match-exec", param
)
+ # This is the laziest spot in which we can get mad about an
+ # inability to import Invoke.
+ if invoke is None:
+ raise invoke_import_error
# Like OpenSSH, we 'redirect' stdout but let stderr bubble up
passed = invoke.run(exec_cmd, hide="stdout", warn=True).ok
# Tackle any 'passed, but was negated' results from above
diff --git a/tests/test_config.py b/tests/test_config.py
index 16f09c48..7c86667a 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -702,6 +702,15 @@ def _expect(success_on):
class TestMatchExec(object):
+ @patch("paramiko.config.invoke", new=None)
+ @patch("paramiko.config.invoke_import_error", new=ImportError("meh"))
+ def test_raises_invoke_ImportErrors_at_runtime(self):
+ # Not an ideal test, but I don't know of a non-bad way to fake out
+ # module-time ImportErrors. So we mock the symptoms. Meh!
+ with raises(ImportError) as info:
+ load_config("match-exec").lookup("oh-noes")
+ assert str(info.value) == "meh"
+
@patch("paramiko.config.invoke.run")
@mark.parametrize(
"cmd,user",