Repository navigation
fix: make selector output portable on Python 3.11 and Windows #3744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| """Tests for provider-selection compute guidance.""" | ||
|
|
||
| import importlib.util | ||
| import os | ||
| import re | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
| from urllib.parse import urlsplit | ||
|
|
||
|
|
@@ -61,3 +64,50 @@ def test_managed_provider_does_not_show_self_host_compute_notice(capsys): | |
| print_self_host_compute_notice("openai") | ||
|
|
||
| assert capsys.readouterr().out == "" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("color_name", SELECTOR.Color.__members__) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Categorize the new pytest tests. Mark the color and banner tests as unit tests. Mark the interactive subprocess test as an integration test. As per coding guidelines: “Use Also applies to: 77-77, 89-89
|
||
| def test_color_strings_preserve_ansi_values(color_name: str) -> None: | ||
| color = SELECTOR.Color[color_name] | ||
|
|
||
| assert str(color) == color.value | ||
| assert f"{color}" == color.value | ||
|
|
||
|
|
||
| def test_banner_prints_ansi_colors_instead_of_enum_names( | ||
| capsys: pytest.CaptureFixture[str], | ||
| ) -> None: | ||
| SELECTOR.print_banner() | ||
|
|
||
| output = capsys.readouterr().out | ||
| assert output.startswith("\033[96m\n") | ||
| assert "LLM Provider Selector" in output | ||
| assert output.endswith("\033[0m\n") | ||
| assert "Color." not in output | ||
|
|
||
|
|
||
| def test_interactive_selection_supports_cp1252_output(tmp_path: Path) -> None: | ||
| result = subprocess.run( | ||
| [ | ||
| sys.executable, | ||
| "-c", | ||
| "import runpy, sys; selector = runpy.run_path(sys.argv[1]); " | ||
| "selector['interactive_select'](" | ||
| "providers=[('custom', 'Custom provider')], " | ||
| "models_per_provider={'custom': [('ascii-model', 'Custom model')]}, " | ||
| "persist=True)", | ||
| str(SELECTOR_PATH), | ||
| ], | ||
| input="1\n1\n", | ||
| encoding="cp1252", | ||
| env={**os.environ, "PYTHONIOENCODING": "cp1252:strict"}, | ||
| capture_output=True, | ||
| cwd=tmp_path, | ||
| timeout=10, | ||
| ) | ||
|
|
||
| assert result.returncode == 0, result.stderr | ||
| assert "LLM Provider Selector" in result.stdout | ||
| assert "Config saved to" in result.stdout | ||
| assert "Config loaded to current session" in result.stdout | ||
| assert (tmp_path / ".llm.env").read_text() == "LLM_PROVIDER=custom\nLLM_MODEL=ascii-model\n" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔎 Supported by static analysis
Script executed:
Repository: affaan-m/ECC
Length of output: 13611
Use a stdout-configured logger for the changed messages.
The applicable Python guidance requires logging for
print()calls in edited files and does not define a CLI exception. Preserve stdout behavior. Do not use default logging, which writes to stderr.Source: Coding guidelines