Skip to content

Commit

Permalink
Fix paths
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Oct 14, 2024
1 parent 3c10bb4 commit cbf14f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions python_files/testing_tools/adapter/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def _resolve_relpath(
if path.startswith("./"):
return path[2:]
if not _path_isabs(path):
if rootdir:
rootdir = rootdir.replace(_pathsep, "/")
if not rootdir.endswith("/"):
rootdir += "/"
if _normcase(path).startswith(_normcase(rootdir)):
return path[len(rootdir) :]
return path

# Deal with root-dir-as-fileid.
Expand Down
12 changes: 6 additions & 6 deletions python_files/tests/testing_tools/adapter/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_fix_path(path, expected):
# absolute
("/", posixpath, "/"),
("/spam.py", posixpath, "/spam.py"),
("\\", ntpath, ".\\" if is_python313_or_later() else "\\"),
("\\", ntpath, ".\\\\" if is_python313_or_later() else "\\"),
(r"\spam.py", ntpath, r".\\spam.py" if is_python313_or_later() else r"\spam.py"),
(r"C:\spam.py", ntpath, r"C:\spam.py"),
# no-op
Expand Down Expand Up @@ -225,11 +225,11 @@ def test_fix_fileid(fileid, os_path, expected):
("/eggs/spam.py", "/eggs", ntpath, "./spam.py"),
("/eggs/spam.py", "/eggs/", ntpath, "./spam.py"),
# no-op
("/spam.py", "/eggs", ntpath, "/spam.py"),
("/spam.py", "/eggs/", ntpath, "/spam.py"),
("/spam.py", "/eggs", ntpath, ".//spam.py" if is_python313_or_later() else "/spam.py"),
("/spam.py", "/eggs/", ntpath, ".//spam.py" if is_python313_or_later() else "/spam.py"),
# root-only (no-op)
("/", "/", ntpath, "/"),
("/", "/spam", ntpath, "/"),
("/", "/spam", ntpath, ".//" if is_python313_or_later() else "/"),
("//", "/", ntpath, "//"),
("//", "//", ntpath, "//"),
("//", "//spam", ntpath, "//"),
Expand All @@ -244,11 +244,11 @@ def test_fix_fileid(fileid, os_path, expected):
(r"\eggs\spam.py", "\\Eggs", ntpath, r"./spam.py"),
(r"\eggs\Spam.py", "\\Eggs", ntpath, r"./Spam.py"),
# no-op
(r"\spam.py", r"\eggs", ntpath, r"/spam.py"),
(r"\spam.py", r"\eggs", ntpath, ".//spam.py" if is_python313_or_later() else r"/spam.py"),
(r"C:\spam.py", r"C:\eggs", ntpath, r"C:/spam.py"),
# TODO: Should these be supported.
(r"C:\spam.py", "\\", ntpath, r"C:/spam.py"),
(r"\spam.py", "C:\\", ntpath, r"/spam.py"),
(r"\spam.py", "C:\\", ntpath, ".//spam.py" if is_python313_or_later() else r"/spam.py"),
# root-only
("\\", "\\", ntpath, "/"),
("\\\\", "\\", ntpath, "//"),
Expand Down

0 comments on commit cbf14f7

Please sign in to comment.