-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module __file__ attribute does not have the right casing
- Loading branch information
1 parent
9af6d46
commit cfc03a2
Showing
8 changed files
with
130 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
from types import ModuleType | ||
from typing import Optional | ||
|
||
|
||
def module_casesensitivepath(module: ModuleType) -> Optional[str]: | ||
"""Return the canonical __file__ of the module without resolving symlinks.""" | ||
path = module.__file__ | ||
if path is None: | ||
return None | ||
return casesensitivepath(path) | ||
|
||
|
||
def casesensitivepath(path: str) -> str: | ||
"""Return the case-sensitive version of the path.""" | ||
resolved_path = os.path.realpath(path) | ||
if resolved_path.lower() == path.lower(): | ||
return resolved_path | ||
# Patch has one or more symlinks. Todo: find the correct path casing. | ||
return path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import sys | ||
from pathlib import Path | ||
from types import ModuleType | ||
|
||
from _pytest._py import os_path | ||
|
||
_ON_CASEINSENSITIVE_OS = sys.platform.startswith("win") | ||
|
||
|
||
def test_casesensitivepath(tmp_path: Path) -> None: | ||
dirname_with_caps = tmp_path / "Testdir" | ||
dirname_with_caps.mkdir() | ||
real_filename = dirname_with_caps / "_test_casesensitivepath.py" | ||
with real_filename.open("wb"): | ||
pass | ||
real_linkname = dirname_with_caps / "_test_casesensitivepath_link.py" | ||
real_linkname.symlink_to(real_filename) | ||
|
||
# Test path resolving | ||
|
||
original = str(real_filename) | ||
expected = str(real_filename) | ||
assert os_path.casesensitivepath(original) == expected | ||
|
||
original = str(real_filename).lower() | ||
if _ON_CASEINSENSITIVE_OS: | ||
expected = str(real_filename) | ||
else: | ||
expected = str(real_filename).lower() | ||
assert os_path.casesensitivepath(original) == expected | ||
|
||
# Test symlink preservation | ||
|
||
original = str(real_linkname) | ||
expected = str(real_linkname) | ||
assert os_path.casesensitivepath(original) == expected | ||
|
||
original = str(real_linkname).lower() | ||
expected = str(real_linkname).lower() | ||
assert os_path.casesensitivepath(original) == expected | ||
|
||
|
||
def test_module_casesensitivepath(tmp_path: Path) -> None: | ||
dirname_with_caps = tmp_path / "Testdir" | ||
dirname_with_caps.mkdir() | ||
real_filename = dirname_with_caps / "_test_module_casesensitivepath.py" | ||
with real_filename.open("wb"): | ||
pass | ||
real_linkname = dirname_with_caps / "_test_module_casesensitivepath_link.py" | ||
real_linkname.symlink_to(real_filename) | ||
|
||
mod = ModuleType("dummy.name") | ||
|
||
mod.__file__ = None | ||
assert os_path.module_casesensitivepath(mod) is None | ||
|
||
# Test path resolving | ||
|
||
original = str(real_filename) | ||
expected = str(real_filename) | ||
mod.__file__ = original | ||
assert os_path.module_casesensitivepath(mod) == expected | ||
|
||
original = str(real_filename).lower() | ||
if _ON_CASEINSENSITIVE_OS: | ||
expected = str(real_filename) | ||
else: | ||
expected = str(real_filename).lower() | ||
mod.__file__ = original | ||
assert os_path.module_casesensitivepath(mod) == expected | ||
|
||
# Test symlink preservation | ||
|
||
original = str(real_linkname) | ||
expected = str(real_linkname) | ||
mod.__file__ = original | ||
assert os_path.module_casesensitivepath(mod) == expected | ||
|
||
original = str(real_linkname).lower() | ||
expected = str(real_linkname).lower() | ||
mod.__file__ = original | ||
assert os_path.module_casesensitivepath(mod) == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters