← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:mypy-testing into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:mypy-testing into launchpad:master.

Commit message:
mypy: Run for lp.testing

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/436845
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:mypy-testing into launchpad:master.
diff --git a/lib/lp/testing/__init__.py b/lib/lp/testing/__init__.py
index 4b78f9a..05eae7c 100644
--- a/lib/lp/testing/__init__.py
+++ b/lib/lp/testing/__init__.py
@@ -67,7 +67,7 @@ from datetime import datetime, timedelta
 from fnmatch import fnmatchcase
 from functools import partial
 from select import select
-from typing import TYPE_CHECKING, Type
+from typing import TYPE_CHECKING, Optional, Type
 
 import fixtures
 import lp_sitecustomize
@@ -1079,8 +1079,8 @@ class AbstractYUITestCase(TestCase):
     # 30 seconds for the suite.
     suite_timeout = 30000
     # By default we do not restrict per-test or times.  yuixhr tests do.
-    incremental_timeout = None
-    initial_timeout = None
+    incremental_timeout = None  # type: Optional[int]
+    initial_timeout = None  # type: Optional[int]
     html_uri = None
     test_path = None
 
diff --git a/lib/lp/testing/html5browser.py b/lib/lp/testing/html5browser.py
index 6022cef..c559c64 100644
--- a/lib/lp/testing/html5browser.py
+++ b/lib/lp/testing/html5browser.py
@@ -56,7 +56,7 @@ class Browser:
     def run_tests(
         self,
         uri: str,
-        timeout: int = TIMEOUT,
+        timeout: float = TIMEOUT,
         incremental_timeout: Optional[int] = None,
     ) -> Results:
         """
@@ -95,7 +95,7 @@ class Browser:
             status=Results.Status.TIMEOUT, last_test_message=results
         )
 
-    def _get_test_results(self, timeout: int) -> Any:
+    def _get_test_results(self, timeout: float) -> Any:
         """
         Load the test results from the page.
 
diff --git a/lib/lp/testing/pgsql.py b/lib/lp/testing/pgsql.py
index 9db1fd0..7069d83 100644
--- a/lib/lp/testing/pgsql.py
+++ b/lib/lp/testing/pgsql.py
@@ -10,6 +10,7 @@ import os
 import random
 import sys
 import time
+from typing import List, Optional
 
 import psycopg2
 from breezy.errors import LockContention
@@ -92,7 +93,7 @@ class CursorWrapper:
     """
 
     real_cursor = None
-    last_executed_sql = []
+    last_executed_sql = []  # type: List[str]
     record_sql = False
 
     def __init__(self, real_cursor):
@@ -162,16 +163,16 @@ def uninstallFakeConnect():
 class PgTestSetup:
 
     # Shared:
-    connections = []
+    connections = []  # type: List[ConnectionWrapper]
     # Use a dynamically generated dbname:
     dynamic = object()
 
     template = "template1"
     # Needs to match configs/testrunner*/*:
     dbname = "launchpad_ftest"
-    dbuser = None
-    host = None
-    port = None
+    dbuser = None  # type: Optional[str]
+    host = None  # type: Optional[str]
+    port = None  # type: Optional[int]
 
     # Class attributes. With PostgreSQL 8.4, pg_shdepend bloats
     # hugely when we drop and create databases, because this
diff --git a/lib/lp/testing/swift/tests/test_fixture.py b/lib/lp/testing/swift/tests/test_fixture.py
index 99828a1..122e2b4 100644
--- a/lib/lp/testing/swift/tests/test_fixture.py
+++ b/lib/lp/testing/swift/tests/test_fixture.py
@@ -3,10 +3,11 @@
 
 """Testing the mock Swift test fixture."""
 
-__all__ = []
+__all__ = []  # type: List[str]
 
 from datetime import datetime
 from hashlib import md5
+from typing import List
 
 from requests.exceptions import ConnectionError
 from swiftclient import client as swiftclient
diff --git a/lib/lp/testing/systemdocs.py b/lib/lp/testing/systemdocs.py
index fe3966a..bb39965 100644
--- a/lib/lp/testing/systemdocs.py
+++ b/lib/lp/testing/systemdocs.py
@@ -234,7 +234,9 @@ class PrettyPrinter(pprint.PrettyPrinter):
 
     # Disable wrapping of long strings on Python >= 3.5, which is unhelpful
     # in doctests.  There seems to be no reasonable public API for this.
-    _dispatch = dict(pprint.PrettyPrinter._dispatch)
+    _dispatch = dict(
+        pprint.PrettyPrinter._dispatch  # type: ignore[attr-defined]
+    )
     del _dispatch[str.__repr__]
     del _dispatch[bytes.__repr__]
     del _dispatch[bytearray.__repr__]
diff --git a/lib/lp/testing/tests/test_layers.py b/lib/lp/testing/tests/test_layers.py
index 69c46af..386586e 100644
--- a/lib/lp/testing/tests/test_layers.py
+++ b/lib/lp/testing/tests/test_layers.py
@@ -3,9 +3,10 @@
 
 """Tests for test layers."""
 
-__all__ = []
+__all__ = []  # type: List[str]
 
 import threading
+from typing import List
 
 from lp.testing import TestCase
 from lp.testing.layers import BaseLayer
diff --git a/lib/lp/testing/tests/test_matchers.py b/lib/lp/testing/tests/test_matchers.py
index f2c629a..b8d09e8 100644
--- a/lib/lp/testing/tests/test_matchers.py
+++ b/lib/lp/testing/tests/test_matchers.py
@@ -28,7 +28,9 @@ from lp.testing.matchers import (
 class ITestInterface(Interface):
     """A dummy interface for testing."""
 
-    def doFoo():
+    # XXX cjwatson 2023-02-03: mypy-zope should fix the need to override
+    # mypy here.
+    def doFoo():  # type: ignore[misc]
         """Dummy method for interface compliance testing."""
 
 
diff --git a/lib/lp/testing/tests/test_sampledata.py b/lib/lp/testing/tests/test_sampledata.py
index b3ca6d7..1b17765 100644
--- a/lib/lp/testing/tests/test_sampledata.py
+++ b/lib/lp/testing/tests/test_sampledata.py
@@ -8,9 +8,10 @@ silently switching off some of our constraints. We can detect this by
 doing a dump and restore - this will fail if the data is corrupt.
 """
 
