1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
Commit graph

355 commits

Author SHA1 Message Date
Jon Dufresne
8b24a66aa1 Set TestData.__test__ to False to avoid pytest discovery
As the class name starts with "Test", pytest interprets it as a test
case, but it is not one. Further, due to its `__init__` method, pytest
emits the following warning:

    .../pip/tests/lib/__init__.py:141: PytestCollectionWarning: cannot
    collect test class 'TestData' because it has a __init__ constructor

For additional information on pytest discovery, see:
https://docs.pytest.org/en/latest/example/pythoncollection.html
2021-09-05 13:51:46 -07:00
Jon Dufresne
9e88e8708f Replace assert_raises_regexp function with pytest.raises
These methods serve the same purpose. Can shift to using the upstream
implementation.

https://docs.pytest.org/en/latest/reference/reference.html#pytest.raises
2021-08-29 07:09:50 -07:00
Jon Dufresne
20d8d0bfe4 Remove unused method ConfigurationMixin.get_file_contents()
Unused since its introduction in
f9990605dc.
2021-08-28 09:21:53 -07:00
Pradyun Gedam
8899c25796
Merge pull request #10396 from jdufresne/more-test-mypy
Complete typing of some tests/lib/* files
2021-08-28 08:13:18 +01:00
Stéphane Bidoul
7aaea4e218
Merge pull request #10401 from jdufresne/files-to-clear
Remove unused ConfigurationMixin._files_to_clear
2021-08-27 19:52:46 +02:00
Jon Dufresne
34a3838b73 Complete typing of some tests/lib/* files 2021-08-27 09:25:22 -07:00
Jon Dufresne
d4a2f89fd1 Remove unused argument run_from from PipTestEnvironment.run() 2021-08-26 18:55:52 -07:00
Jon Dufresne
8271a5e288 Remove unused ConfigurationMixin._files_to_clear
The list is always empty.

Removing the unused attributes simplifies the mixin and avoids the need
to add a type annotation for it.

Unused since its introduction in
bd850c0798.
2021-08-26 11:59:03 -07:00
Tzu-ping Chung
135faabfd6
Remove direct pkg_resource usages from resolver and preparer 2021-08-23 02:07:33 +08: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
d144fd960c Cleanup several Python 2 version_info checks/workarounds 2021-08-20 09:39:31 -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
4d933d2e10
Use a stricter regex for matching the Python version
Co-authored-by: Kevin Puetz <puetzk@puetzk.org>
2021-08-06 15:55:55 +01:00
Pradyun Gedam
35b938b42e
Permit multi-character segments in Python versions, in a test
This is necessary since Python 3.10 has two digits in the minor version.
2021-08-06 13:42:31 +01:00
Pradyun Gedam
a196b3bf01
Minor formatting tweaks (#10190)
Co-authored-by: Pradyun Gedam <pradyunsg@users.noreply.github.com>
2021-07-24 03:55:14 +08:00
Tzu-ping Chung
e6c317769a Move assert_[not_]installed to Script and use it
This help function is much better than the previous ad-hoc logic used in
test_uninstall.py, which has trouble identifying normalized names.
2021-07-12 11:44:23 +08:00
Tzu-ping Chung
a31f8fd5ed Add failed test case 2021-04-19 08:31:28 +08:00
Paul Moore
cc3adad1b2 Don't use virtualenv internals in tests 2021-04-05 13:16:26 +01:00
Pradyun Gedam
37ad296684
Tweak textwrap.dedent strings 2021-04-02 12:00:01 +01:00
Pradyun Gedam
ebb80861ee
Blacken tests/lib 2021-04-02 11:59:57 +01:00
Jon Dufresne
6874e88ada Remove unnecessary method Path.__hash__
Only calls the parent implementation, so rely on inheritance.
2021-02-23 15:20:53 -08:00
Jon Dufresne
581868484b Use super() for Python 2 old-style classes
Followup to c148bcc1aa.
2021-02-23 15:20:52 -08:00
Andrey Bienkowski
e4e9af1d27 Drop python2 related stuff in tests 2021-02-23 13:49:59 +03:00
Pradyun Gedam
d541e4d789
Merge pull request #9593 from hexagonrecursion/strange-format
Refactor a confusing int to str conversion
2021-02-21 12:47:01 +00:00
Pradyun Gedam
c2ba7c043b
Merge pull request #9606 from hexagonrecursion/fstr 2021-02-21 08:30:00 +00: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
Tzu-ping Chung
5fac450375
Merge pull request #9368 from jdufresne/ensure
Remove unnecessary uses of six.ensure_(binary|str|text)
2021-02-18 20:40:21 +08:00
Tzu-ping Chung
4b3ecda35a
Merge pull request #9412 from jdufresne/kwargs
Use keyword-only arguments
2021-02-18 19:38:55 +08:00
Andrey Bienkowski
a9b8d12286
Apply review suggestion
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
2021-02-18 08:33:44 +00:00
Andrey Bienkowski
9b2cb894ba Convert more str.format() calls to f-strings 2021-02-13 09:27:17 +03:00
Andrey Bienkowski
45132fa7c9 Refactor a confusing int to str conversion 2021-02-10 14:42:28 +03: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
Jon Dufresne
8683413501 Use keyword-only arguments
https://www.python.org/dev/peps/pep-3102/

Replaces the pattern: self.name = kwargs.pop('name')

Keyword-only arguments offer some advantages:

- In the event of a typo or misuse, a more informative error is
  presented to the programmer.

- More self documenting and makes interfaces more explicit.

- They more easily allow explicit typing.

Adding types to ConfigOptionParser required changing some call sites to
pass arguments without using a dict due to mypy bug:
https://github.com/python/mypy/issues/9676
2021-01-29 21:15:36 -08:00
Xavier Fernandez
14830ae837
Merge pull request #9372 from jdufresne/devnull
Prefer subprocess.DEVNULL over open(os.devnull, 'w')
2021-01-07 11:58:08 +01: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
Jon Dufresne
50517b2171 Prefer subprocess.DEVNULL over open(os.devnull, 'w')
Available since Python 3.3.

https://docs.python.org/3/library/subprocess.html#subprocess.DEVNULL

Use a context manager for the other opened file, dump.
2020-12-27 08:37:08 -08:00
Jon Dufresne
14380668b5 Drop csv23 in favor of stdlib csv
Using csv23 has been unnecessary since dropping Python 2 support. It
previously remained as a compatibility shim.
2020-12-27 08:09:32 -08:00
Jon Dufresne
c115cdc81a Remove unnecessary uses of six.ensure_(binary|str|text)
Now that Python 2 is not supported, the bytes/str boundaries are more
clear and explicit. Using six.ensure_* methods for backwards
compatibility is no longer necessary as the types are known and verified
using mypy.

One exception is tests/lib/wheel.py which allows tests to pass test
setup data as either bytes or str.

The module operations.install.wheel also remains untouched as it is
especially delicate to bytes/str mixups and the current version is
working.
2020-12-27 07:56:18 -08:00
Hugo van Kemenade
a3e246f7d0 Cleanup: replace 'from urllib import xyz as urllib_xyz' with import urllib.xyz 2020-12-27 16:18:44 +02:00
Pradyun Gedam
86afa89043
Merge pull request #9361 from jdufresne/f-strings
Use f-strings for simple string formatting
2020-12-26 10:24:18 +00:00
Jon Dufresne
cdcf74fb8e Use f-strings for simple string formatting
Use pyupgrade to convert simple string formatting to use f-string
syntax. pyupgrade is intentionally timid and will not create an f-string
if it would make the expression longer or if the substitution parameters
are anything but simple names or dotted names.
2020-12-25 16:21:20 -08:00
Jon Dufresne
09b3d3a50b Remove object from class definitions
Unnecessary since dropping Python 2 support. In Python 3, all classes
are new style classes.
2020-12-25 15:48:11 -08: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
ba40f58ecc Remove encoding cookie from Python source files
Unnecessary since dropping Python 2. Python now decodes files as utf-8
by default.
2020-12-25 07:26:07 -08: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
Jon Dufresne
f32adaf09b Remove __future__ imports
Unnecessary since dropping Python 2.
2020-12-24 08:38:09 -08:00
Hugo van Kemenade
9db97546b3 os.curdir is already a str
Co-authored-by: Jon Dufresne <jon.dufresne@gmail.com>
2020-12-22 22:41:58 +02:00
Hugo van Kemenade
33f48e2b72 Replace more six 2020-12-22 10:22:20 +02:00
Hugo van Kemenade
817ee23051 Remove redundant Python 2.7 code 2020-12-22 09:06:26 +02: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
5b1093fc75 Use monkeypatch.*env in conftest and tests.lib
Session fixtures have to use mock.patch.dict though
2020-07-25 20:46:45 +07:00
c564a3d541 Use monkeypatch.setenv in config and option tests 2020-07-25 20:46:45 +07:00
Pradyun Gedam
fa2fceecf1
Merge pull request #8189 from gutsytechster/remove_raise_for_status 2020-07-15 18:06:27 +05:30
Prashant Sharma
07e8712677
reformat(pip/_internal): Resolve lint errors 2020-07-09 15:15:01 +05:30
gutsytechster
8c267e6e39
feat(pip/_internal/*): Use custom raise_for_status method 2020-07-08 18:08:55 +05:30
Chris Hunt
a365764e57 Add test for RECORD population by make_wheel 2020-07-07 09:25:16 -04:00
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
Pradyun Gedam
18431be48f
Merge pull request #8467 from McSinyx/lazy-wheel 2020-06-30 13:39:04 +00:00
25a25a0975 Test network.lazy_wheel.dist_from_wheel_url 2020-06-26 15:15:28 +07: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
Devesh Kumar Singh
db11f83e2a Fix tests module with flake8-bugbear 2020-06-05 02:41:08 +05:30
Sumana Harihareswara
cef69fef7f Updated author email in configuration and tests
Per https://groups.google.com/d/msg/pypa-dev/rUNsfIbruHM/LCEx-CB5AgAJ
the pypa-dev Google Group is now decommissioned.
Using distutils-sig instead as author/maintainer email.

Signed-off-by: Sumana Harihareswara <sh@changeset.nyc>
2020-05-28 16:51:02 -04:00
Pradyun Gedam
2552151858
Add helpers to TestPipResult 2020-05-22 17:27:44 +05:30
Paul Moore
80c640b5a8
Merge pull request #8067 from deveshks/fix-create-basic-wheel-bug
Canonicalise package name in tests.lib.create_basic_wheel_for_package
2020-05-21 13:54:01 +01:00
Pradyun Gedam
1b90e1bccf
Revert "remove _copy_source_tree and friends"
This reverts commit 873f1e6332.
2020-05-13 02:50:10 +05:30
Pradyun Gedam
09a5af52e4
Merge pull request #8125 from uranusjr/yanked-link-warning-relocate 2020-05-05 16:15:52 +05:30
Ilan Schnell
28b0fd353b add allow_error parameter to .run() method 2020-04-28 22:49:18 -05:00
Tzu-ping Chung
367e6617bd Move yanked message unit tests to use resolver 2020-04-25 03:53:53 +08:00
Devesh Kumar Singh
7bcccbd3dc Canonicalise package name in tests.lib.create_basic_wheel_for_package 2020-04-17 01:21:51 +05:30
Stéphane Bidoul
873f1e6332
remove _copy_source_tree and friends 2020-04-12 12:00:57 +02:00
Paul Moore
037791d170 Add a test demonstrating #7966 2020-04-03 11:18:44 +01:00
Tzu-ping Chung
22f7c883ad Requires-Python support in test helper 2020-04-02 18:38:43 +08:00
Paul Moore
ac26f1bc33
Merge pull request #7934 from uranusjr/create_basic_wheel_for_package_improve
Rewrite tests.lib.create_basic_wheel_for_package
2020-04-02 11:25:36 +01:00
Tzu-ping Chung
09f4d0004b Use extra_files to write package files instead 2020-04-02 01:25:05 +08:00
Ilan Schnell
2a8f5705b2 combine yaml test functionality into single module 2020-03-31 15:35:29 -05:00
Ilan Schnell
2c6a063a27 remove proxy module tests/lib/scripttest.py in favour of importing from tests.lib directly 2020-03-31 01:25:45 -05:00
Tzu-ping Chung
2c8a0bff42 Rewrite tests.lib.create_basic_wheel_for_package
This implementation uses tests.lib.make_wheel, which allows more
flexible wheel configuration in a more structured way.

Output-wise this should be almost identical to the previous
implementation, with the following exceptions:

* Metadata-Version is bumped from 2.0 (previous implementation) to 2.1
  (from make_wheel).
* Fields previously supplied as UNKNOWN are now omitted since they are
  not significant to tests.
* The DESCRIPTION file is omitted (since the description field is now
  missing, see previous point).
2020-03-30 03:20:00 +08:00
gutsytechster
315447d170 fix(tests/lib): Catch subprocess.CalledProcessError in need_executable
This fixes https://github.com/pypa/pip/issues/7924
2020-03-29 16:21:02 +05:30
Pradyun Gedam
4d1932fcdd
Merge pull request #7826 from jaraco/bugfix/6973-format-method
Convert the remaining '%' formatters to '.format'.
2020-03-10 14:58:25 +05:30
Prashant Sharma
115a83698f
fix(tests/lib/path): Remove duplicate resolve method (#7837) 2020-03-09 23:29:27 +01:00
Jason R. Coombs
fd288ab0e5 Merge remote-tracking branch 'origin/master' into bugfix/6973-format-method 2020-03-06 18:17:10 -05:00
Jason R. Coombs
3511d3d493 Convert the remaining '%' formatters to '.format'. Fixes #6973. 2020-03-06 12:43:03 -05:00
Jason R. Coombs
2c0d691893 Skip svn tests if svnadmin is not available. Fixes #7823. 2020-03-06 04:09:48 -05:00
Chris Hunt
6d8a58f7e1 Add wheel builder test helper
As we introduce stricter metadata parsing, we will need to ensure that
the wheel files used in our tests are compliant (except in the specific
way that we're testing against).

Currently we have a large number of test cases relying on undocumented or
under-documented wheel files that have various inconsistencies
(incorrect name, missing fields) that are unrelated to the features
actually under test.

With a new wheel builder helper function, we will be able to replace all
of our instances of pre-built wheel test fixtures with dynamically-generated
files in code that are correct by default.
2020-01-31 19:30:19 -05:00
Chris Hunt
dd8753cdee Mitigate Windows test failures due to PAX-format wheel release 2020-01-29 08:53:23 -05:00
Tzu-ping Chung
facf5c8894 Add comments to unicode workarounds 2020-01-09 13:11:30 +05:30
Tzu-ping Chung
7a80acaf44 Tell shutil.make_archive to use Unicode paths
By default, make_archive uses str paths on Python 2, which causes it to
skip files with unencodable names. By passing in a unicode base_dir
explicitly, it is smart enough to use unicode all the way down instead.
2020-01-09 13:01:31 +05:30
Chris Hunt
33043ba22f Use pkg_resources.Distribution derived from wheel directly
We now extract all metadata files from the wheel directly into memory
and make them available to the wrapping pkg_resources.Distribution via
the DictMetadata introduced earlier.
2020-01-05 10:57:14 -05:00
Chris Hunt
b58205ea01 Use valid wheel for functional download tests
Previously we were copying an existing wheel to a file with a
different distribution name. When using stricter metadata parsing this
would fail, so now we use a more conformant dummy wheel function.
2020-01-04 23:08:43 +01:00
Chris Hunt
b65bd4c31a Remove unused args parameter from _git_commit 2020-01-03 19:24:22 -05:00
Chris Hunt
5665b94a5b Make explicit argument for git commit -a 2020-01-03 19:21:36 -05:00