Skip to content

Commit

Permalink
Make the unit tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Feb 21, 2021
1 parent e09b190 commit 9a3ed71
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions tests/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ def __init__(self, base_path, *args, **kwargs):

# 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
3 changes: 2 additions & 1 deletion tests/unit/resolution_resolvelib/test_requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@pytest.fixture
def test_cases(data):
def data_file(name):
return data.packages.joinpath(name)
return str(data.packages.joinpath(name))

def data_url(name):
return path_to_url(data_file(name))
Expand Down Expand Up @@ -61,6 +61,7 @@ def test_new_resolver_correct_number_of_matches(test_cases, factory):
matches = factory.find_candidates(
[req], Constraint.empty(), prefers_installed=False,
)
print(matches)
assert sum(1 for _ in matches) == match_count


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def test_get_html_page_directory_append_index(tmpdir):
dirpath = tmpdir / "something"
dirpath.mkdir()
dir_url = "file:///{}".format(
urllib.request.pathname2url(dirpath).lstrip("/"),
urllib.request.pathname2url(str(dirpath)).lstrip("/"),
)
expected_url = "{}/index.html".format(dir_url.rstrip("/"))

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_get_path_uid_symlink(tmpdir):
f = tmpdir / "symlink" / "somefile"
f.parent.mkdir()
f.write_text("content")
fs = f + '_link'
fs = str(f) + '_link'
os.symlink(f, fs)
with pytest.raises(OSError):
get_path_uid(fs)
Expand All @@ -40,7 +40,7 @@ def test_get_path_uid_symlink_without_NOFOLLOW(tmpdir, monkeypatch):
f = tmpdir / "symlink" / "somefile"
f.parent.mkdir()
f.write_text("content")
fs = f + '_link'
fs = str(f) + '_link'
os.symlink(f, fs)
with pytest.raises(OSError):
get_path_uid(fs)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_operations_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_copy_source_tree_with_socket_fails_with_no_socket_error(

errored_files = [err[0] for err in e.value.args[0]]
assert len(errored_files) == 1
assert unreadable_file in errored_files
assert str(unreadable_file) in errored_files

copied_files = get_filelist(target)
# All files without errors should have been copied.
Expand All @@ -154,7 +154,7 @@ def test_copy_source_tree_with_unreadable_dir_fails(clean_project, tmpdir):

errored_files = [err[0] for err in e.value.args[0]]
assert len(errored_files) == 1
assert unreadable_file in errored_files
assert str(unreadable_file) in errored_files

copied_files = get_filelist(target)
# All files without errors should have been copied.
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_req.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_environment_marker_extras(self, data):
"""
reqset = RequirementSet()
req = install_req_from_editable(
data.packages.joinpath("LocalEnvironMarker")
str(data.packages.joinpath("LocalEnvironMarker"))
)
req.user_supplied = True
reqset.add_requirement(req)
Expand Down Expand Up @@ -175,7 +175,7 @@ def test_missing_hash_with_require_hashes_in_reqs_file(self, data, tmpdir):
session = finder._link_collector.session
command = create_command('install')
with requirements_file('--require-hashes', tmpdir) as reqs_file:
options, args = command.parse_args(['-r', reqs_file])
options, args = command.parse_args(['-r', str(reqs_file)])
command.get_requirements(args, options, finder, session)
assert options.require_hashes

Expand Down Expand Up @@ -373,7 +373,7 @@ def test_unsupported_wheel_link_requirement_raises(self):
def test_unsupported_wheel_local_file_requirement_raises(self, data):
reqset = RequirementSet()
req = install_req_from_line(
data.packages.joinpath('simple.dist-0.1-py1-none-invalid.whl'),
str(data.packages.joinpath('simple.dist-0.1-py1-none-invalid.whl')),
)
assert req.link is not None
assert req.link.is_wheel
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/test_req_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def get_file_content(filename, *args, **kwargs):
pip._internal.req.req_file, 'get_file_content', get_file_content
)

result = list(parse_reqfile(req_file, session=session))
result = list(parse_reqfile(str(req_file), session=session))
assert len(result) == 1
assert result[0].name == req_name
assert not result[0].constraint
Expand Down Expand Up @@ -576,7 +576,7 @@ def test_multiple_appending_options(self, tmpdir, finder, options):
fp.write("--extra-index-url url1 \n")
fp.write("--extra-index-url url2 ")

list(parse_reqfile(tmpdir.joinpath("req1.txt"), finder=finder,
list(parse_reqfile(str(tmpdir.joinpath("req1.txt")), finder=finder,
session=PipSession(), options=options))

assert finder.index_urls == ['url1', 'url2']
Expand All @@ -602,7 +602,7 @@ def make_var(name):
getenv.side_effect = lambda n: env_vars[n]

reqs = list(parse_reqfile(
tmpdir.joinpath('req1.txt'),
str(tmpdir.joinpath('req1.txt')),
finder=finder,
session=PipSession()
))
Expand All @@ -627,7 +627,7 @@ def test_expand_missing_env_variables(self, tmpdir, finder):
getenv.return_value = ''

reqs = list(parse_reqfile(
tmpdir.joinpath('req1.txt'),
str(tmpdir.joinpath('req1.txt')),
finder=finder,
session=PipSession()
))
Expand All @@ -641,14 +641,14 @@ def test_join_lines(self, tmpdir, finder):
with open(tmpdir.joinpath("req1.txt"), "w") as fp:
fp.write("--extra-index-url url1 \\\n--extra-index-url url2")

list(parse_reqfile(tmpdir.joinpath("req1.txt"), finder=finder,
list(parse_reqfile(str(tmpdir.joinpath("req1.txt")), finder=finder,
session=PipSession()))

assert finder.index_urls == ['url1', 'url2']

def test_req_file_parse_no_only_binary(self, data, finder):
list(parse_reqfile(
data.reqfiles.joinpath("supported_options2.txt"),
str(data.reqfiles.joinpath("supported_options2.txt")),
finder=finder,
session=PipSession()))
expected = FormatControl({'fred'}, {'wilma'})
Expand All @@ -661,7 +661,7 @@ def test_req_file_parse_comment_start_of_line(self, tmpdir, finder):
with open(tmpdir.joinpath("req1.txt"), "w") as fp:
fp.write("# Comment ")

reqs = list(parse_reqfile(tmpdir.joinpath("req1.txt"),
reqs = list(parse_reqfile(str(tmpdir.joinpath("req1.txt")),
finder=finder,
session=PipSession()))

Expand All @@ -674,7 +674,7 @@ def test_req_file_parse_comment_end_of_line_with_url(self, tmpdir, finder):
with open(tmpdir.joinpath("req1.txt"), "w") as fp:
fp.write("https://example.com/foo.tar.gz # Comment ")

reqs = list(parse_reqfile(tmpdir.joinpath("req1.txt"),
reqs = list(parse_reqfile(str(tmpdir.joinpath("req1.txt")),
finder=finder,
session=PipSession()))

Expand All @@ -688,7 +688,7 @@ def test_req_file_parse_egginfo_end_of_line_with_url(self, tmpdir, finder):
with open(tmpdir.joinpath("req1.txt"), "w") as fp:
fp.write("https://example.com/foo.tar.gz#egg=wat")

reqs = list(parse_reqfile(tmpdir.joinpath("req1.txt"),
reqs = list(parse_reqfile(str(tmpdir.joinpath("req1.txt")),
finder=finder,
session=PipSession()))

Expand All @@ -708,7 +708,7 @@ def test_req_file_no_finder(self, tmpdir):
--no-index
""")