-__all__ = []
+__all__ = []  # type: List[str]
 
 import subprocess
+from typing import List
 
 from lp.testing import TestCase
 from lp.testing.layers import DatabaseLayer
diff --git a/lib/lp/testing/tests/test_standard_yuixhr_test_template.py b/lib/lp/testing/tests/test_standard_yuixhr_test_template.py
index 736fd10..c7672d4 100644
--- a/lib/lp/testing/tests/test_standard_yuixhr_test_template.py
+++ b/lib/lp/testing/tests/test_standard_yuixhr_test_template.py
@@ -4,7 +4,9 @@
 """{Describe your test suite here}.
 """
 
-__all__ = []
+__all__ = []  # type: List[str]
+
+from typing import List
 
 from lp.testing import person_logged_in
 from lp.testing.factory import LaunchpadObjectFactory
@@ -96,7 +98,7 @@ def example(request, data):
     # .extend.)
 
 
-@example.add_cleanup
+@example.add_cleanup  # type: ignore[no-redef]
 def example(request, data):
     # This is an example of a cleanup function, which will be called
     # at the end of the test.  You usually won't need one of these,
diff --git a/lib/lp/testing/tests/test_yuixhr_fixture.py b/lib/lp/testing/tests/test_yuixhr_fixture.py
index 6b97c76..65e6a08 100644
--- a/lib/lp/testing/tests/test_yuixhr_fixture.py
+++ b/lib/lp/testing/tests/test_yuixhr_fixture.py
@@ -4,7 +4,9 @@
 """These are yui appserver fixtures for the yui appserver test code's tests.
 """
 
-__all__ = []
+__all__ = []  # type: List[str]
+
+from typing import Any, Dict, List, Tuple
 
 from zope.security.proxy import removeSecurityProxy
 
@@ -15,7 +17,7 @@ from lp.testing.yuixhr import login_as_person, make_suite, setup
 # The following are the fixtures needed by the tests.
 
 # We use this variable for test results.
-_received = []
+_received = []  # type: List[Tuple[str, Any, Dict[str, str]]]
 
 
 @setup
@@ -23,7 +25,7 @@ def baseline(request, data):
     data["hello"] = "world"
 
 
-@baseline.add_cleanup
+@baseline.add_cleanup  # type: ignore[no-redef]
 def baseline(request, data):
     global _received
     _received.append(("baseline", request, data))
@@ -34,7 +36,7 @@ def second(request, data):
     data["second"] = "here"
 
 
-@second.add_cleanup
+@second.add_cleanup  # type: ignore[no-redef]
 def second(request, data):
     global _received
     _received.append(("second", request, data))
@@ -50,7 +52,7 @@ def faux_database_thing(request, data):
     test_value = None
 
 
-@faux_database_thing.add_cleanup
+@faux_database_thing.add_cleanup  # type: ignore[no-redef]
 def faux_database_thing(request, data):
     global test_value
     test_value = "teardown was called"
@@ -61,7 +63,7 @@ def show_teardown_value(request, data):
     data["setup_data"] = "Hello world"
 
 
-@show_teardown_value.add_cleanup
+@show_teardown_value.add_cleanup  # type: ignore[no-redef]
 def show_teardown_value(request, data):
     global test_value
     test_value = data
@@ -92,7 +94,7 @@ def teardown_will_fail(request, data):
     pass
 
 
-@teardown_will_fail.add_cleanup
+@teardown_will_fail.add_cleanup  # type: ignore[no-redef]
 def teardown_will_fail(request, data):
     raise RuntimeError("rutebegas")
 
