diff --git a/armarx_setup/core/config.py b/armarx_setup/core/config.py index e6cf24b3ad51ee642849305ae926d91babb07fd6..e6b483aab842d1ac1db14d829661a4cb41021284 100644 --- a/armarx_setup/core/config.py +++ b/armarx_setup/core/config.py @@ -624,7 +624,7 @@ class AxiiConfig: cfg.set(cfg_name, value, parse=parse) else: nested_cfg.set(nested_name, value, parse=parse) - cfg.set(cfg_name, cfg, parse=False) + cfg.set(cfg_name, nested_cfg, parse=False) def unset(self, name: str, is_global: bool = True): """Unset a variable.""" diff --git a/tests/e2e/__init__.py b/tests/e2e/__init__.py index 8b9be92dc0b1d6d3e23dbb8b1f962a28348945cb..561bc120094d0b89699aa45fd863e3816149ea44 100644 --- a/tests/e2e/__init__.py +++ b/tests/e2e/__init__.py @@ -1,4 +1,42 @@ +import os +import pytest + +from armarx_setup.core.config import axii_config +from armarx_setup.core.util.commands import run +from armarx_setup.core.workspace import Workspace + + cmd_args = { "capture_output": True, "quiet": True } + + +@pytest.fixture() +def test_workspace(): + """ + Fixture to create a workspace, supply it as "test_workspace", and destroy it afterwards. + """ + + workspace_name = "test_workspace" + workspace_path = os.path.join("/tmp", workspace_name) + + run(f"axii workspace create {workspace_path} {workspace_name}", **cmd_args) + axii_config.load_known_workspaces() + + workspace = Workspace.load_workspace_by_path(workspace_path) + + # Simulate activating workspace. + os.environ["ARMARX_WORKSPACE"] = workspace_path + + yield workspace + + run(f"axii workspace purge {workspace_name} --yes") + + # Simulate deactivating workspace. + del os.environ["ARMARX_WORKSPACE"] + + + + + diff --git a/tests/e2e/test_axii_config.py b/tests/e2e/test_axii_config.py new file mode 100644 index 0000000000000000000000000000000000000000..9e9796ddcc1c20ac5fdf45800ac16bee2ab40673 --- /dev/null +++ b/tests/e2e/test_axii_config.py @@ -0,0 +1,65 @@ +""" +Tests `axii config` functionalities. +""" + +import os +import pytest + +from armarx_setup.core import error +from armarx_setup.core.config import axii_config +from armarx_setup.core.util.commands import run +from armarx_setup.core.workspace import Workspace + +from tests.e2e import cmd_args, test_workspace + + +variable_name = "e2e_test_var" +variable_value = "true" + + +def test_get_nonexistent_global_config_var(): + """ + Test getting non-existent global config variable. + """ + + try: + run(f"axii config --global {variable_name}", **cmd_args) + except error.CommandFailed as e: + stdout = e.stdout + return_code = e.return_code + else: + stdout = "" + return_code = 0 + + assert return_code == 1, "Return code should be 1." + assert f"No such config variable '{variable_name}'." in stdout + + +def test_set_global_config_var(): + """ + Test setting global config variable. + """ + + stdout = run(f"axii config --global {variable_name} {variable_value}", **cmd_args) + + assert stdout == f"Set '{variable_name}' (global) to {variable_value}." + + +def test_get_global_config_var(): + """ + Test getting global config variable. + """ + + stdout = run(f"axii config --global {variable_name}", **cmd_args) + + assert stdout == "true" + + +def test_unset_global_config_var(): + """ + Test unsetting global config variable. + """ + + stdout = run(f"axii config --global --unset {variable_name}", **cmd_args) + + assert stdout == f"Unset '{variable_name}' (global)." diff --git a/tests/e2e/test_axii_workspace.py b/tests/e2e/test_axii_workspace.py index 79e9502b8cd38fc90de00b84eee451da27f24b81..aa3d963bbc8d8f03832d9265d8642461c9e548a2 100644 --- a/tests/e2e/test_axii_workspace.py +++ b/tests/e2e/test_axii_workspace.py @@ -10,32 +10,7 @@ from armarx_setup.core.config import axii_config from armarx_setup.core.util.commands import run from armarx_setup.core.workspace import Workspace -from tests.e2e import cmd_args - - -@pytest.fixture() -def test_workspace(): - """ - Fixture to create a workspace, supply it as "test_workspace", and destroy it afterwards. - """ - - workspace_name = "test_workspace" - workspace_path = os.path.join("/tmp", workspace_name) - - run(f"axii workspace create {workspace_path} {workspace_name}", **cmd_args) - axii_config.load_known_workspaces() - - workspace = Workspace.load_workspace_by_path(workspace_path) - - # Simulate activating workspace. - os.environ["ARMARX_WORKSPACE"] = workspace_path - - yield workspace - - run(f"axii workspace purge {workspace_name} --yes") - - # Simulate deactivating workspace. - del os.environ["ARMARX_WORKSPACE"] +from tests.e2e import cmd_args, test_workspace def test_workspace_create_and_purge():