Skip to content
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

Strict typing, py.typed and link issues #8

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@
extensions += ['sphinx.ext.extlinks']

# local

# jaraco/jaraco.test#8
nitpick_ignore += [
('py:class', '_pytest.config.Config'),
('py:class', '_pytest.nodes.Item'),
]
2 changes: 1 addition & 1 deletion jaraco/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys


def property_error(name):
def property_error(name: str) -> str:
"""
Generate a regular expression for capturing the expected
error messages that can result from attempting to set
Expand Down
6 changes: 3 additions & 3 deletions jaraco/test/cpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import importlib
import types

from jaraco.context import suppress
from jaraco.collections import Projection
from jaraco.context import suppress


def from_test_support(*names):
def from_test_support(*names: str) -> types.SimpleNamespace:
"""
Return a SimpleNamespace of names from test.support.
Expand All @@ -28,7 +28,7 @@ def from_test_support(*names):


@suppress(ImportError)
def try_import(name):
def try_import(name: str) -> types.ModuleType:
"""
Attempt to import a submodule of test.support; return None if missing.
"""
Expand Down
18 changes: 10 additions & 8 deletions jaraco/test/http.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
import urllib.request

import pytest

import jaraco.functools
from jaraco.context import ExceptionTrap


@jaraco.functools.once
def has_internet():
def has_internet() -> bool:
"""
Is this host able to reach the Internet?
Return True if the internet appears reachable and False
otherwise.
"""
with ExceptionTrap() as trap:
with ExceptionTrap() as trap: # type: ignore[no-untyped-call] # jaraco/jaraco.context#15
urllib.request.urlopen('http://pypi.org')
return not trap


def check_internet():
def check_internet() -> None:
"""
(pytest) Skip if internet is unavailable.
"""
has_internet() or pytest.skip('Internet connectivity unavailable')
if not has_internet():
pytest.skip('Internet connectivity unavailable')


@pytest.fixture
def needs_internet():
def needs_internet() -> None:
"""
Pytest fixture signaling that internet is required.
"""
check_internet()


def pytest_configure(config):
def pytest_configure(config: pytest.Config) -> None:
"""
Register the 'network' marker.
"""
Expand All @@ -42,9 +44,9 @@ def pytest_configure(config):
)


def pytest_runtest_setup(item):
def pytest_runtest_setup(item: pytest.Item) -> None:
"""
For any tests marked with 'network', install fixture.
"""
for marker in item.iter_markers(name='network'):
item.fixturenames.extend({'needs_internet'} - set(item.fixturenames))
item.fixturenames.extend({'needs_internet'} - set(item.fixturenames)) # type: ignore[attr-defined]
Empty file added jaraco/test/py.typed
Empty file.
7 changes: 6 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[mypy]
# Is the project well-typed?
strict = False
strict = True

# Early opt-in even when strict = False
warn_unused_ignores = True
Expand All @@ -13,3 +13,8 @@ explicit_package_bases = True
disable_error_code =
# Disable due to many false positives
overload-overlap,

# Can't ignore inline because the error is inconsistent
# Exists but untyped on Python 3.8 on Windows. Doesn't exist anywhere else.
[mypy-test.*]
ignore_missing_imports = True
1 change: 1 addition & 0 deletions newsfragments/8.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Complete annotations and add ``py.typed`` marker -- by :user:`Avasam`
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,3 @@ pytest11 = {"jaraco.test.http" = "jaraco.test.http"}


[tool.setuptools_scm]


[tool.pytest-enabler.mypy]
# Disabled due to jaraco/skeleton#143
5 changes: 3 additions & 2 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import pytest


def test_needs_internet(needs_internet):
@pytest.mark.usefixtures("needs_internet")
def test_needs_internet() -> None:
"""
This test should always succeed or be skipped.
"""
urllib.request.urlopen('http://pypi.org/')


@pytest.mark.network
def test_network_marker():
def test_network_marker() -> None:
"""
This test should always succeed or be skipped.
"""
Expand Down
Loading