Skip to content

Commit e8dd8c0

Browse files
committed
Fix paths
1 parent 0df1929 commit e8dd8c0

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

python_files/testing_tools/adapter/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ def _resolve_relpath(
102102
if path.startswith("./"):
103103
return path[2:]
104104
if not _path_isabs(path):
105+
if rootdir:
106+
rootdir = rootdir.replace(_pathsep, "/")
107+
if not rootdir.endswith("/"):
108+
rootdir += "/"
109+
if _normcase(path).startswith(_normcase(rootdir)):
110+
return path[len(rootdir) :]
105111
return path
106112

107113
# Deal with root-dir-as-fileid.

python_files/tests/testing_tools/adapter/test_util.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_fix_path(path, expected):
124124
# absolute
125125
("/", posixpath, "/"),
126126
("/spam.py", posixpath, "/spam.py"),
127-
("\\", ntpath, ".\\" if is_python313_or_later() else "\\"),
127+
("\\", ntpath, ".\\\\" if is_python313_or_later() else "\\"),
128128
(r"\spam.py", ntpath, r".\\spam.py" if is_python313_or_later() else r"\spam.py"),
129129
(r"C:\spam.py", ntpath, r"C:\spam.py"),
130130
# no-op
@@ -225,11 +225,11 @@ def test_fix_fileid(fileid, os_path, expected):
225225
("/eggs/spam.py", "/eggs", ntpath, "./spam.py"),
226226
("/eggs/spam.py", "/eggs/", ntpath, "./spam.py"),
227227
# no-op
228-
("/spam.py", "/eggs", ntpath, "/spam.py"),
229-
("/spam.py", "/eggs/", ntpath, "/spam.py"),
228+
("/spam.py", "/eggs", ntpath, ".//spam.py" if is_python313_or_later() else "/spam.py"),
229+
("/spam.py", "/eggs/", ntpath, ".//spam.py" if is_python313_or_later() else "/spam.py"),
230230
# root-only (no-op)
231231
("/", "/", ntpath, "/"),
232-
("/", "/spam", ntpath, "/"),
232+
("/", "/spam", ntpath, ".//" if is_python313_or_later() else "/"),
233233
("//", "/", ntpath, "//"),
234234
("//", "//", ntpath, "//"),
235235
("//", "//spam", ntpath, "//"),
@@ -244,11 +244,11 @@ def test_fix_fileid(fileid, os_path, expected):
244244
(r"\eggs\spam.py", "\\Eggs", ntpath, r"./spam.py"),
245245
(r"\eggs\Spam.py", "\\Eggs", ntpath, r"./Spam.py"),
246246
# no-op
247-
(r"\spam.py", r"\eggs", ntpath, r"/spam.py"),
247+
(r"\spam.py", r"\eggs", ntpath, ".//spam.py" if is_python313_or_later() else r"/spam.py"),
248248
(r"C:\spam.py", r"C:\eggs", ntpath, r"C:/spam.py"),
249249
# TODO: Should these be supported.
250250
(r"C:\spam.py", "\\", ntpath, r"C:/spam.py"),
251-
(r"\spam.py", "C:\\", ntpath, r"/spam.py"),
251+
(r"\spam.py", "C:\\", ntpath, ".//spam.py" if is_python313_or_later() else r"/spam.py"),
252252
# root-only
253253
("\\", "\\", ntpath, "/"),
254254
("\\\\", "\\", ntpath, "//"),

0 commit comments

Comments
 (0)