diff --git a/lib/lp/testing/tests/test_yuixhr_fixture_facet.py b/lib/lp/testing/tests/test_yuixhr_fixture_facet.py
index 4ccf9a0..5e7a0e9 100644
--- a/lib/lp/testing/tests/test_yuixhr_fixture_facet.py
+++ b/lib/lp/testing/tests/test_yuixhr_fixture_facet.py
@@ -4,7 +4,9 @@
 """Test the ability to specify a facet for the yuixhr tests.
 """
 
-__all__ = []
+__all__ = []  # type: List[str]
+
+from typing import List
 
 from lp.testing.yuixhr import make_suite
 
diff --git a/pyproject.toml b/pyproject.toml
index 83925c3..cf22bee 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -34,6 +34,14 @@ module = "breezy.*"
 ignore_missing_imports = true
 
 [[tool.mypy.overrides]]
+module = "brzbuildrecipe.*"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
+module = "cryptography.*"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
 module = "debian.*"
 ignore_missing_imports = true
 
@@ -62,6 +70,10 @@ module = "iso8601"
 ignore_missing_imports = true
 
 [[tool.mypy.overrides]]
+module = "launchpadlib.*"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
 module = "lazr.*"
 ignore_missing_imports = true
 
@@ -70,10 +82,26 @@ module = "lpbuildd.*"
 ignore_missing_imports = true
 
 [[tool.mypy.overrides]]
+module = "oops"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
+module = "oops_amqp"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
+module = "oops_datedir_repo.*"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
 module = "packaging"
 ignore_missing_imports = true
 
 [[tool.mypy.overrides]]
+module = "pgbouncer.*"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
 module = "pymacaroons"
 ignore_missing_imports = true
 
@@ -90,14 +118,34 @@ module = "responses"
 ignore_missing_imports = true
 
 [[tool.mypy.overrides]]
+module = "selenium.*"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
 module = "soupmatchers"
 ignore_missing_imports = true
 
 [[tool.mypy.overrides]]
+module = "soupsieve"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
 module = "storm.*"
 ignore_missing_imports = true
 
 [[tool.mypy.overrides]]
+module = "subunit"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
+module = "swiftclient"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
+module = "talisker.*"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
 module = "testscenarios.*"
 ignore_missing_imports = true
 
@@ -122,6 +170,22 @@ module = "txfixtures.*"
 ignore_missing_imports = true
 
 [[tool.mypy.overrides]]
+module = "webob.*"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
+module = "webtest"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
+module = "wsgi_intercept"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
+module = "wsgiproxy.*"
+ignore_missing_imports = true
+
+[[tool.mypy.overrides]]
 module = "zope.*"
 ignore_missing_imports = true
 
diff --git a/requirements/types.txt b/requirements/types.txt
index 752d982..221aad3 100644
--- a/requirements/types.txt
+++ b/requirements/types.txt
@@ -2,6 +2,9 @@ lxml-stubs==0.4.0
 types-Markdown==0.1.0
 types-beautifulsoup4==4.9.0
 types-bleach==3.3.1
+types-oauthlib==3.1.0
+types-psycopg2==2.9.21.4
 types-pytz==0.1.0
 types-requests==0.1.13
 types-six==0.1.9
+types-urllib3==1.26.25.4
diff --git a/tox.ini b/tox.ini
index 83877d4..9054ea2 100644
--- a/tox.ini
+++ b/tox.ini
@@ -27,7 +27,7 @@ commands_pre =
     {toxinidir}/scripts/update-version-info.sh
 commands =
     mypy --follow-imports=silent \
-    {posargs:lib/lp/answers lib/lp/app lib/lp/archivepublisher lib/lp/archiveuploader lib/lp/buildmaster lib/lp/charms/model/charmrecipebuildbehaviour.py lib/lp/code/model/cibuildbehaviour.py lib/lp/code/model/recipebuilder.py lib/lp/oci/model/ocirecipebuildbehaviour.py lib/lp/snappy/model/snapbuildbehaviour.py lib/lp/soyuz/model/binarypackagebuildbehaviour.py lib/lp/soyuz/model/livefsbuildbehaviour.py lib/lp/translations/model/translationtemplatesbuildbehaviour.py}
+    {posargs:lib/lp/answers lib/lp/app lib/lp/archivepublisher lib/lp/archiveuploader lib/lp/buildmaster lib/lp/charms/model/charmrecipebuildbehaviour.py lib/lp/code/model/cibuildbehaviour.py lib/lp/code/model/recipebuilder.py lib/lp/oci/model/ocirecipebuildbehaviour.py lib/lp/snappy/model/snapbuildbehaviour.py lib/lp/soyuz/model/binarypackagebuildbehaviour.py lib/lp/soyuz/model/livefsbuildbehaviour.py lib/lp/testing lib/lp/translations/model/translationtemplatesbuildbehaviour.py}
 
 [testenv:docs]
 basepython = python3