Skip to content

Commit 7b2e112

Browse files
committed
try fix windows tests - add windows prompt install test
1 parent ff7a997 commit 7b2e112

File tree

6 files changed

+149
-837
lines changed

6 files changed

+149
-837
lines changed

justfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ test-powershell:
287287
. .venv/Scripts/activate.ps1
288288
pytest --cov-append tests/shellcompletion/test_shell_resolution.py::TestShellResolution::test_powershell tests/test_parser_completers.py tests/test_parser_completers.py tests/shellcompletion/test_powershell.py::PowerShellTests tests/shellcompletion/test_powershell.py::PowerShellExeTests
289289
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
290-
# uv sync --no-extra rich
291-
# . .venv/Scripts/activate.ps1
292-
# pytest --cov-append tests/shellcompletion/test_powershell.py::PowerShellExeTests::test_prompt_install
293-
# if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
290+
uv sync --no-extra rich
291+
. .venv/Scripts/activate.ps1
292+
pytest --cov-append tests/shellcompletion/test_powershell.py::PowerShellExeTests::test_prompt_install
293+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
294294

295295
# test pwsh shell completions
296296
[script("pwsh")]
@@ -299,10 +299,10 @@ test-pwsh:
299299
. .venv/Scripts/activate.ps1
300300
pytest --cov-append tests/shellcompletion/test_shell_resolution.py::TestShellResolution::test_pwsh tests/test_parser_completers.py tests/shellcompletion/test_powershell.py::PWSHTests tests/shellcompletion/test_powershell.py::PWSHExeTests
301301
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
302-
# uv sync --no-extra rich
303-
# . .venv/Scripts/activate.ps1
304-
# pytest --cov-append tests/shellcompletion/test_powershell.py::PWSHExeTests::test_prompt_install
305-
# if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
302+
uv sync --no-extra rich
303+
. .venv/Scripts/activate.ps1
304+
pytest --cov-append tests/shellcompletion/test_powershell.py::PWSHExeTests::test_prompt_install
305+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
306306

