Loading src/climax/__main__.py +14 −19 Original line number Diff line number Diff line Loading @@ -390,6 +390,7 @@ def _install_new_max_instance( _sync_max_instance(root_directory, verbose=False) if choose_vocabulary_post_install: try: vocabulary_bundle_name = _choose_between( [ bundle.get("name") Loading @@ -398,23 +399,15 @@ def _install_new_max_instance( ], "vocabulaire à utiliser", ) print(root_directory) bundles_add(vocabulary_bundle_name, str(root_directory)) except (KeyboardInterrupt, TypeError): pass # Path(root_directory, "content_html", "fr").mkdir(exist_ok=True, parents=True) # welcome_page = Path(root_directory, "content_html", "fr", "index.html") # with open(welcome_page, "w", encoding="utf-8") as f: # f.write(WELCOME_PAGE) rich_print( "[bold]" + _("La nouvelle instance de MaX est prête dans {}").format(root_directory) + "[/bold]" ) # rich_print( # _( # 'Vous pouvez éventuellement installer un projet de démonstration avec "climax demo".' # ) # ) def _sync_max_instance(root_directory: Path, verbose=True): Loading Loading @@ -624,6 +617,8 @@ def _choose_between(values: List[str], label: str = "") -> str: terminal_menu = TerminalMenu(values, title=label) menu_entry_index = terminal_menu.show() if menu_entry_index is None: raise KeyboardInterrupt return values[menu_entry_index] except NotImplementedError: # mainly windows choice = None Loading tests.py +24 −1 Original line number Diff line number Diff line import unittest from src.climax.__main__ import MaXProjectConfig, dir_is_max, _sync_bundles from src.climax.__main__ import ( MaXProjectConfig, dir_is_max, _sync_bundles, _choose_between, ) from pathlib import Path import tempfile import subprocess import typer from unittest.mock import patch import types import sys TEST_CONFIG_FILE = "tests_assets/max_config.xml" Loading Loading @@ -171,6 +178,22 @@ class TestConfigFiles(unittest.TestCase): self.assertEqual(2, context.exception.exit_code) self.assertFalse(Path(failing_bundle_dir, ".installed").exists()) def test_choose_between_cancel_raises_keyboardinterrupt(self): fake_module = types.SimpleNamespace() class FakeTerminalMenu: def __init__(self, values, title=""): # noqa: ARG002 pass def show(self): return None fake_module.TerminalMenu = FakeTerminalMenu with patch.dict(sys.modules, {"simple_term_menu": fake_module}): with self.assertRaises(KeyboardInterrupt): _choose_between(["a"], "pick one") if __name__ == "__main__": unittest.main() Loading
src/climax/__main__.py +14 −19 Original line number Diff line number Diff line Loading @@ -390,6 +390,7 @@ def _install_new_max_instance( _sync_max_instance(root_directory, verbose=False) if choose_vocabulary_post_install: try: vocabulary_bundle_name = _choose_between( [ bundle.get("name") Loading @@ -398,23 +399,15 @@ def _install_new_max_instance( ], "vocabulaire à utiliser", ) print(root_directory) bundles_add(vocabulary_bundle_name, str(root_directory)) except (KeyboardInterrupt, TypeError): pass # Path(root_directory, "content_html", "fr").mkdir(exist_ok=True, parents=True) # welcome_page = Path(root_directory, "content_html", "fr", "index.html") # with open(welcome_page, "w", encoding="utf-8") as f: # f.write(WELCOME_PAGE) rich_print( "[bold]" + _("La nouvelle instance de MaX est prête dans {}").format(root_directory) + "[/bold]" ) # rich_print( # _( # 'Vous pouvez éventuellement installer un projet de démonstration avec "climax demo".' # ) # ) def _sync_max_instance(root_directory: Path, verbose=True): Loading Loading @@ -624,6 +617,8 @@ def _choose_between(values: List[str], label: str = "") -> str: terminal_menu = TerminalMenu(values, title=label) menu_entry_index = terminal_menu.show() if menu_entry_index is None: raise KeyboardInterrupt return values[menu_entry_index] except NotImplementedError: # mainly windows choice = None Loading
tests.py +24 −1 Original line number Diff line number Diff line import unittest from src.climax.__main__ import MaXProjectConfig, dir_is_max, _sync_bundles from src.climax.__main__ import ( MaXProjectConfig, dir_is_max, _sync_bundles, _choose_between, ) from pathlib import Path import tempfile import subprocess import typer from unittest.mock import patch import types import sys TEST_CONFIG_FILE = "tests_assets/max_config.xml" Loading Loading @@ -171,6 +178,22 @@ class TestConfigFiles(unittest.TestCase): self.assertEqual(2, context.exception.exit_code) self.assertFalse(Path(failing_bundle_dir, ".installed").exists()) def test_choose_between_cancel_raises_keyboardinterrupt(self): fake_module = types.SimpleNamespace() class FakeTerminalMenu: def __init__(self, values, title=""): # noqa: ARG002 pass def show(self): return None fake_module.TerminalMenu = FakeTerminalMenu with patch.dict(sys.modules, {"simple_term_menu": fake_module}): with self.assertRaises(KeyboardInterrupt): _choose_between(["a"], "pick one") if __name__ == "__main__": unittest.main()