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

Update automated tests, pass as-is #301

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
9 changes: 6 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ jobs:
python -m pip install -r tests/requirements.txt

- name: Run pyright tests
uses: gramster/pyright-action@main
uses: jakebailey/pyright-action@v2
with:
project: tests/pyrighttestconfig.json
warn-partial: true
pylance-version: latest-prerelease

- name: Run mypy tests
run:
python -m mypy .

hygiene:
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"editor.formatOnSave": false,
"python.formatting.provider": "black",
"python.analysis.diagnosticMode": "workspace",
"python.analysis.typeCheckingMode": "strict",
"python.analysis.openFilesOnly": false
}
87 changes: 58 additions & 29 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[tool.black]
line_length = 130
target_version = ["py37"]
# Target oldest supported Python version
target_version = ["py38"]

[tool.isort]
profile = "black"
Expand Down Expand Up @@ -39,19 +40,45 @@ extra_standard_library = [
"UserString",
]

[tool.pyright]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests show several of these reportUnsupportedDunderAll diagnostics from pyright. Are they bugs in the stubs? Should we suppress the warning or fix them?

"relativedelta" is specified in __all__ but is not present in module (reportUnsupportedDunderAll)

Copy link
Contributor Author

@Avasam Avasam Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix them (in following PRs, like all other warnings and suppressed errors). The stub is saying that from module import * will export a symbol that is missing in the stub itself.

In your example, stubs/matplotlib/dates.pyi is missing:

from dateutil.relativedelta import relativedelta

# Target oldest supported Python version
pythonversion = "3.8"
typeCheckingMode = "standard"
# Partial stubs are acceptable
reportUnknownArgumentType = false
# Stubs-only packages are fine for testing
reportMissingModuleSource = false
# Stubs are allowed to use private variables
reportPrivateUsage = false
reportPrivateImportUsage = false
# Incompatible overrides and property type mismatches are out of our stubs' control
# as they are inherited from the implementation.
reportIncompatibleMethodOverride = false
reportIncompatibleVariableOverride = false
reportPropertyTypeMismatch = false
# Overlapping overloads are often necessary in a stub, meaning pyright's check
# (which is stricter than mypy's; see mypy issue #10143 and #10157)
# would cause many false positives and catch few bugs.
reportOverlappingOverload = false
# The name of the self/cls parameter is out of third-party stubs' control.
reportSelfClsParameterName = false

# Error reports to fix in code
reportArgumentType = "none" # TODO
reportAssertTypeFailure = "none" # TODO
reportAssignmentType = "none" # TODO
reportAttributeAccessIssue = "none" # TODO
reportFunctionMemberAccess = "none" # TODO
reportGeneralTypeIssues = "none" # TODO
reportInvalidTypeForm = "none" # TODO
reportMissingImports = "none" # TODO
reportUndefinedVariable = "none" # TODO
reportUnusedVariable = "none" # TODO

[tool.mypy]
# Import discovery
mypy_path = "partial"
namespace_packages = false
explicit_package_bases = false
ignore_missing_imports = true
follow_imports = "normal"
follow_imports_for_stubs = false
no_site_packages = false
no_silence_site_packages = false
# Platform configuration
# Target oldest supported Python version
python_version = "3.8"
# Disallow dynamic typing
# Allow dynamic typing
disallow_any_unimported = false # TODO
disallow_any_expr = false # TODO
disallow_any_decorated = false # TODO
Expand All @@ -64,25 +91,27 @@ disallow_untyped_defs = false # TODO
disallow_incomplete_defs = false # TODO
check_untyped_defs = true
disallow_untyped_decorators = true
# None and Optional handling
no_implicit_optional = true
strict_optional = true
# Configuring warnings
warn_redundant_casts = true
warn_unused_ignores = false # Change from pandas
warn_no_return = true
warn_return_any = false # TODO
warn_unreachable = false # GH#27396
# Suppressing errors
show_none_errors = true
ignore_errors = false
# Miscellaneous strictness flags
allow_untyped_globals = false
allow_redefinition = false
local_partial_types = false
implicit_reexport = true
strict_equality = true
disable_error_code = [
# Not all imports in these stubs are gonna be typed
"import-untyped",
# TODO
"arg-type",
"assignment",
"attr-defined",
"import-not-found",
"misc",
"name-defined",
"no-redef",
"operator",
"override",
"return",
"truthy-function",
"valid-type",
"var-annotated",
]
# Configuring error messages
show_error_context = false
show_column_numbers = false
show_error_codes = true
show_column_numbers = true
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/matplotlib/figure_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import assert_type
from typing_extensions import assert_type

