-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add typing hints to pytest components #1478
base: master
Are you sure you want to change the base?
Changes from all commits
8f23ffe
2639dc5
50fdc83
fb97862
9fcd05e
200d915
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
""" | ||
import os | ||
import warnings | ||
from typing import Dict | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does Labgrid sort its imports? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the way Would you prefer them to be in a different order? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I suppose I just don't understand how the ordering works Perhaps 'warnings' is consider an internal module and 'typing' is not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. Ruff puts |
||
from yaml import YAMLError | ||
import attr | ||
|
||
|
@@ -262,7 +263,7 @@ def get_imports(self): | |
|
||
return imports | ||
|
||
def get_paths(self): | ||
def get_paths(self) -> Dict[str, str]: | ||
"""Helper function that returns the subdict of all paths | ||
|
||
Returns: | ||
|
@@ -275,7 +276,7 @@ def get_paths(self): | |
|
||
return paths | ||
|
||
def get_images(self): | ||
def get_images(self) -> Dict[str, str]: | ||
"""Helper function that returns the subdict of all images | ||
|
||
Returns: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The commit message is missing the motivation for this change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, the message is:
I initially found it unclear that the Does this approach make sense to you? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. I didn't even know that Labgrid had created its own debug level! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
partial |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
from .fixtures import pytest_addoption, env, target, strategy | ||
from .hooks import pytest_configure, pytest_collection_modifyitems, pytest_cmdline_main | ||
|
||
__all__ = [ | ||
"pytest_addoption", | ||
"env", | ||
"target", | ||
"strategy", | ||
"pytest_configure", | ||
"pytest_collection_modifyitems", | ||
"pytest_cmdline_main", | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be in a separate commit? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import os | ||
import subprocess | ||
from typing import Iterator | ||
|
||
import pytest | ||
|
||
from .. import Environment, Target | ||
from ..exceptions import NoResourceFoundError, NoDriverFoundError | ||
from ..strategy import Strategy | ||
from ..remote.client import UserError | ||
from ..resource.remote import RemotePlace | ||
from ..util.ssh import sshmanager | ||
|
@@ -12,7 +16,9 @@ | |
# pylint: disable=redefined-outer-name | ||
|
||
|
||
def pytest_addoption(parser): | ||
def pytest_addoption(parser: pytest.Parser, pluginmanager: pytest.PytestPluginManager) -> None: | ||
del pluginmanager # unused | ||
|
||
group = parser.getgroup('labgrid') | ||
group.addoption( | ||
'--env-config', | ||
|
@@ -57,7 +63,7 @@ def pytest_addoption(parser): | |
|
||
|
||
@pytest.fixture(scope="session") | ||
def env(request, record_testsuite_property): | ||
def env(request: pytest.FixtureRequest, record_testsuite_property) -> Iterator[Environment]: | ||
"""Return the environment configured in the supplied configuration file. | ||
It contains the targets contained in the configuration file. | ||
""" | ||
|
@@ -74,7 +80,8 @@ def env(request, record_testsuite_property): | |
try: | ||
target = env.get_target(target_name) | ||
except UserError as e: | ||
pytest.exit(e) | ||
pytest.exit(str(e)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change seems to be unrelated to typing? Or does it fix a bug? If so, best to put the bug-fixes first, in one or more separate commits. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this fixes that the wrong type is passed to the |
||
assert target, "could not get target from environment" | ||
try: | ||
remote_place = target.get_resource(RemotePlace, wait_avail=False) | ||
remote_name = remote_place.name | ||
|
@@ -117,7 +124,7 @@ def env(request, record_testsuite_property): | |
|
||
|
||
@pytest.fixture(scope="session") | ||
def target(env): | ||
def target(env: Environment) -> Target: | ||
"""Return the default target `main` configured in the supplied | ||
configuration file.""" | ||
target = env.get_target() | ||
|
@@ -128,13 +135,13 @@ def target(env): | |
|
||
|
||
@pytest.fixture(scope="session") | ||
def strategy(request, target): | ||
def strategy(request: pytest.FixtureRequest, target: Target) -> Strategy: | ||
"""Return the Strategy of the default target `main` configured in the | ||
supplied configuration file.""" | ||
try: | ||
strategy = target.get_driver("Strategy") | ||
strategy: Strategy = target.get_driver("Strategy") | ||
except NoDriverFoundError as e: | ||
pytest.exit(e) | ||
pytest.exit(str(e)) | ||
|
||
state = request.config.option.lg_initial_state | ||
if state is not None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pytest
-specific