Skip to content

Commit

Permalink
chore(tests): remove type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
branchvincent authored and radoering committed May 1, 2022
1 parent 8c75c1a commit 4fce656
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 74 deletions.
15 changes: 1 addition & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module = [
'lark.*',
'setuptools.*',
'tomlkit.*',
'virtualenv.*',
]
ignore_missing_imports = true

Expand All @@ -107,20 +108,6 @@ module = [
'poetry.core.version.pep440.parser',
'poetry.core.version.pep440.segments',
'poetry.core.version.pep440.version',
# test modules
'tests.conftest',
'tests.integration.test_pep517',
'tests.json.*',
'tests.masonry.*',
'tests.packages.*',
'tests.pyproject.*',
'tests.semver.*',
'tests.spdx.*',
'tests.test_factory',
'tests.testutils.*',
'tests.utils.*',
'tests.vcs.*',
'tests.version.*',
]
ignore_errors = true

Expand Down
4 changes: 2 additions & 2 deletions src/poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pprint import pformat
from tarfile import TarInfo
from typing import TYPE_CHECKING
from typing import ContextManager
from typing import Iterator

from poetry.core.masonry.builders.builder import Builder
from poetry.core.masonry.builders.builder import BuildIncludeFile
Expand Down Expand Up @@ -213,7 +213,7 @@ def build_setup(self) -> bytes:
).encode()

@contextmanager
def setup_py(self) -> ContextManager[Path]:
def setup_py(self) -> Iterator[Path]:
setup = self._path / "setup.py"
has_setup = setup.exists()

