Skip to content

Commit

Permalink
Merge pull request #8547 from chrahunt/test-record-population
Browse files Browse the repository at this point in the history
Test RECORD population for data files
  • Loading branch information
chrahunt authored Jul 8, 2020
2 parents 9ec3cfa + ffddab6 commit 5da104a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/functional/test_install_wheel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import csv
import distutils
import glob
import os
Expand Down Expand Up @@ -282,6 +283,28 @@ def test_wheel_record_lines_in_deterministic_order(script, data):
assert record_lines == sorted(record_lines)


def test_wheel_record_lines_have_hash_for_data_files(script):
package = make_wheel(
"simple",
"0.1.0",
extra_data_files={
"purelib/info.txt": "c",
},
).save_to_dir(script.scratch_path)
script.pip("install", package)
record_file = (
script.site_packages_path / "simple-0.1.0.dist-info" / "RECORD"
)
record_text = record_file.read_text()
record_rows = list(csv.reader(record_text.splitlines()))
records = {
r[0]: r[1:] for r in record_rows
}
assert records["info.txt"] == [
"sha256=Ln0sA6lQeuJl7PW1NWiFpTOTogKdJBOUmXJloaJa78Y", "1"
]


@pytest.mark.incompatible_with_test_venv
def test_install_user_wheel(script, shared_data, with_wheel, tmpdir):
"""
Expand Down
44 changes: 44 additions & 0 deletions tests/lib/test_wheel.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""Tests for wheel helper.
"""
import csv
from email import message_from_string
from functools import partial
from zipfile import ZipFile

from pip._vendor.six import ensure_text, iteritems

from pip._internal.utils.typing import MYPY_CHECK_RUNNING
from tests.lib.wheel import (
_default,
Expand Down Expand Up @@ -152,6 +155,47 @@ def test_make_wheel_basics(tmpdir):
}


def test_make_wheel_default_record():
with make_wheel(
name="simple",
version="0.1.0",
extra_files={"simple/__init__.py": "a"},
extra_metadata_files={"LICENSE": "b"},
extra_data_files={"purelib/info.txt": "c"},
).as_zipfile() as z:
record_bytes = z.read("simple-0.1.0.dist-info/RECORD")
record_text = ensure_text(record_bytes)
record_rows = list(csv.reader(record_text.splitlines()))
records = {
row[0]: row[1:] for row in record_rows
}

expected = {
"simple/__init__.py": [
"sha256=ypeBEsobvcr6wjGzmiPcTaeG7_gUfE5yuYB3ha_uSLs", "1"
],
"simple-0.1.0.data/purelib/info.txt": [
"sha256=Ln0sA6lQeuJl7PW1NWiFpTOTogKdJBOUmXJloaJa78Y", "1"
],
"simple-0.1.0.dist-info/LICENSE": [
"sha256=PiPoFgA5WUoziU9lZOGxNIu9egCI1CxKy3PurtWcAJ0", "1"
],
"simple-0.1.0.dist-info/RECORD": ["", ""],
}
for name, values in iteritems(expected):
assert records[name] == values, name

# WHEEL and METADATA aren't constructed in a stable way, so just spot
# check.
expected_variable = {
"simple-0.1.0.dist-info/METADATA": "51",
"simple-0.1.0.dist-info/WHEEL": "104",
}
for name, length in iteritems(expected_variable):
assert records[name][0].startswith("sha256="), name
assert records[name][1] == length, name


def test_make_wheel_extra_files():
with make_wheel(
name="simple",
Expand Down

0 comments on commit 5da104a

Please sign in to comment.