Create a ``Context``-like object whose methods yield `.Result` objects. :param config: A Configuration object to use. Identical in behavior to `.Context`. :param run: A data structure indicating what `.Result` objects to return from call
(self, config: Optional[Config] = None, **kwargs: Any)
| 433 | """ |
| 434 | |
| 435 | def __init__(self, config: Optional[Config] = None, **kwargs: Any) -> None: |
| 436 | """ |
| 437 | Create a ``Context``-like object whose methods yield `.Result` objects. |
| 438 | |
| 439 | :param config: |
| 440 | A Configuration object to use. Identical in behavior to `.Context`. |
| 441 | |
| 442 | :param run: |
| 443 | A data structure indicating what `.Result` objects to return from |
| 444 | calls to the instantiated object's `~.Context.run` method (instead |
| 445 | of actually executing the requested shell command). |
| 446 | |
| 447 | Specifically, this kwarg accepts: |
| 448 | |
| 449 | - A single `.Result` object. |
| 450 | - A boolean; if True, yields a `.Result` whose ``exited`` is ``0``, |
| 451 | and if False, ``1``. |
| 452 | - An iterable of the above values, which will be returned on each |
| 453 | subsequent call to ``.run`` (the first item on the first call, |
| 454 | the second on the second call, etc). |
| 455 | - A dict mapping command strings or compiled regexen to the above |
| 456 | values (including an iterable), allowing specific |
| 457 | call-and-response semantics instead of assuming a call order. |
| 458 | |
| 459 | :param sudo: |
| 460 | Identical to ``run``, but whose values are yielded from calls to |
| 461 | `~.Context.sudo`. |
| 462 | |
| 463 | :param bool repeat: |
| 464 | A flag determining whether results yielded by this class' methods |
| 465 | repeat or are consumed. |
| 466 | |
| 467 | For example, when a single result is indicated, it will normally |
| 468 | only be returned once, causing ``NotImplementedError`` afterwards. |
| 469 | But when ``repeat=True`` is given, that result is returned on |
| 470 | every call, forever. |
| 471 | |
| 472 | Similarly, iterable results are normally exhausted once, but when |
| 473 | this setting is enabled, they are wrapped in `itertools.cycle`. |
| 474 | |
| 475 | Default: ``True``. |
| 476 | |
| 477 | :raises: |
| 478 | ``TypeError``, if the values given to ``run`` or other kwargs |
| 479 | aren't of the expected types. |
| 480 | |
| 481 | .. versionchanged:: 1.5 |
| 482 | Added support for boolean and string result values. |
| 483 | .. versionchanged:: 1.5 |
| 484 | Added support for regex dict keys. |
| 485 | .. versionchanged:: 1.5 |
| 486 | Added the ``repeat`` keyword argument. |
| 487 | .. versionchanged:: 2.0 |
| 488 | Changed ``repeat`` default value from ``False`` to ``True``. |
| 489 | """ |
| 490 | # Set up like any other Context would, with the config |
| 491 | super().__init__(config) |
| 492 | # Pull out behavioral kwargs |
nothing calls this directly
no test coverage detected