Commit Graph

29 Commits

Author SHA1 Message Date
Damian Shaw 68529081c2
Enforce f-strings via Ruff (#12393) 2023-11-07 09:14:56 +00:00
Tzu-ping Chung c3160c5423 Avoid importing things from conftest
It is generally discouraged to import from conftest. Things are now
moved to tests.lib and imported from there instead.

Also did some cleanup to remove the no-longer-needed nullcontext shim.
2023-05-09 15:43:53 +08:00
Danny McClanahan bad03ef931
Use data-dist-info-metadata (PEP 658) to decouple resolution from downloading (#11111)
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
2022-09-10 11:28:57 +01:00
Tzu-ping Chung 42359a9605 Migrate tests to use pathlib.Path
The pip-specific Path implementation has been removed, and all its
usages replaced by pathlib.Path. The tmpdir and tmpdir_factory fixtures
are also removed, and all usages are replaced by tmp_path and
tmp_path_factory, which use pathlib.Path.

The pip() function now also accepts pathlib.Path so we don't need to put
str() everywhere. Path arguments are coerced with os.fspath() into str.
2022-06-08 19:58:46 +08:00
Tzu-ping Chung 1181b22119 Apply mypy config override to blocked_signals 2021-11-22 17:05:15 +08:00
Tzu-ping Chung 7d27b9c412 Fix various typing errors on Windows 2021-11-22 15:55:31 +08:00
Jon Dufresne 72937f6520 Complete type annotations for tests/conftest.py and tests/lib/* 2021-09-29 19:57:29 -07:00
Jon Dufresne 943af79f26 Run mypy on the tests directory
The tests are a large consumer of the pip API (both the internal API and
otherwise). By running mypy on tests, we help to:

1. Ensure the internal API is consistent with regards to typing

2. Ensure the tests are representative of real life scenarios as the API
   are used correctly.

3. Helps to recognize unnecessary tests that simply pass junk data to
   functions which can be caught by the type checker.

4. Make sure test support code in tests/lib/ is correct and consistent.
   This is especially important when refactoring such code. For example, if
   we were to replace tests/lib/path.py with pathlib.

As a first start, untyped defs are allowed. All existing typing issues
have been resolved. Overtime, we can chip away at untyped defs and
eventually remove the configuration option for stricter type checking of
tests.

The following changes were made to help make mypy pass:

Remove unused record_callback argument from make_wheel() in tests.
Unused since its introduction in
6d8a58f7e1.

Replace toml with tomli_w in tests/functional/test_pep517.py. Unlike the
toml package, tomli_w contains inline typing annotations.

Remove unnecessary make_no_network_finder(). Unnecessary since
bab1e4f8a1 where the _get_pages method was
removed.
2021-08-22 09:57:26 -06:00
Jon Dufresne 6a6561c2cb Move many type comments to annotations
Use the tool com2ann to automatically convert most type comments to type
annotations. Some type comments continue to exist where any work beyond
the automatic conversion was required (for example, additional
formatting or circular references).

For additional information on the com2ann tool, see:
https://github.com/ilevkivskyi/com2ann
2021-08-10 07:12:32 -07:00
Pradyun Gedam ebb80861ee
Blacken tests/lib 2021-04-02 11:59:57 +01:00
Jon Dufresne 0945809afc Remove typing.TYPE_CHECKING guards
The typing module has been available since Python 3.5. Guarding the
import has been unnecessary since dropping Python 2.

Some guards remain to either:

- Avoid circular imports
- Importing objects that are also guarded by typing.TYPE_CHECKING
- Avoid mypy_extensions dependency
2021-02-19 18:34:21 -08:00
Jon Dufresne d9b5525193 Prefer stdlib contextlib over contextlib2 when available
Removes the vendored contextlib2.

ExitStack and suppress are available from stdlib contextlib on all
supported Python versions.

The nullcontext context manager which isn't available in Python 3.6, but
the function is simple to implement. Once Python 3.6 support is dropped,
so too can the compat shim.
2021-02-19 04:13:33 -08:00
Jon Dufresne a6392bd62e Replace pip._internal.utils.typing with stdlib typing
The stdlib module has been available since Python 3.5 and the
TYPE_CHECKING constant has been available since 3.5.2.

By using stdlib, this removes the need for pip to maintain its own
Python 2 typing compatibility shim.
2021-02-18 19:09:13 -08:00
Tzu-ping Chung 62af9563ca
Merge pull request #8687 from hroncok/keyring_madness 2021-02-19 00:59:50 +08:00
Andrey Bienkowski 50db373adb Lint 2021-02-10 13:38:21 +03:00
Andrey Bienkowski ab35018c04 Use unittest.mock instead of mock 2021-02-10 13:28:55 +03:00
Miro Hrončok 886275de2d Only query the keyring for URLs that actually trigger error 401
Fixes https://github.com/pypa/pip/issues/8090
2021-01-04 17:47:56 +01:00
Pradyun Gedam f91ba6b348
Merge pull request #9354 from jdufresne/super
Use short Python3 super() syntax
2020-12-25 19:18:28 +00:00
Jon Dufresne 2e38024991 Drop u prefix from str literals
Unnecessary since dropping Python 2 support.

This makes one test case from test_str_to_display a duplicate and so has
been removed.
2020-12-25 07:26:06 -08:00
Jon Dufresne 5e11687cbd Replace typing.Text with str
Using typing.Text is unnecessary since dropping Python 2 support.

In Python 3, typing.Text is a simple alias of str. It exists as a
backward compatibility shim for Python 2.
2020-12-24 16:40:55 -08:00
Jon Dufresne c148bcc1aa Use short Python3 super() syntax 2020-12-24 15:11:51 -08:00
Pradyun Gedam 16c3205184
Add a better error message for no-more-responses 2020-10-30 23:08:59 +05:30
Pradyun Gedam 25ab172b55
Update linter: isort 2020-09-23 19:52:28 +05:30
Christopher Hunt 4645ecbdb0
Merge pull request #8447 from jku/use-valid-signals-on-py38
test server: Don't mask invalid signals on py38
2020-07-02 12:03:11 -04:00
Jussi Kukkonen 23ec070cf1
test server: use set of signals
This is what signal.pthread_sigmask() really wants and matches signal.valid_signals() output

Co-authored-by: Christopher Hunt <chrahunt@gmail.com>
2020-07-02 18:00:29 +03:00
Devesh Kumar Singh 6119a837ea Add unit tests for --no-input flag 2020-06-26 07:21:45 +05:30
Jussi Kukkonen dd42e7ec25 test server: Don't mask invalid signals on py38
This removes warnings from test output in python 3.8:

  /usr/lib/python3.8/signal.py:60: RuntimeWarning:
  invalid signal number 32, please use valid_signals()
2020-06-16 17:58:44 +03:00
Chris Hunt 31f49023bd Add mock_server documentation 2019-11-17 16:12:17 -05:00
Chris Hunt 204a004377 Add test helpers for HTTP(S) server and certs 2019-11-03 17:05:52 -05:00