| 1 |
import re |
| 2 |
from unittest.mock import patch |
| 3 |
|
| 4 |
import invoke |
| 5 |
import invoke.collection |
| 6 |
import invoke.exceptions |
| 7 |
import invoke.program |
| 8 |
import invoke.tasks |
| 9 |
|
| 10 |
|
| 11 |
class Init: |
| 12 |
"__init__" |
| 13 |
|
| 14 |
def dunder_version(self): |
| 15 |
assert hasattr(invoke, "__version__") |
| 16 |
ver = invoke.__version__ |
| 17 |
assert isinstance(ver, str) |
| 18 |
assert re.match(r"\d+\.\d+\.\d+", ver) |
| 19 |
|
| 20 |
class exposes_bindings: |
| 21 |
def task_decorator(self): |
| 22 |
assert invoke.task is invoke.tasks.task |
| 23 |
|
| 24 |
def task_class(self): |
| 25 |
assert invoke.Task is invoke.tasks.Task |
| 26 |
|
| 27 |
def collection_class(self): |
| 28 |
assert invoke.Collection is invoke.collection.Collection |
| 29 |
|
| 30 |
def context_class(self): |
| 31 |
assert invoke.Context is invoke.context.Context |
| 32 |
|
| 33 |
def mock_context_class(self): |
| 34 |
assert invoke.MockContext is invoke.context.MockContext |
| 35 |
|
| 36 |
def config_class(self): |
| 37 |
assert invoke.Config is invoke.config.Config |
| 38 |
|
| 39 |
def pty_size_function(self): |
| 40 |
assert invoke.pty_size is invoke.terminals.pty_size |
| 41 |
|
| 42 |
def local_class(self): |
| 43 |
assert invoke.Local is invoke.runners.Local |
| 44 |
|
| 45 |
def runner_class(self): |
| 46 |
assert invoke.Runner is invoke.runners.Runner |
| 47 |
|
| 48 |
def promise_class(self): |
| 49 |
assert invoke.Promise is invoke.runners.Promise |
| 50 |
|
| 51 |
def failure_class(self): |
| 52 |
assert invoke.Failure is invoke.runners.Failure |
| 53 |
|
| 54 |
def exceptions(self): |
| 55 |
# Meh |
| 56 |
for obj in vars(invoke.exceptions).values(): |
| 57 |
if isinstance(obj, type) and issubclass(obj, BaseException): |
| 58 |
top_level = getattr(invoke, obj.__name__) |
| 59 |
real = getattr(invoke.exceptions, obj.__name__) |
| 60 |
assert top_level is real |
| 61 |
|
| 62 |
def runner_result(self): |
| 63 |
assert invoke.Result is invoke.runners.Result |
| 64 |
|
| 65 |
def watchers(self): |
| 66 |
assert invoke.StreamWatcher is invoke.watchers.StreamWatcher |
| 67 |
assert invoke.Responder is invoke.watchers.Responder |
| 68 |
assert invoke.FailingResponder is invoke.watchers.FailingResponder |
| 69 |
|
| 70 |
def program(self): |
| 71 |
assert invoke.Program is invoke.program.Program |
| 72 |
|
| 73 |
def filesystemloader(self): |
| 74 |
assert invoke.FilesystemLoader is invoke.loader.FilesystemLoader |
| 75 |
|
| 76 |
def argument(self): |
| 77 |
assert invoke.Argument is invoke.parser.Argument |
| 78 |
|
| 79 |
def parsercontext(self): |
| 80 |
assert invoke.ParserContext is invoke.parser.ParserContext |
| 81 |
|
| 82 |
def parser(self): |
| 83 |
assert invoke.Parser is invoke.parser.Parser |
| 84 |
|
| 85 |
def parseresult(self): |
| 86 |
assert invoke.ParseResult is invoke.parser.ParseResult |
| 87 |
|
| 88 |
def executor(self): |
| 89 |
assert invoke.Executor is invoke.executor.Executor |
| 90 |
|
| 91 |
def call(self): |
| 92 |
assert invoke.call is invoke.tasks.call |
| 93 |
|
| 94 |
def Call(self): |
| 95 |
# Starting to think we shouldn't bother with lowercase-c call... |
| 96 |
assert invoke.Call is invoke.tasks.Call |
| 97 |
|
| 98 |
class offers_singletons: |
| 99 |
@patch("invoke.Context") |
| 100 |
def run(self, Context): |
| 101 |
result = invoke.run("foo", bar="biz") |
| 102 |
ctx = Context.return_value |
| 103 |
ctx.run.assert_called_once_with("foo", bar="biz") |
| 104 |
assert result is ctx.run.return_value |
| 105 |
|
| 106 |
@patch("invoke.Context") |
| 107 |
def sudo(self, Context): |
| 108 |
result = invoke.sudo("foo", bar="biz") |
| 109 |
ctx = Context.return_value |
| 110 |
ctx.sudo.assert_called_once_with("foo", bar="biz") |
| 111 |
assert result is ctx.sudo.return_value |