307307
# test fish shell completions
308308
[script("fish")]

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
55
[project]
66
name = "django-typer"
77
version = "3.1.0"
8-
requires-python = ">=3.9,<4.0"
8+
requires-python = "==3.13.2"
99
description = "Use Typer to define the CLI for your Django management commands."
1010
authors = [
1111
{name = "Brian Kohan", email = "[email protected]"},
@@ -17,15 +17,15 @@ repository = "https://github.com/django-commons/django-typer"
1717
homepage = "https://django-typer.readthedocs.io"
1818
keywords = ["django", "CLI", "management", "Typer", "commands"]
1919
dependencies = [
20-
"Django>=3.2,<6.0",
20+
"django~=5.2.0",
2121
"click>=8.1.8,<8.2",
2222
# typer's release history is full of breaking changes for minor versions
2323
# given the reliance on some of its private internals we peg the typer
2424
# version very strictly to bug fix releases for specific minor lines.
2525
"typer-slim>=0.14.0,<0.16.0",
2626
"shellingham>=1.5.4,<2.0",
2727
# we need this on 3.9 for ParamSpec
28-
"typing-extensions>=3.7.4.3; python_version < '3.10'"
28+
"typing-extensions>=3.7.4.3; python_version < '3.10'",
2929
]
3030
classifiers = [
3131
"Environment :: Console",

tests/shellcompletion/__init__.py

Lines changed: 76 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -501,78 +501,94 @@ def test_multi_install(self):
501501
finally:
502502
self.remove_script(script=manage2)
503503

504-
if platform.system() != "Windows":
505-
506-
def test_prompt_install(self, env={}, directory: t.Optional[Path] = None):
507-
import pexpect
508-
509-
env = {
510-
**dict(os.environ),
511-
"DJANGO_SETTINGS_MODULE": "tests.settings.completion",
512-
"DJANGO_COLORS": "nocolor",
513-
**env,
514-
}
515-
516-
rex = re.compile
517-
expected = [
518-
rex(
519-
r"Append\s+the\s+above\s+contents\s+to\s+(?P<file>.*)\?", re.DOTALL
520-
), # 0
521-
rex(
522-
r"Create\s+(?P<file>.*)\s+with\s+the\s+above\s+contents\?",
523-
re.DOTALL,
524-
), # 1
525-
rex(r"Aborted\s+shell\s+completion\s+installation."), # 2
526-
rex(rf"Installed\s+autocompletion\s+for\s+{self.shell}"), # 3
527-
]
528-
529-
install_command = [
530-
"shellcompletion",
531-
"--no-color",
532-
"--shell",
533-
self.shell,
534-
"install",
535-
]
536-
self.remove()
537-
self.verify_remove(directory=directory)
504+
def test_prompt_install(self, env={}, directory: t.Optional[Path] = None):
505+
import pexpect
506+
507+
env = {
508+
**dict(os.environ),
509+
"DJANGO_SETTINGS_MODULE": "tests.settings.completion",
510+
"DJANGO_COLORS": "nocolor",
511+
**env,
512+
}
513+
514+
rex = re.compile
515+
expected = [
516+
rex(
517+
r"Append\s+the\s+above\s+contents\s+to\s+(?P<file>.*)\?", re.DOTALL
518+
), # 0
519+
rex(
520+
r"Create\s+(?P<file>.*)\s+with\s+the\s+above\s+contents\?",
521+
re.DOTALL,
522+
), # 1
523+
rex(r"Aborted\s+shell\s+completion\s+installation."), # 2
524+
rex(rf"Installed\s+autocompletion\s+for\s+{self.shell}"), # 3
525+
]
526+
527+
install_command = [
528+
"shellcompletion",
529+
"--no-color",
530+
"--shell",
531+
self.shell,
532+
"install",
533+
]
534+
self.remove()
535+
self.verify_remove(directory=directory)
538536

537+
if platform.system() != "Windows":
539538
install = pexpect.spawn(self.manage_script, install_command, env=env)
540539
install.setwinsize(24, 800)
540+
else:
541+
from pexpect.popen_spawn import PopenSpawn
541542

542-
def wait_for_output(child) -> t.Tuple[int, t.Optional[str]]:
543-
index = child.expect(expected)
544-
if index in [0, 1]:
545-
return index, child.match.group("file").decode()
546-
return index, None
543+
install = PopenSpawn(
544+
" ".join([self.manage_script, *install_command]),
545+
env=env,
546+
encoding="utf-8",
547+
)
547548

548-
# test an abort
549-
idx, _ = wait_for_output(install)
550-
self.assertLess(idx, 2)
551-
install.sendline("N")
549+
def wait_for_output(child) -> t.Tuple[int, t.Optional[str]]:
550+
index = child.expect(expected)
551+
if index in [0, 1]:
552+
return index, child.match.group("file")
553+
return index, None
552554

553-
while True:
554-
idx, _ = wait_for_output(install)
555-
if idx < 2:
556-
install.sendline("N")
557-
else:
558-
self.assertEqual(idx, 2)
559-
break
555+
# test an abort
556+
idx, _ = wait_for_output(install)
557+
self.assertLess(idx, 2)
558+
install.sendline("N")
560559

561-
self.verify_remove(directory=directory)
560+
while True:
561+
idx, _ = wait_for_output(install)
562+
if idx < 2:
563+
install.sendline("N")
564+
else:
565+
self.assertEqual(idx, 2)
566+
break
562567

563-
# test an install
568+
self.verify_remove(directory=directory)
569+
570+
# test an install
571+
if platform.system() != "Windows":
564572
install = pexpect.spawn(self.manage_script, install_command, env=env)
565573
install.setwinsize(24, 800)
574+
else:
575+
from pexpect.popen_spawn import PopenSpawn
576+
577+
install = PopenSpawn(
578+
" ".join([self.manage_script, *install_command]),
579+
env=env,
580+
encoding="utf-8",
581+
)
566582

567-
while True:
568-
idx, _ = wait_for_output(install)
569-
if idx < 2:
570-
install.sendline("Y")
571-
else:
572-
self.assertEqual(idx, 3)
573-
break
583+
while True:
584+
idx, _ = wait_for_output(install)
585+
if idx < 2:
586+
install.sendline("Y")
587+
else:
588+
self.assertEqual(idx, 3)
589+
break
574590

575-
self.verify_install(directory=directory)
591+
self.verify_install(directory=directory)
576592

577593
# TODO
578594
# else:

tests/test_tracebacks.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def test_default_traceback(self):
2828
self.assertEqual(len(re.findall(r"\.py:\d+", result) or []), 1)
2929

3030
hlp = run_command("test_command1", "--no-color", "--help")[0]
31+
# TODO - why are extra newlines inserted here on windows??
32+
if platform.system() == "Windows":
33+
hlp = hlp.replace("\r\n", "")
3134
self.assertNotIn("--hide-locals", hlp)
3235
self.assertIn("--show-locals", hlp)
3336

@@ -63,6 +66,10 @@ def test_tb_command_overrides(self):
6366
self.assertGreater(len(re.findall(r"\.py:\d+", result) or []), 0)
6467

6568
hlp = run_command("test_tb_overrides", "--no-color", "--help")[0]
69+
70+
# TODO - why are extra newlines inserted here on windows??
71+
if platform.system() == "Windows":
72+
hlp = hlp.replace("\r\n", "")
6673
self.assertIn("--hide-locals", hlp)
6774
self.assertNotIn("--show-locals", hlp)
6875

@@ -171,6 +178,10 @@ def test_traceback_no_locals_short_false(self):
171178
"--no-color",
172179
"--help",
173180
)[0]
181+
182+
# TODO - why are extra newlines inserted here on windows??
183+
if platform.system() == "Windows":
184+
hlp = hlp.replace("\r\n", "")
174185
self.assertFalse("--show-locals" in hlp)
175186
self.assertTrue("--hide-locals" in hlp)
176187
result = run_command(

tests/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ def run_command(
169169
try:
170170
env = kwargs.pop("env") if "env" in kwargs else os.environ.copy()
171171
if platform.system() == "Windows":
172-
env.setdefault("PYTHONIOENCODING", "utf-8")
172+
env["PYTHONIOENCODING"] = "utf-8"
173+
env["PYTHONUTF8"] = "1"
173174
if chdir:
174175
os.chdir(manage_py.parent)
175176
result = subprocess.run(

0 commit comments

Comments
 (0)