Skip to content

Commit

Permalink
chore(tests): add missing return types
Browse files Browse the repository at this point in the history
  • Loading branch information
branchvincent authored and radoering committed May 1, 2022
1 parent 4fce656 commit f26e236
Show file tree
Hide file tree
Showing 40 changed files with 417 additions and 393 deletions.
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ known_third_party = ["poetry.core._vendor"]
strict = true
explicit_package_bases = true
namespace_packages = true
show_error_codes = true
mypy_path = "src"
files = "src, tests"
exclude = "(?x)(^tests/.*/fixtures | ^src/poetry/core/_vendor)"
Expand Down Expand Up @@ -111,6 +112,11 @@ module = [
]
ignore_errors = true

[[tool.mypy.overrides]]
module = ['tests.*']
# TODO: remove when mypy runs in environment with dependencies
disallow_untyped_decorators = false

[tool.vendoring]
destination = "src/poetry/core/_vendor/"
requirements = "src/poetry/core/_vendor/vendor.txt"
Expand Down
16 changes: 10 additions & 6 deletions tests/integration/test_pep517.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@
)
def test_pep517_check_poetry_managed(
request: FixtureRequest, getter: str, project: str
):
) -> None:
with temporary_project_directory(request.getfixturevalue(getter)(project)) as path:
assert project_wheel_metadata(path)


def test_pep517_check(project_source_root: Path):
def test_pep517_check(project_source_root: Path) -> None:
assert project_wheel_metadata(str(project_source_root))


