|
13 | 13 |
|
14 | 14 | from poetry.core.constraints.version import Version |
15 | 15 |
|
| 16 | +from poetry.config.config import Config |
| 17 | +from poetry.console.exceptions import PoetryConsoleError |
16 | 18 | from poetry.toml.file import TOMLFile |
17 | 19 | from poetry.utils.env import GET_BASE_PREFIX |
18 | 20 | from poetry.utils.env import GET_PYTHON_VERSION_ONELINER |
@@ -1302,3 +1304,30 @@ def test_generate_env_name_uses_real_path( |
1302 | 1304 | venv_name1 = EnvManager.generate_env_name("simple-project", "the_real_dir") |
1303 | 1305 | venv_name2 = EnvManager.generate_env_name("simple-project", "linked_dir") |
1304 | 1306 | assert venv_name1 == venv_name2 |
| 1307 | + |
| 1308 | + |
| 1309 | +def test_create_venv_invalid_prompt_template_variable( |
| 1310 | + manager: EnvManager, poetry: Poetry, config: Config |
| 1311 | +) -> None: |
| 1312 | + config.merge({"virtualenvs": {"prompt": "{project_name}-{invalid_var}"}}) |
| 1313 | + |
| 1314 | + with pytest.raises(PoetryConsoleError) as exc_info: |
| 1315 | + manager.create_venv() |
| 1316 | + |
| 1317 | + assert "Invalid template variable 'invalid_var'" in str(exc_info.value) |
| 1318 | + assert "Valid variables are: {project_name}, {python_version}" in str( |
| 1319 | + exc_info.value |
| 1320 | + ) |
| 1321 | + |
| 1322 | + |
| 1323 | +def test_create_venv_malformed_prompt_template( |
| 1324 | + manager: EnvManager, poetry: Poetry, config: Config |
| 1325 | +) -> None: |
| 1326 | + config.merge({"virtualenvs": {"prompt": "{project_name"}}) # Missing closing brace |
| 1327 | + |
| 1328 | + with pytest.raises(PoetryConsoleError) as exc_info: |
| 1329 | + manager.create_venv() |
| 1330 | + |
| 1331 | + assert "Invalid template string in 'virtualenvs.prompt' setting" in str( |
| 1332 | + exc_info.value |
| 1333 | + ) |
0 commit comments