Expand Down
8 changes: 4 additions & 4 deletions src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def __init__(
self._authors = []
self._maintainers = []

self.homepage = None
self.repository_url = None
self.documentation_url = None
self.keywords = []
self.homepage: str | None = None
self.repository_url: str | None = None
self.documentation_url: str | None = None
self.keywords: list[str] = []
self._license = None
self.readmes: tuple[Path, ...] = ()

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/core/packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def group_markers(
return groups


def convert_markers(marker: BaseMarker) -> dict[str, list[tuple[str, str]]]:
def convert_markers(marker: BaseMarker) -> dict[str, list[list[tuple[str, str]]]]:
groups = group_markers([marker])

requirements = {}
Expand Down
12 changes: 6 additions & 6 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def is_any(self) -> bool:
def is_empty(self) -> bool:
return False

def validate(self, environment: dict[str, Any]) -> bool:
def validate(self, environment: dict[str, Any] | None) -> bool:
raise NotImplementedError()

def without_extras(self) -> BaseMarker:
Expand Down Expand Up @@ -96,7 +96,7 @@ def is_any(self) -> bool:
def is_empty(self) -> bool:
return False

def validate(self, environment: dict[str, Any]) -> bool:
def validate(self, environment: dict[str, Any] | None) -> bool:
return True

def without_extras(self) -> BaseMarker:
Expand Down Expand Up @@ -140,7 +140,7 @@ def is_any(self) -> bool:
def is_empty(self) -> bool:
return True

def validate(self, environment: dict[str, Any]) -> bool:
def validate(self, environment: dict[str, Any] | None) -> bool:
return False

def without_extras(self) -> BaseMarker:
Expand Down Expand Up @@ -274,7 +274,7 @@ def union(self, other: BaseMarker) -> BaseMarker:

return other.union(self)

def validate(self, environment: dict[str, Any]) -> bool:
def validate(self, environment: dict[str, Any] | None) -> bool:
if environment is None:
return True

Expand Down Expand Up @@ -505,7 +505,7 @@ def union_simplify(self, other: BaseMarker) -> BaseMarker | None:

return None

def validate(self, environment: dict[str, Any]) -> bool:
def validate(self, environment: dict[str, Any] | None) -> bool:
return all(m.validate(environment) for m in self._markers)

def without_extras(self) -> BaseMarker:
Expand Down Expand Up @@ -695,7 +695,7 @@ def union(self, other: BaseMarker) -> BaseMarker:

return MarkerUnion.of(*new_markers)

def validate(self, environment: dict[str, Any]) -> bool:
def validate(self, environment: dict[str, Any] | None) -> bool:
return any(m.validate(environment) for m in self._markers)

def without_extras(self) -> BaseMarker:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import sys
import tempfile

from pathlib import Path
from typing import TYPE_CHECKING
Expand All @@ -11,7 +12,6 @@
import virtualenv

from poetry.core.factory import Factory
from tests.testutils import tempfile


if TYPE_CHECKING:
Expand Down
12 changes: 7 additions & 5 deletions tests/json/test_poetry_schema.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import annotations

from typing import Any

import pytest

from poetry.core.json import validate_object


@pytest.fixture
def base_object() -> dict:
def base_object() -> dict[str, Any]:
return {
"name": "myapp",
"version": "1.0.0",
Expand All @@ -17,7 +19,7 @@ def base_object() -> dict:


@pytest.fixture
def multi_url_object() -> dict:
def multi_url_object() -> dict[str, Any]:
return {
"name": "myapp",
"version": "1.0.0",
Expand All @@ -35,18 +37,18 @@ def multi_url_object() -> dict:
}


def test_path_dependencies(base_object: dict):
def test_path_dependencies(base_object: dict[str, Any]):
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):
def test_multi_url_dependencies(multi_url_object: dict[str, Any]):
assert len(validate_object(multi_url_object, "poetry-schema")) == 0


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

Expand Down
10 changes: 7 additions & 3 deletions tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import Iterator

import pytest

Expand All @@ -27,7 +29,7 @@


@pytest.fixture(autouse=True)
def setup() -> None:
def setup() -> Iterator[None]:
clear_samples_dist()

yield
Expand Down Expand Up @@ -541,11 +543,13 @@ def test_package_with_include(mocker: MockerFixture):
assert "with-include-1.2.3/for_wheel_only/__init__.py" not in names
assert "with-include-1.2.3/src/src_package/__init__.py" in names

setup = tar.extractfile("with-include-1.2.3/setup.py").read()
file = tar.extractfile("with-include-1.2.3/setup.py")
assert file
setup = file.read()
setup_ast = ast.parse(setup)

setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
ns = {}
ns: dict[str, Any] = {}
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
assert ns["package_dir"] == {"": "src"}
assert ns["packages"] == [
Expand Down
24 changes: 13 additions & 11 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
from email.parser import Parser
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import Iterator

import pytest

from poetry.core.factory import Factory
from poetry.core.masonry.builders.sdist import SdistBuilder
from poetry.core.masonry.utils.package_include import PackageInclude
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.package import Package
from poetry.core.packages.project_package import ProjectPackage
from poetry.core.packages.vcs_dependency import VCSDependency


Expand All @@ -27,7 +29,7 @@


@pytest.fixture(autouse=True)
def setup() -> None:
def setup() -> Iterator[None]:
clear_samples_dist()

yield
Expand All @@ -46,7 +48,7 @@ def project(name: str) -> Path:


def test_convert_dependencies():
package = Package("foo", "1.2.3")
package = ProjectPackage("foo", "1.2.3")
result = SdistBuilder.convert_dependencies(
package,
[
Expand All @@ -66,11 +68,11 @@ def test_convert_dependencies():
"E>=1.0,<2.0",
"F>=1.0,<2.0,!=1.3",
]
extras = {}
extras: dict[str, Any] = {}

assert result == (main, extras)

package = Package("foo", "1.2.3")
package = ProjectPackage("foo", "1.2.3")
package.extras = {"bar": [Dependency("A", "*")]}

result = SdistBuilder.convert_dependencies(
Expand Down Expand Up @@ -120,7 +122,7 @@ def test_make_setup():
setup_ast = ast.parse(setup)

setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
ns = {}
ns: dict[str, Any] = {}
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
assert ns["packages"] == [
"my_package",
Expand Down Expand Up @@ -368,7 +370,7 @@ def test_with_src_module_file():
setup_ast = ast.parse(setup)

setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
ns = {}
ns: dict[str, Any] = {}
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
assert ns["package_dir"] == {"": "src"}
assert ns["modules"] == ["module_src"]
Expand All @@ -393,7 +395,7 @@ def test_with_src_module_dir():
setup_ast = ast.parse(setup)

setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
ns = {}
ns: dict[str, Any] = {}
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
assert ns["package_dir"] == {"": "src"}
assert ns["packages"] == ["package_src"]
Expand Down Expand Up @@ -436,7 +438,7 @@ def test_default_with_excluded_data(mocker: MockerFixture):
setup_ast = ast.parse(setup)

setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
ns = {}
ns: dict[str, Any] = {}
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
assert "package_dir" not in ns
assert ns["packages"] == ["my_package"]
Expand Down Expand Up @@ -578,7 +580,7 @@ def test_excluded_subpackage():
setup_ast = ast.parse(setup)

setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
ns = {}
ns: dict[str, Any] = {}
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)

assert ns["packages"] == ["example"]
Expand Down Expand Up @@ -648,6 +650,6 @@ def test_split_source():
setup_ast = ast.parse(setup)

setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
ns = {}
ns: dict[str, Any] = {}
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
assert "" in ns["package_dir"] and "module_b" in ns["package_dir"]
8 changes: 5 additions & 3 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import Iterator
from typing import TextIO

import pytest

Expand All @@ -23,7 +25,7 @@


@pytest.fixture(autouse=True)
def setup() -> None:
def setup() -> Iterator[None]:
clear_samples_dist()

yield
Expand Down Expand Up @@ -300,11 +302,11 @@ def test_wheel_file_is_closed(monkeypatch: MonkeyPatch):
"""Confirm that wheel zip files are explicitly closed."""

# Using a list is a hack for Python 2.7 compatibility.
fd_file = [None]
fd_file: list[TextIO | None] = [None]

real_fdopen = os.fdopen

def capturing_fdopen(*args: Any, **kwargs: Any):
def capturing_fdopen(*args: Any, **kwargs: Any) -> TextIO | None:
fd_file[0] = real_fdopen(*args, **kwargs)
return fd_file[0]

Expand Down
4 changes: 2 additions & 2 deletions tests/masonry/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def cwd(directory: str | Path) -> Iterator[None]:


def test_get_requires_for_build_wheel():
expected = []
expected: list[str] = []
with cwd(os.path.join(fixtures, "complete")):
assert api.get_requires_for_build_wheel() == expected


def test_get_requires_for_build_sdist():
expected = []
expected: list[str] = []
with cwd(os.path.join(fixtures, "complete")):
assert api.get_requires_for_build_sdist() == expected

Expand Down
6 changes: 3 additions & 3 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def test_with_constraint():
def test_marker_properly_sets_python_constraint():
dependency = Dependency("foo", "^1.2.3")

dependency.marker = 'python_version >= "3.6" and python_version < "4.0"'
dependency.marker = 'python_version >= "3.6" and python_version < "4.0"' # type: ignore[assignment]

assert str(dependency.python_constraint) == ">=3.6,<4.0"

Expand All @@ -309,8 +309,8 @@ def test_dependency_markers_are_the_same_as_markers():
def test_marker_properly_unsets_python_constraint():
dependency = Dependency("foo", "^1.2.3")

dependency.marker = 'python_version >= "3.6"'
dependency.marker = 'python_version >= "3.6"' # type: ignore[assignment]
assert str(dependency.python_constraint) == ">=3.6"

dependency.marker = "*"
dependency.marker = "*" # type: ignore[assignment]
assert str(dependency.python_constraint) == "*"
Loading

0 comments on commit 4fce656

Please sign in to comment.