def test_pep517_build_sdist(temporary_directory: Path, project_source_root: Path):
def test_pep517_build_sdist(
temporary_directory: Path, project_source_root: Path
) -> None:
build_package(
srcdir=str(project_source_root),
outdir=str(temporary_directory),
Expand All @@ -48,7 +50,9 @@ def test_pep517_build_sdist(temporary_directory: Path, project_source_root: Path
assert len(distributions) == 1


def test_pep517_build_wheel(temporary_directory: Path, project_source_root: Path):
def test_pep517_build_wheel(
temporary_directory: Path, project_source_root: Path
) -> None:
build_package(
srcdir=str(project_source_root),
outdir=str(temporary_directory),
Expand All @@ -58,7 +62,7 @@ def test_pep517_build_wheel(temporary_directory: Path, project_source_root: Path
assert len(distributions) == 1


def test_pip_wheel_build(temporary_directory: Path, project_source_root: Path):
def test_pip_wheel_build(temporary_directory: Path, project_source_root: Path) -> None:
tmp = str(temporary_directory)
pip = subprocess_run(
"pip", "wheel", "--use-pep517", "-w", tmp, str(project_source_root)
Expand All @@ -71,7 +75,7 @@ def test_pip_wheel_build(temporary_directory: Path, project_source_root: Path):
assert len(wheels) == 1


def test_pip_install_no_binary(python: str, project_source_root: Path):
def test_pip_install_no_binary(python: str, project_source_root: Path) -> None:
subprocess_run(
python,
"-m",
Expand Down
6 changes: 3 additions & 3 deletions tests/json/test_poetry_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ def multi_url_object() -> dict[str, Any]:
}


def test_path_dependencies(base_object: dict[str, Any]):
def test_path_dependencies(base_object: dict[str, Any]) -> None:
base_object["dependencies"].update({"foo": {"path": "../foo"}})
base_object["dev-dependencies"].update({"foo": {"path": "../foo"}})

assert len(validate_object(base_object, "poetry-schema")) == 0


def test_multi_url_dependencies(multi_url_object: dict[str, Any]):
def test_multi_url_dependencies(multi_url_object: dict[str, Any]) -> None:
assert len(validate_object(multi_url_object, "poetry-schema")) == 0


def test_multiline_description(base_object: dict[str, Any]):
def test_multiline_description(base_object: dict[str, Any]) -> None:
bad_description = "Some multi-\nline string"
base_object["description"] = bad_description

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tests.masonry.builders.fixtures.excluded_subpackage.example import __version__


def test_version():
def test_version() -> None:
assert __version__ == "0.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
extensions = [Extension("extended.extended", ["extended/extended.c"])]


def build():
def build() -> None:
distribution = Distribution({"name": "extended", "ext_modules": extensions})
distribution.package_dir = "extended"

Expand Down
30 changes: 17 additions & 13 deletions tests/masonry/builders/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pytest_mock import MockerFixture


def test_builder_find_excluded_files(mocker: MockerFixture):
def test_builder_find_excluded_files(mocker: MockerFixture) -> None:
p = mocker.patch("poetry.core.vcs.git.Git.get_ignored_files")
p.return_value = []

Expand All @@ -31,7 +31,7 @@ def test_builder_find_excluded_files(mocker: MockerFixture):
sys.platform == "win32",
reason="Windows is case insensitive for the most part",
)
def test_builder_find_case_sensitive_excluded_files(mocker: MockerFixture):
def test_builder_find_case_sensitive_excluded_files(mocker: MockerFixture) -> None:
p = mocker.patch("poetry.core.vcs.git.Git.get_ignored_files")
p.return_value = []

Expand All @@ -56,7 +56,9 @@ def test_builder_find_case_sensitive_excluded_files(mocker: MockerFixture):
sys.platform == "win32",
reason="Windows is case insensitive for the most part",
)
def test_builder_find_invalid_case_sensitive_excluded_files(mocker: MockerFixture):
def test_builder_find_invalid_case_sensitive_excluded_files(
mocker: MockerFixture,
) -> None:
p = mocker.patch("poetry.core.vcs.git.Git.get_ignored_files")
p.return_value = []

Expand All @@ -69,7 +71,7 @@ def test_builder_find_invalid_case_sensitive_excluded_files(mocker: MockerFixtur
assert {"my_package/Bar/foo/bar/Foo.py"} == builder.find_excluded_files()


def test_get_metadata_content():
def test_get_metadata_content() -> None:
builder = Builder(
Factory().create_poetry(Path(__file__).parent / "fixtures" / "complete")
)
Expand Down Expand Up @@ -122,7 +124,7 @@ def test_get_metadata_content():
]


def test_metadata_homepage_default():
def test_metadata_homepage_default() -> None:
builder = Builder(
Factory().create_poetry(Path(__file__).parent / "fixtures" / "simple_version")
)
Expand All @@ -132,7 +134,7 @@ def test_metadata_homepage_default():
assert metadata["Home-page"] is None


def test_metadata_with_vcs_dependencies():
def test_metadata_with_vcs_dependencies() -> None:
builder = Builder(
Factory().create_poetry(
Path(__file__).parent / "fixtures" / "with_vcs_dependency"
Expand All @@ -146,7 +148,7 @@ def test_metadata_with_vcs_dependencies():
assert requires_dist == "cleo @ git+https://github.com/sdispater/cleo.git@master"


def test_metadata_with_url_dependencies():
def test_metadata_with_url_dependencies() -> None:
builder = Builder(
Factory().create_poetry(
Path(__file__).parent / "fixtures" / "with_url_dependency"
Expand All @@ -164,7 +166,7 @@ def test_metadata_with_url_dependencies():
)


def test_missing_script_files_throws_error():
def test_missing_script_files_throws_error() -> None:
builder = Builder(
Factory().create_poetry(
Path(__file__).parent / "fixtures" / "script_reference_file_missing"
Expand All @@ -177,7 +179,7 @@ def test_missing_script_files_throws_error():
assert "is not found." in err.value.args[0]


def test_invalid_script_files_definition():
def test_invalid_script_files_definition() -> None:
with pytest.raises(RuntimeError) as err:
Builder(
Factory().create_poetry(
Expand All @@ -197,7 +199,7 @@ def test_invalid_script_files_definition():
"script_callable_legacy_table",
],
)
def test_entrypoint_scripts_legacy_warns(fixture: str):
def test_entrypoint_scripts_legacy_warns(fixture: str) -> None:
with pytest.warns(DeprecationWarning):
Builder(
Factory().create_poetry(Path(__file__).parent / "fixtures" / fixture)
Expand Down Expand Up @@ -236,7 +238,9 @@ def test_entrypoint_scripts_legacy_warns(fixture: str):
],
)
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
def test_builder_convert_entry_points(fixture: str, result: dict[str, list[str]]):
def test_builder_convert_entry_points(
fixture: str, result: dict[str, list[str]]
) -> None:
entry_points = Builder(
Factory().create_poetry(Path(__file__).parent / "fixtures" / fixture)
).convert_entry_points()
Expand Down Expand Up @@ -264,13 +268,13 @@ def test_builder_convert_entry_points(fixture: str, result: dict[str, list[str]]
),
],
)
def test_builder_convert_script_files(fixture: str, result: list[Path]):
def test_builder_convert_script_files(fixture: str, result: list[Path]) -> None:
project_root = Path(__file__).parent / "fixtures" / fixture
script_files = Builder(Factory().create_poetry(project_root)).convert_script_files()
assert [p.relative_to(project_root) for p in script_files] == result


def test_metadata_with_readme_files():
def test_metadata_with_readme_files() -> None:
test_path = Path(__file__).parent.parent.parent / "fixtures" / "with_readme_files"
builder = Builder(Factory().create_poetry(test_path))

Expand Down
20 changes: 10 additions & 10 deletions tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def clear_samples_dist() -> None:
or platform.python_implementation().lower() == "pypy",
reason="Disable test on Windows for Python <=3.6 and for PyPy",
)
def test_wheel_c_extension():
def test_wheel_c_extension() -> None:
module_path = fixtures_dir / "extended"
builder = Builder(Factory().create_poetry(module_path))
builder.build(fmt="all")
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_wheel_c_extension():
or platform.python_implementation().lower() == "pypy",
reason="Disable test on Windows for Python <=3.6 and for PyPy",
)
def test_wheel_c_extension_with_no_setup():
def test_wheel_c_extension_with_no_setup() -> None:
module_path = fixtures_dir / "extended_with_no_setup"
builder = Builder(Factory().create_poetry(module_path))
builder.build(fmt="all")
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_wheel_c_extension_with_no_setup():
or platform.python_implementation().lower() == "pypy",
reason="Disable test on Windows for Python <=3.6 and for PyPy",
)
def test_wheel_c_extension_src_layout():
def test_wheel_c_extension_src_layout() -> None:
module_path = fixtures_dir / "src_extended"
builder = Builder(Factory().create_poetry(module_path))
builder.build(fmt="all")
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_wheel_c_extension_src_layout():
zip.close()


def test_complete():
def test_complete() -> None:
module_path = fixtures_dir / "complete"
builder = Builder(Factory().create_poetry(module_path))
builder.build(fmt="all")
Expand Down Expand Up @@ -317,7 +317,7 @@ def test_complete():
zip.close()


def test_complete_no_vcs():
def test_complete_no_vcs() -> None:
# Copy the complete fixtures dir to a temporary directory
module_path = fixtures_dir / "complete"
temporary_dir = Path(tempfile.mkdtemp()) / "complete"
Expand Down Expand Up @@ -420,7 +420,7 @@ def test_complete_no_vcs():
zip.close()


def test_module_src():
def test_module_src() -> None:
module_path = fixtures_dir / "source_file"
builder = Builder(Factory().create_poetry(module_path))
builder.build(fmt="all")
Expand All @@ -444,7 +444,7 @@ def test_module_src():
zip.close()


def test_package_src():
def test_package_src() -> None:
module_path = fixtures_dir / "source_package"
builder = Builder(Factory().create_poetry(module_path))
builder.build(fmt="all")
Expand All @@ -469,7 +469,7 @@ def test_package_src():
zip.close()


def test_split_source():
def test_split_source() -> None:
module_path = fixtures_dir / "split_source"
builder = Builder(Factory().create_poetry(module_path))
builder.build(fmt="all")
Expand All @@ -495,7 +495,7 @@ def test_split_source():
zip.close()


def test_package_with_include(mocker: MockerFixture):
def test_package_with_include(mocker: MockerFixture) -> None:
module_path = fixtures_dir / "with-include"

# Patch git module to return specific excluded files
Expand Down Expand Up @@ -582,7 +582,7 @@ def test_package_with_include(mocker: MockerFixture):
assert "src_package/__init__.py" in names


def test_respect_format_for_explicit_included_files():
def test_respect_format_for_explicit_included_files() -> None:
module_path = fixtures_dir / "exclude-whl-include-sdist"
builder = Builder(Factory().create_poetry(module_path))
builder.build(fmt="all")
Expand Down

0 comments on commit f26e236

Please sign in to comment.