Skip to content

Commit

Permalink
Change to pathlib for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Apr 1, 2021
1 parent ade7220 commit e9a68bb
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 34 deletions.
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
24 changes: 14 additions & 10 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
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
3 changes: 1 addition & 2 deletions tests/lib/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/lib/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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[
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_operations_prepare.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_self_check_outdated.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
import sys
from pathlib import Path

import freezegun
import pretend
Expand All @@ -16,7 +17,6 @@
logger,
pip_self_version_check,
)
from tests.lib.path import Path


class MockBestCandidateResult:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_utils_filesystem.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_utils_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e9a68bb

Please sign in to comment.