Skip to content

Commit

Permalink
Update automated tests, pass as-is (#301)
Browse files Browse the repository at this point in the history
* Update automated tests, pass as-is

* Address PR comments

* Split formatters shell script

* Update and fix tests to run from anywhere

* Update tests

* Not installing pyright on CI

* Not a TODO

* Set pyright's typeCheckingMode to standard

* Use Python scripts instead and check pyright against pylance-prerelease

* Forgot to delete run_formatters

* typing_extensions goes under "Typed libraries and stubs"

* Bump minimum Python version to 3.9

* Missed mypy target version

* Unpin typing_extensions

* post-merge fix

* use docopt-ng instead of docopt

* Add type-var to mypy disable
  • Loading branch information
Avasam authored Nov 6, 2024
1 parent 62181ec commit f33aa54
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 57 deletions.
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
}
93 changes: 63 additions & 30 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[tool.black]
line_length = 130
target_version = ["py37"]
# Target oldest supported Python version
target_version = ["py39"]

[tool.ruff]
line-length = 130
# Target oldest supported Python version
target-version = "py39"

[tool.ruff.lint]
select = [
Expand Down Expand Up @@ -61,19 +64,46 @@ extra-standard-library = [
"zoneinfo",
]

[tool.pyright]
# Target oldest supported Python version
pythonversion = "3.9"
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
reportInvalidTypeArguments = "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
python_version = "3.8"
# Disallow dynamic typing
# Target oldest supported Python version
python_version = "3.9"
# Allow dynamic typing
disallow_any_unimported = false # TODO
disallow_any_expr = false # TODO
disallow_any_decorated = false # TODO
Expand All @@ -86,25 +116,28 @@ 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",
"type-var",
"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.

22 changes: 19 additions & 3 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
matplotlib
mypy==0.950
# Tools used for testing
docopt-ng
mypy==1.13.*
pyright

# Typed libraries and stubs
matplotlib>=3.8
pytest
scipy-stubs
typing_extensions

# Untyped libraries, used to prevent "reportMissingImports" and get inferred typing
joblib
networkx
PyOpenGL
scikit-image
scikit-learn
typing_extensions==4.2.0
transformers
vispy
numpydoc
pyamg
traitlets
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.

0 comments on commit f33aa54

Please sign in to comment.