Skip to content

Commit cd1964d

Browse files
committed
Fix CLI and localization unit tests for colored terminal output.
Disable ANSI styling in CLI test invocations and isolate the Windows locale fallback test from registry lookups so CI passes reliably.
1 parent 03ee14a commit cd1964d

5 files changed

Lines changed: 14 additions & 11 deletions

File tree

tests/api/unit_tests/test_cli_basics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_help_runs_without_synergy(self):
2727
with patch("moldflow_cli.context.get_synergy") as mock_ctx_synergy, patch(
2828
"moldflow_cli.factories.get_synergy"
2929
) as mock_fact_synergy:
30-
result = runner.invoke(app, ["--help"])
30+
result = runner.invoke(app, ["--no-color", "--help"])
3131
assert result.exit_code == 0
3232
# Help should not need to touch Synergy/COM at all.
3333
mock_ctx_synergy.assert_not_called()
@@ -40,7 +40,7 @@ def test_help_runs_without_synergy(self):
4040
def test_help_shows_global_no_color_option(self):
4141
"""Global help should advertise the output-styling toggle."""
4242
app = build_cli_app()
43-
result = runner.invoke(app, ["--help"])
43+
result = runner.invoke(app, ["--no-color", "--help"])
4444
assert result.exit_code == 0
4545
assert "--no-color" in result.stdout
4646

@@ -50,9 +50,9 @@ def test_subcommand_help_runs_without_synergy(self):
5050
with patch("moldflow_cli.context.get_synergy") as mock_ctx_synergy, patch(
5151
"moldflow_cli.factories.get_synergy"
5252
) as mock_fact_synergy:
53-
list_help = runner.invoke(app, ["list", "--help"])
54-
describe_help = runner.invoke(app, ["describe", "--help"])
55-
invoke_help = runner.invoke(app, ["invoke", "--help"])
53+
list_help = runner.invoke(app, ["--no-color", "list", "--help"])
54+
describe_help = runner.invoke(app, ["--no-color", "describe", "--help"])
55+
invoke_help = runner.invoke(app, ["--no-color", "invoke", "--help"])
5656

5757
assert list_help.exit_code == 0
5858
assert describe_help.exit_code == 0

tests/api/unit_tests/test_cli_describe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ def test_list_human_output_shows_explicit_message_for_empty_filtered_results():
823823
def test_list_with_describe_requires_structured_output():
824824
"""Expanded list metadata should stay opt-in for JSON/YAML flows only."""
825825
app = build_cli_app()
826-
result = runner.invoke(app, ["list", "--with-describe"])
826+
result = runner.invoke(app, ["--no-color", "list", "--with-describe"])
827827
assert result.exit_code != 0
828828
combined = (result.stdout or "") + (getattr(result, "stderr", "") or "")
829829
assert "--with-describe requires --json or --yaml" in combined
@@ -855,7 +855,7 @@ def test_list_json_allows_zero_max_results():
855855
def test_list_rejects_negative_max_results():
856856
"""List should reject negative result caps explicitly."""
857857
app = build_cli_app()
858-
result = runner.invoke(app, ["list", "--json", "--max-results", "-1"])
858+
result = runner.invoke(app, ["--no-color", "list", "--json", "--max-results", "-1"])
859859
assert result.exit_code != 0
860860
combined = (result.stdout or "") + (getattr(result, "stderr", "") or "")
861861
assert "--max-results must be greater than or equal to 0" in combined

tests/api/unit_tests/test_cli_invoke_execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _get_cli_test_manager(self) -> CLITestManager:
9090
setattr(moldflow, "CLITestManager", CLITestManager)
9191
setattr(moldflow.Synergy, "cli_test_manager", property(_get_cli_test_manager))
9292
try:
93-
result = runner.invoke(app, ["invoke", "cli_test_manager"])
93+
result = runner.invoke(app, ["--no-color", "invoke", "cli_test_manager"])
9494
assert result.exit_code != 0
9595
combined = (result.stdout or "") + (getattr(result, "stderr", "") or "")
9696
lowered = combined.lower()

tests/api/unit_tests/test_cli_invoke_parse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ def cli_echo(self, value: str) -> str:
697697
with patch("moldflow_cli.context.get_synergy") as mock_ctx_synergy, patch(
698698
"moldflow_cli.factories.get_synergy"
699699
) as mock_fact_synergy:
700-
r = runner.invoke(app, ["invoke", "synergy.cli_echo", '{"value":'])
700+
r = runner.invoke(app, ["--no-color", "invoke", "synergy.cli_echo", '{"value":'])
701701

702702
assert r.exit_code != 0
703703
combined = (
@@ -1856,7 +1856,7 @@ def open_project(self, path: int):
18561856
def test_invoke_help_shows_arg_syntax():
18571857
"""Invoke --help should demonstrate the step.param.attr=value routing syntax."""
18581858
app = build_cli_app()
1859-
result = runner.invoke(app, ["invoke", "--help"])
1859+
result = runner.invoke(app, ["--no-color", "invoke", "--help"])
18601860
help_text = result.stdout.lower()
18611861
assert result.exit_code == 0
18621862
assert "find_plot_by_name.plot_name" in help_text or "step.param.attr" in help_text

tests/core/test_localization.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,13 @@ def test_set_language_env(self, locale):
127127
assert _(TEST_STRING) == TEST_TRANSLATION_DICT[locale]
128128
del os.environ[LOCALE_ENVIRONMENT_VARIABLE_NAME]
129129

130+
@pytest.mark.usefixtures("environment_locale")
130131
def test_set_language_windows_locale_fallback(self):
131132
"""
132133
Test set_language falls back to the Windows user locale.
133134
"""
134-
with patch("moldflow.localization._get_windows_locale_name", return_value="ja-JP"):
135+
with patch("moldflow.localization.winreg.OpenKey", side_effect=FileNotFoundError), patch(
136+
"moldflow.localization._get_windows_locale_name", return_value="ja-JP"
137+
):
135138
_ = set_language(version=TEST_VERSION)
136139
assert _(TEST_STRING) == "テスト文字列"

0 commit comments

Comments
 (0)