mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-03 09:30:21 +08:00
fix(tools): make TeX source discovery case-consistent (#2985)
Keep the existing lowercase .tex extension rule when the platform glob also returns uppercase matches. Add a regression case that supplies the Windows-style glob result on any CI host. Related to #2354.
This commit is contained in:
@@ -189,7 +189,8 @@ class TexDownloader:
|
||||
3. Tex file containing \\documentclass
|
||||
4. Largest tex file
|
||||
"""
|
||||
tex_files = list(directory.rglob("*.tex"))
|
||||
# Windows globbing also returns uppercase extensions.
|
||||
tex_files = [path for path in directory.rglob("*.tex") if path.name.endswith(".tex")]
|
||||
|
||||
if not tex_files:
|
||||
return None
|
||||
|
||||
@@ -309,12 +309,26 @@ class TestFindMainTex:
|
||||
found = downloader._find_main_tex(tmp_path)
|
||||
assert found is not None and found.name == "Main.tex"
|
||||
|
||||
@pytest.mark.parametrize("case_insensitive_glob", [False, True])
|
||||
def test_uppercase_extension_file_is_invisible(
|
||||
self, downloader: TexDownloader, tmp_path: Path
|
||||
self,
|
||||
downloader: TexDownloader,
|
||||
tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
case_insensitive_glob: bool,
|
||||
) -> None:
|
||||
# Known limitation: discovery globs "*.tex" case-sensitively, so a file
|
||||
# named MAIN.TEX is never even considered a candidate.
|
||||
(tmp_path / "MAIN.TEX").write_text("upper", encoding="utf-8")
|
||||
uppercase = tmp_path / "MAIN.TEX"
|
||||
uppercase.write_text("upper", encoding="utf-8")
|
||||
if case_insensitive_glob:
|
||||
rglob = Path.rglob
|
||||
|
||||
def glob_with_uppercase(path: Path, pattern: str):
|
||||
if path == tmp_path and pattern == "*.tex":
|
||||
return iter([uppercase])
|
||||
return rglob(path, pattern)
|
||||
|
||||
monkeypatch.setattr(Path, "rglob", glob_with_uppercase)
|
||||
|
||||
assert downloader._find_main_tex(tmp_path) is None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user