Skip to content

Commit 7063a3f

Browse files
authored
Merge pull request #1949 from dbcli/RW/improve-cli-runner-test-coverage
Improve `cli_runner.py` test coverage
2 parents ac68fbd + 8e82205 commit 7063a3f

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Upcoming (TBD)
2+
==============
3+
4+
Internal
5+
---------
6+
* Improve test coverage for DSN variable expansion.
7+
8+
19
1.76.0 (2026/06/20)
210
==============
311

test/pytests/test_cli_runner.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,31 @@ def run_with_client(
7474
return client
7575

7676

77+
def test_expand_dsn_alias_env_var_returns_none() -> None:
78+
assert cli_runner.expand_dsn_alias_env_var(None, 'prod') is None
79+
80+
81+
def test_split_dsn_netloc_handles_user_without_password() -> None:
82+
assert cli_runner.split_dsn_netloc('user@host:3306') == ('user', None, 'host', '3306')
83+
84+
85+
def test_split_dsn_netloc_handles_empty_host() -> None:
86+
assert cli_runner.split_dsn_netloc('user:pass@') == ('user', 'pass', None, None)
87+
88+
89+
def test_split_dsn_netloc_handles_bracketed_ipv6_host() -> None:
90+
assert cli_runner.split_dsn_netloc('user:pass@[::1]:3306') == ('user', 'pass', '::1', '3306')
91+
92+
93+
def test_expand_dsn_alias_env_vars_rejects_non_integer_port(monkeypatch: pytest.MonkeyPatch) -> None:
94+
monkeypatch.setenv('MYCLI_TEST_DSN_PORT', 'not-an-int')
95+
96+
with pytest.raises(cli_runner.DsnAliasEnvVarError) as excinfo:
97+
cli_runner.expand_dsn_alias_env_vars('mysql://user:pass@host:${MYCLI_TEST_DSN_PORT}/db', 'prod')
98+
99+
assert str(excinfo.value) == 'Port in DSN alias prod must be an integer.'
100+
101+
77102
def test_run_from_cli_args_checkup_exits_zero(monkeypatch: pytest.MonkeyPatch) -> None:
78103
cli_args = make_cli_args()
79104
cli_args.checkup = True

0 commit comments

Comments
 (0)