from matplotlib.axes import Axes
from matplotlib.figure import Figure
Expand Down
2 changes: 1 addition & 1 deletion tests/matplotlib/pyplot_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, assert_type
from typing_extensions import assert_type

import matplotlib.pyplot as plt
import numpy as np
Expand Down
8 changes: 0 additions & 8 deletions tests/pyrighttestconfig.json

This file was deleted.

23 changes: 20 additions & 3 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Tools used for testing
docopt
mypy==1.11.*
pyright
debonte marked this conversation as resolved.
Show resolved Hide resolved
matplotlib

# Typed libraries and stubs
matplotlib>=3.8
pytest
mypy==0.950
typing_extensions==4.2.0

# Untyped libraries, used to prevent "reportMissingImports" and get inferred typing
joblib
networkx
PyOpenGL
scikit-image
scikit-learn
scipy
transformers
vispy
numpydoc
pyamg
traitlets
uarray
39 changes: 39 additions & 0 deletions tests/run_formatters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import subprocess
import sys
from pathlib import Path


def install_requirements():
print("\nInstalling requirements...")
return subprocess.run((sys.executable, "-m", "pip", "install", "--upgrade", "isort", "black"))


def run_isort():
print("\nRunning isort...")
return subprocess.run((sys.executable, "-m", "isort", "."))


def run_black():
print("\nRunning Black...")
return subprocess.run((sys.executable, "-m", "black", "."))


def main():
test_folder = Path(__file__).parent
root = test_folder.parent
os.chdir(root)

install_requirements().check_returncode()
results = (
run_isort(),
run_black(),
)
if sum([result.returncode for result in results]) > 0:
print("\nOne or more tests failed. See above for details.")
else:
print("\nAll tests passed!")


if __name__ == "__main__":
main()
3 changes: 0 additions & 3 deletions tests/run_tests.cmd

This file was deleted.

44 changes: 44 additions & 0 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import subprocess
import sys
from pathlib import Path


def install_requirements(test_folder: str):
print("\nInstalling requirements...")
return subprocess.run(
(sys.executable, "-m", "pip", "install", "--upgrade", "-r", os.path.join(test_folder, "requirements.txt"))
)


def run_pyright():
print("\nRunning Pyright...")
# https://github.com/RobertCraigie/pyright-python#keeping-pyright-and-pylance-in-sync
del os.environ["PYRIGHT_PYTHON_FORCE_VERSION"]
os.environ["PYRIGHT_PYTHON_PYLANCE_VERSION"] = "latest-prerelease"
return subprocess.run((sys.executable, "-m", "pyright"))


def run_mypy():
print("\nRunning mypy...")
return subprocess.run((sys.executable, "-m", "mypy"))


def main():
test_folder = Path(__file__).parent
root = test_folder.parent
os.chdir(root)

install_requirements(test_folder).check_returncode()
results = (
run_mypy(),
run_pyright(),
)
if sum([result.returncode for result in results]) > 0:
print("\nOne or more tests failed. See above for details.")
else:
print("\nAll tests passed!")


if __name__ == "__main__":
main()
7 changes: 0 additions & 7 deletions tests/run_tests.sh

This file was deleted.

Loading