Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to pathlib for tests #9578

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/functional/test_completion.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import textwrap
from os.path import curdir, join, pardir
from pathlib import Path

import pytest

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_install_reqs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import textwrap
from pathlib import Path

import pytest

Expand All @@ -13,7 +14,6 @@
requirements_file,
)
from tests.lib.local_repos import local_checkout
from tests.lib.path import Path


class ArgRecordingSdist:
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/test_install_vcs_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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.
"""
Expand All @@ -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.
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_install_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_list.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/test_new_resolver_target.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
28 changes: 16 additions & 12 deletions tests/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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('\\', '/')

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -478,8 +482,8 @@ def __init__(self, base_path, *args, virtualenv, pip_expect_warning=None, **kwar

# Setup our environment
environ = kwargs.setdefault("environ", os.environ.copy())
environ["PATH"] = Path.pathsep.join(
[self.bin_path] + [environ.get("PATH", [])],
environ["PATH"] = os.pathsep.join(
[str(self.bin_path)] + [environ.get("PATH", [])],
)
environ["PYTHONUSERBASE"] = self.user_base_path
# Writing bytecode can mess up updated file detection
Expand Down
3 changes: 1 addition & 2 deletions tests/lib/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/local_repos.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down