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

Switch to Pathlib in tests #6326

Closed
wants to merge 1 commit 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
16 changes: 8 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ def not_code_files_and_folders(path, names):
ignored.extend(fnmatch.filter(names, pattern))
return set(ignored)

pip_src = Path(str(tmpdir_factory.mktemp('pip_src'))).join('pip_src')
pip_src = Path(str(tmpdir_factory.mktemp('pip_src'))).joinpath('pip_src')
# Copy over our source tree so that each use is self contained
shutil.copytree(
SRC_DIR,
pip_src.abspath,
pip_src.absolute(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a str() wraparound

ignore=not_code_files_and_folders,
)
return pip_src
Expand Down Expand Up @@ -231,12 +231,12 @@ def virtualenv_template(request, tmpdir_factory, pip_src,

# Create the virtual environment
tmpdir = Path(str(tmpdir_factory.mktemp('virtualenv')))
venv = VirtualEnvironment(tmpdir.join("venv_orig"), venv_type=venv_type)
venv = VirtualEnvironment(tmpdir.joinpath("venv_orig"), venv_type=venv_type)

# Install setuptools and pip.
install_egg_link(venv, 'setuptools', setuptools_install)
pip_editable = Path(str(tmpdir_factory.mktemp('pip'))) / 'pip'
pip_src.copytree(pip_editable)
shutil.copytree(str(pip_src), str(pip_editable))
assert compileall.compile_dir(str(pip_editable), quiet=1)
subprocess.check_call([venv.bin / 'python', 'setup.py', '-q', 'develop'],
cwd=pip_editable)
Expand Down Expand Up @@ -267,7 +267,7 @@ def virtualenv(virtualenv_template, tmpdir, isolate):
temporary directory. The returned object is a
``tests.lib.venv.VirtualEnvironment`` object.
"""
venv_location = tmpdir.join("workspace", "venv")
venv_location = tmpdir.joinpath("workspace", "venv")
yield VirtualEnvironment(venv_location, virtualenv_template)


Expand All @@ -286,7 +286,7 @@ def script(tmpdir, virtualenv, deprecated_python):
"""
return PipTestEnvironment(
# The base location for our test environment
tmpdir.join("workspace"),
tmpdir.joinpath("workspace"),

# Tell the Test Environment where our virtualenv is located
virtualenv=virtualenv,
Expand All @@ -310,12 +310,12 @@ def script(tmpdir, virtualenv, deprecated_python):
@pytest.fixture(scope="session")
def common_wheels():
"""Provide a directory with latest setuptools and wheel wheels"""
return DATA_DIR.join('common_wheels')
return DATA_DIR.joinpath('common_wheels')


@pytest.fixture
def data(tmpdir):
return TestData.copy(tmpdir.join("data"))
return TestData.copy(tmpdir.joinpath("data"))


class InMemoryPipResult(object):
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def test_install_editable_uninstalls_existing(data, script, tmpdir):
'%s#egg=pip-test-package' %
local_checkout(
'git+https://github.com/pypa/pip-test-package.git',
tmpdir.join("cache"),
tmpdir.joinpath("cache"),
),
)
result.assert_installed('pip-test-package', with_files=['.git'])
Expand Down Expand Up @@ -360,7 +360,7 @@ def test_vcs_url_urlquote_normalization(script, tmpdir):
local_checkout(
'bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp'
'/release-0.1',
tmpdir.join("cache"),
tmpdir.joinpath("cache"),
),
)

Expand Down Expand Up @@ -615,7 +615,7 @@ def test_install_using_install_option_and_editable(script, tmpdir):
url = 'git+git://github.com/pypa/pip-test-package'
result = script.pip(
'install', '-e', '%s#egg=pip-test-package' %
local_checkout(url, tmpdir.join("cache")),
local_checkout(url, tmpdir.joinpath("cache")),
'--install-option=--script-dir=%s' % folder,
expect_stderr=True)
script_file = (
Expand All @@ -634,7 +634,7 @@ def test_install_global_option_using_editable(script, tmpdir):
url = 'hg+http://bitbucket.org/runeh/anyjson'
result = script.pip(
'install', '--global-option=--version', '-e',
'%s@0.2.5#egg=anyjson' % local_checkout(url, tmpdir.join("cache")),
'%s@0.2.5#egg=anyjson' % local_checkout(url, tmpdir.joinpath("cache")),
expect_stderr=True)
assert 'Successfully installed anyjson' in result.stdout

Expand Down Expand Up @@ -1136,7 +1136,7 @@ def test_install_subprocess_output_handling(script, data):

def test_install_log(script, data, tmpdir):
# test that verbose logs go to "--log" file
f = tmpdir.join("log.txt")
f = tmpdir.joinpath("log.txt")
args = ['--log=%s' % f,
'install', data.src.join('chattymodule')]
result = script.pip(*args)
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_install_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_cleanup_after_install_editable_from_hg(script, tmpdir):
'%s#egg=ScriptTest' %
local_checkout(
'hg+https://bitbucket.org/ianb/scripttest',
tmpdir.join("cache"),
tmpdir.joinpath("cache"),
),
expect_error=True,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_install_reqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_multiple_requirements_files(script, tmpdir):
(
local_checkout(
'svn+http://svn.colorstudy.com/INITools/trunk',
tmpdir.join("cache"),
tmpdir.joinpath("cache"),
),
other_lib_name
),
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_install_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def test_upgrade_vcs_req_with_no_dists_found(script, tmpdir):
"""It can upgrade a VCS requirement that has no distributions otherwise."""
req = "%s#egg=pip-test-package" % local_checkout(
"git+https://github.com/pypa/pip-test-package.git",
tmpdir.join("cache"),
tmpdir.joinpath("cache"),
)
script.pip("install", req)
result = script.pip("install", "-U", req)
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_install_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_install_subversion_usersite_editable_with_distribute(
'%s#egg=initools' %
local_checkout(
'svn+http://svn.colorstudy.com/INITools/trunk',
tmpdir.join("cache"),
tmpdir.joinpath("cache"),
)
)
result.assert_installed('INITools', use_user_site=True)
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def test_uninstall_editable_from_svn(script, tmpdir):
'install', '-e',
'%s#egg=initools' % local_checkout(
'svn+http://svn.colorstudy.com/INITools/trunk',
tmpdir.join("cache"),
tmpdir.joinpath("cache"),
),
)
result.assert_installed('INITools')
Expand All @@ -318,7 +318,7 @@ def test_uninstall_editable_with_source_outside_venv(script, tmpdir):
Test uninstalling editable install from existing source outside the venv.

"""
cache_dir = tmpdir.join("cache")
cache_dir = tmpdir.joinpath("cache")

try:
temp = mkdtemp()
Expand Down Expand Up @@ -371,7 +371,7 @@ def test_uninstall_from_reqs_file(script, tmpdir):
""") %
local_checkout(
'svn+http://svn.colorstudy.com/INITools/trunk',
tmpdir.join("cache")
tmpdir.joinpath("cache")
)
)
result = script.pip('install', '-r', 'test-req.txt')
Expand All @@ -388,7 +388,7 @@ def test_uninstall_from_reqs_file(script, tmpdir):
""") %
local_checkout(
'svn+http://svn.colorstudy.com/INITools/trunk',
tmpdir.join("cache")
tmpdir.joinpath("cache")
)
)
result2 = script.pip('uninstall', '-r', 'test-req.txt', '-y')
Expand Down Expand Up @@ -425,7 +425,7 @@ def test_uninstallpathset_no_paths(caplog):


def test_uninstall_non_local_distutils(caplog, monkeypatch, tmpdir):
einfo = tmpdir.join("thing-1.0.egg-info")
einfo = tmpdir.joinpath("thing-1.0.egg-info")
with open(einfo, "wb"):
pass

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def test_environ(script, tmpdir):
"""$PYTHONWARNINGS was added in python2.7"""
demo = tmpdir.join('warnings_demo.py')
demo = tmpdir.joinpath('warnings_demo.py')
demo.write(textwrap.dedent('''
from logging import basicConfig
from pip._internal.utils import deprecation
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def handle_install_request(script, requirement):

@pytest.mark.yaml
@pytest.mark.parametrize(
"case", generate_yaml_tests(DATA_DIR.folder / "yaml"), ids=id_func
"case", generate_yaml_tests(DATA_DIR.parent / "yaml"), ids=id_func
)
def test_yaml_based(script, case):
available = case.get("available", [])
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

from tests.lib.path import Path, curdir

DATA_DIR = Path(__file__).folder.folder.join("data").abspath
SRC_DIR = Path(__file__).abspath.folder.folder.folder
DATA_DIR = Path(__file__).parent.parent.joinpath("data").absolute()
SRC_DIR = Path(__file__).absolute().parent.parent.parent

pyversion = sys.version[:3]
pyversion_tuple = sys.version_info
Expand Down Expand Up @@ -79,7 +79,7 @@ class TestData(object):

def __init__(self, root, source=None):
self.source = source or DATA_DIR
self.root = Path(root).abspath
self.root = Path(root).absolute()

@classmethod
def copy(cls, root):
Expand All @@ -88,8 +88,8 @@ def copy(cls, root):
return obj

def reset(self):
self.root.rmtree()
self.source.copytree(self.root)
shutil.rmtree(str(self.root))
shutil.copytree(str(self.source), str(self.root))

@property
def packages(self):
Expand Down