parse_reqfile(tmpdir.joinpath("req.txt"), session=PipSession())
parse_reqfile(str(tmpdir.joinpath("req.txt")), session=PipSession())

def test_install_requirements_with_options(self, tmpdir, finder, session,
options):
Expand All @@ -722,7 +722,7 @@ def test_install_requirements_with_options(self, tmpdir, finder, session,
'''.format(global_option=global_option, install_option=install_option)

with requirements_file(content, tmpdir) as reqs_file:
req = next(parse_reqfile(reqs_file.resolve(),
req = next(parse_reqfile(str(reqs_file.resolve()),
finder=finder,
options=options,
session=session))
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_resolution_legacy_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_incompatible_with_ignore_requires(self, caplog):
version_info=(3, 6, 5),
ignore_requires_python=True,
)
assert len(caplog.records) == 1
assert len(caplog.records) == 1, caplog.records
record = caplog.records[0]
assert record.levelname == 'DEBUG'
assert record.message == (
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_invalid_requires_python(self, caplog):
version_info=(3, 6, 5),
ignore_requires_python=False,
)
assert len(caplog.records) == 1
assert len(caplog.records) == 1, caplog.records
record = caplog.records[0]
assert record.levelname == 'WARNING'
assert record.message == (
Expand Down Expand Up @@ -211,7 +211,7 @@ def test_sort_best_candidate__has_non_yanked(self, caplog, monkeypatch):
resolver._populate_link(ireq)

assert ireq.link == candidates[0].link
assert len(caplog.records) == 0
assert len(caplog.records) == 0, caplog.records

def test_sort_best_candidate__all_yanked(self, caplog, monkeypatch):
"""
Expand All @@ -231,7 +231,7 @@ def test_sort_best_candidate__all_yanked(self, caplog, monkeypatch):
assert ireq.link == candidates[1].link

# Check the log messages.
assert len(caplog.records) == 1
assert len(caplog.records) == 1, caplog.records
record = caplog.records[0]
assert record.levelname == 'WARNING'
assert record.message == (
Expand Down Expand Up @@ -263,7 +263,7 @@ def test_sort_best_candidate__yanked_reason(

assert ireq.link == candidates[0].link

assert len(caplog.records) == 1
assert len(caplog.records) == 1, caplog.records
record = caplog.records[0]
assert record.levelname == 'WARNING'
expected_message = (
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_utils_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def make_dir(path):
])
def test_is_socket(create, result, tmpdir):
target = tmpdir.joinpath("target")
create(target)
create(str(target))
assert os.path.lexists(target)
assert is_socket(target) == result

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_utils_temp_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ def test_temp_dir_does_not_delete_explicit_paths_by_default(
with tempdir_registry() as registry:
registry.set_delete(deleted_kind, True)

with TempDirectory(path=path, delete=delete, kind=deleted_kind) as d:
assert str(d.path) == path
with TempDirectory(path=str(path), delete=delete, kind=deleted_kind) as d:
assert str(d.path) == str(path)
assert os.path.exists(path)
assert os.path.exists(path) == exists

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_utils_unpacking.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_unpack_tgz(self, data):
Test unpacking a *.tgz, and setting execute permissions
"""
test_file = data.packages.joinpath("test_tar.tgz")
untar_file(test_file, self.tempdir)
untar_file(str(test_file), str(self.tempdir))
self.confirm_files()
# Check the timestamp of an extracted file
file_txt_path = os.path.join(self.tempdir, 'file.txt')
Expand Down

0 comments on commit 9a3ed71

Please sign in to comment.