Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/installer/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
from collections.abc import Iterable, Iterator
from dataclasses import dataclass
from pathlib import Path
from pathlib import Path, PureWindowsPath
from typing import BinaryIO, cast

from installer.utils import copyfileobj_with_hashing, get_stream_length
Expand Down Expand Up @@ -106,8 +106,7 @@ def to_row(self, path_prefix: str | None = None) -> tuple[str, str, str]:
path = self.path

# Convert Windows paths to use / for consistency
if os.sep == "\\":
path = path.replace("\\", "/") # pragma: no cover
path = PureWindowsPath(path).as_posix()

return (
path,
Expand Down
29 changes: 29 additions & 0 deletions tests/test_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest

import installer.records
from installer.records import Hash, InvalidRecordEntry, RecordEntry, parse_record_file


Expand Down Expand Up @@ -176,6 +177,34 @@ def test_string_representation_with_prefix(
)
assert record.to_row("prefix/") == expected_row

def test_string_representation_with_backslash_path(self, monkeypatch):
monkeypatch.setattr(installer.records.os, "sep", "/")
record = RecordEntry.from_elements(
r"distribution-1.0.dist-info\RECORD",
"",
"",
)

assert record.to_row() == (
"distribution-1.0.dist-info/RECORD",
"",
"",
)

def test_string_representation_with_backslash_path_and_prefix(self, monkeypatch):
monkeypatch.setattr(installer.records.os, "sep", "/")
record = RecordEntry.from_elements(
r"bin\script.py",
"",
"",
)

assert record.to_row("prefix/") == (
"prefix/bin/script.py",
"",
"",
)

def test_equality(self):
record = RecordEntry.from_elements(
"file.py",
Expand Down
Loading