refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
from __future__ import annotations
|
2022-02-07 17:11:43 +00:00
|
|
|
|
|
|
|
import click.testing
|
|
|
|
|
|
|
|
from tests.helpers import TestContext, temporary_root
|
|
|
|
from tutor.commands.cli import cli
|
|
|
|
|
|
|
|
|
|
|
|
class TestCommandMixin:
|
|
|
|
"""
|
|
|
|
Run CLI tests in an isolated test root.
|
|
|
|
"""
|
|
|
|
|
|
|
|
@staticmethod
|
refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
def invoke(args: list[str]) -> click.testing.Result:
|
2022-02-07 17:11:43 +00:00
|
|
|
with temporary_root() as root:
|
|
|
|
return TestCommandMixin.invoke_in_root(root, args)
|
|
|
|
|
|
|
|
@staticmethod
|
2022-10-19 15:46:31 +00:00
|
|
|
def invoke_in_root(
|
refactor: annotation with __future__.annotations
Adds `from __future__ import annotations` to the top of every module,
right below the module's docstring. Replaces any usages of t.List,
t.Dict, t.Set, t.Tuple, and t.Type with their built-in equivalents:
list, dict, set, tuple, and type. Ensures that make test still passes
under Python 3.7, 3.8 and 3.9.
2023-01-17 18:57:23 +00:00
|
|
|
root: str, args: list[str], catch_exceptions: bool = True
|
2022-10-19 15:46:31 +00:00
|
|
|
) -> click.testing.Result:
|
2022-02-07 17:11:43 +00:00
|
|
|
"""
|
|
|
|
Use this method for commands that all need to run in the same root:
|
|
|
|
|
|
|
|
with temporary_root() as root:
|
|
|
|
result1 = self.invoke_in_root(root, ...)
|
|
|
|
result2 = self.invoke_in_root(root, ...)
|
|
|
|
"""
|
|
|
|
runner = click.testing.CliRunner(
|
|
|
|
env={
|
|
|
|
"TUTOR_ROOT": root,
|
|
|
|
"TUTOR_IGNORE_ENTRYPOINT_PLUGINS": "1",
|
|
|
|
"TUTOR_IGNORE_DICT_PLUGINS": "1",
|
2022-11-29 14:50:34 +00:00
|
|
|
},
|
|
|
|
mix_stderr=False,
|
2022-02-07 17:11:43 +00:00
|
|
|
)
|
2022-10-19 15:46:31 +00:00
|
|
|
return runner.invoke(
|
|
|
|
cli, args, obj=TestContext(root), catch_exceptions=catch_exceptions
|
|
|
|
)
|