diff --git a/tests/conftest.py b/tests/conftest.py index 9d1ee4443b9..e5945388bab 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,6 +8,7 @@ import sys import time from contextlib import ExitStack, contextmanager +from pathlib import Path from typing import Dict, Iterable from unittest.mock import patch @@ -18,7 +19,6 @@ from pip._internal.utils.temp_dir import global_tempdir_manager from tests.lib import DATA_DIR, SRC_DIR, PipTestEnvironment, TestData from tests.lib.certs import make_tls_cert, serialize_cert, serialize_key -from tests.lib.path import Path from tests.lib.server import MockServer as _MockServer from tests.lib.server import Responder, make_mock_server, server_running from tests.lib.venv import VirtualEnvironment @@ -136,7 +136,7 @@ def tmpdir(request, tmpdir): """ Return a temporary directory path object which is unique to each test function invocation, created as a sub directory of the base temporary - directory. The returned object is a ``tests.lib.path.Path`` object. + directory. The returned object is a ``pathlib.Path`` object. This uses the built-in tmpdir fixture from pytest itself but modified to return our typical path object instead of py.path.local as well as diff --git a/tests/functional/test_completion.py b/tests/functional/test_completion.py index 8a7464982ee..a75574319e3 100644 --- a/tests/functional/test_completion.py +++ b/tests/functional/test_completion.py @@ -1,10 +1,9 @@ import os import sys +from pathlib import Path import pytest -from tests.lib.path import Path - COMPLETION_FOR_SUPPORTED_SHELLS_TESTS = ( ('bash', """\ _pip_completion() diff --git a/tests/functional/test_download.py b/tests/functional/test_download.py index 21715734314..0d1e367e7a6 100644 --- a/tests/functional/test_download.py +++ b/tests/functional/test_download.py @@ -2,13 +2,13 @@ import shutil import textwrap from hashlib import sha256 +from pathlib import Path import pytest from pip._internal.cli.status_codes import ERROR from pip._internal.utils.urls import path_to_url from tests.lib import create_really_basic_wheel -from tests.lib.path import Path from tests.lib.server import file_response diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 2742e873e33..d3b3b9b47b8 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -7,6 +7,7 @@ import sys import textwrap from os.path import curdir, join, pardir +from pathlib import Path import pytest @@ -27,7 +28,6 @@ ) from tests.lib.filesystem import make_socket_file from tests.lib.local_repos import local_checkout -from tests.lib.path import Path from tests.lib.server import ( file_response, make_mock_server, diff --git a/tests/functional/test_install_reqs.py b/tests/functional/test_install_reqs.py index d559e94be18..db5b39e0f40 100644 --- a/tests/functional/test_install_reqs.py +++ b/tests/functional/test_install_reqs.py @@ -1,6 +1,7 @@ import json import os import textwrap +from pathlib import Path import pytest @@ -13,7 +14,6 @@ requirements_file, ) from tests.lib.local_repos import local_checkout -from tests.lib.path import Path class ArgRecordingSdist: diff --git a/tests/functional/test_install_vcs_git.py b/tests/functional/test_install_vcs_git.py index afd6ffae055..981bd9b5e42 100644 --- a/tests/functional/test_install_vcs_git.py +++ b/tests/functional/test_install_vcs_git.py @@ -73,7 +73,7 @@ def _make_version_pkg_url(path, rev=None, name="version_pkg"): Return a "git+file://" URL to the version_pkg test package. Args: - path: a tests.lib.path.Path object pointing to a Git repository + path: a pathlib.Path object pointing to a Git repository containing the version_pkg package. rev: an optional revision to install like a branch name, tag, or SHA. """ @@ -90,7 +90,7 @@ def _install_version_pkg_only(script, path, rev=None, expect_stderr=False): the version). Args: - path: a tests.lib.path.Path object pointing to a Git repository + path: a pathlib.Path object pointing to a Git repository containing the package. rev: an optional revision to install like a branch name or tag. """ @@ -104,7 +104,7 @@ def _install_version_pkg(script, path, rev=None, expect_stderr=False): installed. Args: - path: a tests.lib.path.Path object pointing to a Git repository + path: a pathlib.Path object pointing to a Git repository containing the package. rev: an optional revision to install like a branch name or tag. """ diff --git a/tests/functional/test_install_wheel.py b/tests/functional/test_install_wheel.py index 8df208bb7da..ee7150ceece 100644 --- a/tests/functional/test_install_wheel.py +++ b/tests/functional/test_install_wheel.py @@ -3,11 +3,11 @@ import glob import os import shutil +from pathlib import Path import pytest from tests.lib import create_basic_wheel_for_package -from tests.lib.path import Path from tests.lib.wheel import make_wheel diff --git a/tests/functional/test_list.py b/tests/functional/test_list.py index 40dfbdea30d..7150fae4d58 100644 --- a/tests/functional/test_list.py +++ b/tests/functional/test_list.py @@ -1,10 +1,10 @@ import json import os +from pathlib import Path import pytest from tests.lib import create_test_package_with_setup, wheel -from tests.lib.path import Path @pytest.fixture(scope="session") diff --git a/tests/functional/test_new_resolver_target.py b/tests/functional/test_new_resolver_target.py index f5ec6ac7a09..d0e433d8812 100644 --- a/tests/functional/test_new_resolver_target.py +++ b/tests/functional/test_new_resolver_target.py @@ -1,7 +1,8 @@ +from pathlib import Path + import pytest from pip._internal.cli.status_codes import ERROR, SUCCESS -from tests.lib.path import Path from tests.lib.wheel import make_wheel diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py index 98474dda46f..bd36a79d40a 100644 --- a/tests/lib/__init__.py +++ b/tests/lib/__init__.py @@ -9,6 +9,7 @@ from contextlib import contextmanager from hashlib import sha256 from io import BytesIO +from pathlib import Path from textwrap import dedent from typing import List, Optional from zipfile import ZipFile @@ -24,7 +25,6 @@ from pip._internal.models.target_python import TargetPython from pip._internal.network.session import PipSession from pip._internal.utils.deprecation import DEPRECATION_MSG_PREFIX -from tests.lib.path import Path, curdir from tests.lib.wheel import make_wheel DATA_DIR = Path(__file__).parent.parent.joinpath("data").resolve() @@ -61,7 +61,7 @@ def _test_path_to_file_url(path): Convert a test Path to a "file://" URL. Args: - path: a tests.lib.path.Path object. + path: a pathlib.Path object. """ return 'file://' + path.resolve().replace('\\', '/') @@ -317,14 +317,18 @@ def assert_installed(self, pkg_name, editable=True, with_files=None, f'{pth_file} unexpectedly {maybe}updated by install' ) - if (pkg_dir in self.files_created) == (curdir in without_files): - maybe = 'not ' if curdir in without_files else '' - files = sorted(self.files_created) - raise TestFailure(textwrap.dedent(f'''\ - expected package directory {pkg_dir!r} {maybe}to be created - actually created: - {files} - ''')) + if (pkg_dir in self.files_created) == (Path(os.curdir) in without_files): + raise TestFailure(textwrap.dedent( + ''' + expected package directory {pkg_dir!r} {maybe}to be created + actually created: + {files} + ''' + ).format( + pkg_dir=pkg_dir, + maybe=Path(os.curdir) in without_files and 'not ' or '', + files=sorted(self.files_created.keys()), + )) for f in with_files: normalized_path = os.path.normpath(pkg_dir / f) diff --git a/tests/lib/filesystem.py b/tests/lib/filesystem.py index dc14b323e33..aac3c28d0cc 100644 --- a/tests/lib/filesystem.py +++ b/tests/lib/filesystem.py @@ -6,8 +6,7 @@ import sys from functools import partial from itertools import chain - -from .path import Path +from pathlib import Path def make_socket_file(path): diff --git a/tests/lib/local_repos.py b/tests/lib/local_repos.py index 0aa75787e0c..516e9f743b5 100644 --- a/tests/lib/local_repos.py +++ b/tests/lib/local_repos.py @@ -1,11 +1,11 @@ import os import subprocess import urllib.request +from pathlib import Path from pip._internal.utils.misc import hide_url from pip._internal.vcs import vcs from tests.lib import path_to_url -from tests.lib.path import Path def _create_svn_initools_repo(initools_dir): diff --git a/tests/lib/venv.py b/tests/lib/venv.py index bd6426a81b8..20732c85fbe 100644 --- a/tests/lib/venv.py +++ b/tests/lib/venv.py @@ -3,11 +3,10 @@ import sys import textwrap import venv as _venv +from pathlib import Path import virtualenv as _virtualenv -from .path import Path - class VirtualEnvironment: """ diff --git a/tests/lib/wheel.py b/tests/lib/wheel.py index e88ce8c6101..4d9b8ae3482 100644 --- a/tests/lib/wheel.py +++ b/tests/lib/wheel.py @@ -10,6 +10,7 @@ from functools import partial from hashlib import sha256 from io import BytesIO, StringIO +from pathlib import Path from typing import ( AnyStr, Callable, @@ -26,8 +27,6 @@ from pip._vendor.requests.structures import CaseInsensitiveDict -from tests.lib.path import Path - # path, digest, size RecordLike = Tuple[str, str, str] RecordCallback = Callable[ diff --git a/tests/unit/test_operations_prepare.py b/tests/unit/test_operations_prepare.py index 4d912fb6eac..02caa6380ee 100644 --- a/tests/unit/test_operations_prepare.py +++ b/tests/unit/test_operations_prepare.py @@ -1,5 +1,6 @@ import os import shutil +from pathlib import Path from shutil import rmtree from tempfile import mkdtemp from unittest.mock import Mock, patch @@ -14,7 +15,6 @@ from pip._internal.utils.hashes import Hashes from pip._internal.utils.urls import path_to_url from tests.lib.filesystem import get_filelist, make_socket_file, make_unreadable_file -from tests.lib.path import Path from tests.lib.requests_mocks import MockResponse diff --git a/tests/unit/test_self_check_outdated.py b/tests/unit/test_self_check_outdated.py index 546e05d98ac..2b3c8a85922 100644 --- a/tests/unit/test_self_check_outdated.py +++ b/tests/unit/test_self_check_outdated.py @@ -3,6 +3,7 @@ import json import os import sys +from pathlib import Path import freezegun import pretend @@ -16,7 +17,6 @@ logger, pip_self_version_check, ) -from tests.lib.path import Path class MockBestCandidateResult: diff --git a/tests/unit/test_utils_filesystem.py b/tests/unit/test_utils_filesystem.py index 3ef814dce4b..8ec16013bbc 100644 --- a/tests/unit/test_utils_filesystem.py +++ b/tests/unit/test_utils_filesystem.py @@ -1,11 +1,11 @@ import os import shutil +from pathlib import Path import pytest from pip._internal.utils.filesystem import copy2_fixed, is_socket from tests.lib.filesystem import make_socket_file, make_unreadable_file -from tests.lib.path import Path def make_file(path): diff --git a/tests/unit/test_utils_wheel.py b/tests/unit/test_utils_wheel.py index 878d8d777e5..d9ce6c39d14 100644 --- a/tests/unit/test_utils_wheel.py +++ b/tests/unit/test_utils_wheel.py @@ -2,13 +2,13 @@ from contextlib import ExitStack from email import message_from_string from io import BytesIO +from pathlib import Path from zipfile import ZipFile import pytest from pip._internal.exceptions import UnsupportedWheel from pip._internal.utils import wheel -from tests.lib.path import Path @pytest.fixture