def test_parse_wheel_record_drop_superfulous(): """Parser emits warning on each row with superfulous columns. """ record_lines = [ "file.py,sha256=AVTFPZpEKzuHr7OvQZmhaU3LvwKz06AJw8mT\\_pNh2yI,3144,", "distribution-1.0.dist-info/RECORD,,,,", ] with pytest.warns(SuperfluousRecordColumnsWarning) as ws: records = list(parse_record_file(record_lines)) assert len(ws) == 2 assert "0" in ws[0].message.args[0] assert "1" in ws[1].message.args[0] assert len(records) == 2 r0 = records[0] assert r0.path.as_posix() == "file.py" assert r0.hash_.name == "sha256" assert r0.hash_.value == "AVTFPZpEKzuHr7OvQZmhaU3LvwKz06AJw8mT\\_pNh2yI" assert r0.size == 3144 r1 = records[1] assert r1.path.as_posix() == "distribution-1.0.dist-info/RECORD" assert r1.hash_ is None assert r1.size is None
def test_provides_correct_contents(self, fancy_wheel): # Know the contents of the wheel files = {} with zipfile.ZipFile(fancy_wheel) as archive: for file in archive.namelist(): if file[-1:] == "/": continue files[file] = archive.read(file) expected_record_lines = ( files["fancy-1.0.0.dist-info/RECORD"].decode("utf-8").splitlines()) expected_records = list(parse_record_file(expected_record_lines)) # Check that the object's output is appropriate got_records = [] got_files = {} with WheelFile.open(fancy_wheel) as source: for record_elements, stream, is_executable in source.get_contents( ): got_records.append(record_elements) got_files[record_elements[0]] = stream.read() assert not is_executable assert sorted(got_records) == sorted(expected_records) assert got_files == files
def test_shows_correct_row_number(self): record_lines = [ "file1.py,sha256=AVTFPZpEKzuHr7OvQZmhaU3LvwKz06AJw8mT\\_pNh2yI,3144", "file2.py,sha256=AVTFPZpEKzuHr7OvQZmhaU3LvwKz06AJw8mT\\_pNh2yI,3144", "file3.py,sha256=AVTFPZpEKzuHr7OvQZmhaU3LvwKz06AJw8mT\\_pNh2yI,3144", "distribution-1.0.dist-info/RECORD,,,,", ] with pytest.raises(InvalidRecord) as exc_info: list(parse_record_file(record_lines)) assert "Row Index 3" in str(exc_info.value)
def test_accepts_all_kinds_of_iterables(self, record_input): """Should accepts any iterable, e.g. container, iterator, or file object.""" records = list(parse_record_file(record_input)) assert len(records) == 2 assert records == [ ( "file.py", "sha256=AVTFPZpEKzuHr7OvQZmhaU3LvwKz06AJw8mT\\_pNh2yI", "3144", ), ("distribution-1.0.dist-info/RECORD", "", ""), ]
def test_parse_wheel_record_simple(record_input): """Parser accepts any iterable, e.g. container, iterator, or file object. """ records = list(parse_record_file(record_input)) assert len(records) == 2 r0 = records[0] assert r0.path.as_posix() == "file.py" assert r0.hash_.name == "sha256" assert r0.hash_.value == "AVTFPZpEKzuHr7OvQZmhaU3LvwKz06AJw8mT\\_pNh2yI" assert r0.size == 3144 r1 = records[1] assert r1.path.as_posix() == "distribution-1.0.dist-info/RECORD" assert r1.hash_ is None assert r1.size is None
def test_parse_wheel_record_invalid(record_lines, invalid_row): """Parser raises ValueError on invalid RECORD. """ with pytest.raises(ValueError) as ctx: list(parse_record_file(record_lines)) assert str(ctx.value) == "invalid row 1: {!r}".format(invalid_row)
def test_rejects_wrong_element_count(self, line, element_count): with pytest.raises(InvalidRecord) as exc_info: list(parse_record_file([line])) message = "expected 3 elements, got {}".format(element_count) assert message in str(exc_info.value)
def test_accepts_empty_iterable(self): list(parse_record_file([]))