Skip to content

Commit

Permalink
feat: Add system config path for Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Luttrell <[email protected]>
  • Loading branch information
roblutt committed Nov 28, 2023
1 parent ac80ce7 commit a9171dd
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 22 deletions.
3 changes: 0 additions & 3 deletions src/openjd/adaptor_runtime/_background/frontend_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ def init(
shell=False,
close_fds=True,
start_new_session=True,
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
except Exception as e:
_logger.error(f"Failed to initialize backend process: {e}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,33 @@ def create_adaptor_configuration_manager(
elif isinstance(schema_path, list):
schema_paths.extend(schema_path)

system_config_path_map = {
"Linux": posixpath.abspath(
posixpath.join(
posixpath.sep,
"etc",
"openjd",
"adaptors",
adaptor_name,
f"{adaptor_name}.json",
)
),
# TODO: Confirm the windows path format
"Windows": f"C:/tmp/{adaptor_name}/{adaptor_name}.json",
}
if OSName.is_posix():
system_config_path_map = {
"Linux": posixpath.abspath(
posixpath.join(
posixpath.sep,
"etc",
"openjd",
"adaptors",
adaptor_name,
f"{adaptor_name}.json",
)
),
}

elif OSName.is_windows():
system_config_path_map = {
"Windows": os.path.abspath(
os.path.join(
os.path.sep,
os.environ["PROGRAMDATA"],
"openjd",
"adaptors",
adaptor_name,
f"{adaptor_name}.json",
)
),
}
user_config_rel_path = os.path.join(".openjd", "adaptors", adaptor_name, f"{adaptor_name}.json")

return ConfigurationManager(
Expand Down
7 changes: 7 additions & 0 deletions test/openjd/adaptor_runtime/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def pytest_collection_modifyitems(items):
"integ",
"test_integration_entrypoint.py",
),
os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"unit",
"adaptors",
"configuration",
"test_configuration_manager.py",
),
]
skip_marker = pytest.mark.skip(reason="Skipping tests on Windows")
for item in items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ def test_create(
assert f"Could not write empty configuration to {path}: " in caplog.text


class TestCreateAdaptorConfigurationManager:
"""
Tests for the create_adaptor_configuration_manager function.
"""

@pytest.mark.skipif(not osname.is_posix())
class TestCreateAdaptorConfigurationManagerPosix:
def test_creates_config_manager(self):
"""
This test is fragile as it relies on the hardcoded path formats to adaptor config files.
Expand Down Expand Up @@ -162,6 +159,54 @@ def test_creates_config_manager(self):
os.path.join(_configuration_manager_dir, "_adaptor_configuration.schema.json")
)


@pytest.mark.skipif(not osname.is_windows())
class TestCreateAdaptorConfigurationManagerWindows:
def test_creates_config_manager(self):
"""
This test is fragile as it relies on the hardcoded path formats to adaptor config files.
"""
# GIVEN
adaptor_name = "adaptor"
default_config_path = "/path/to/config"

# WHEN
result = _create_adaptor_configuration_manager(
_AdaptorConfiguration,
adaptor_name,
default_config_path,
)

# THEN
assert result._config_cls == _AdaptorConfiguration
assert result._default_config_path == default_config_path
assert result._system_config_path_map["Windows"] == (
os.path.abspath(
os.path.join(
os.path.sep,
os.environ["PROGRAMDATA"],
"openjd",
"adaptors",
adaptor_name,
f"{adaptor_name}.json",
)
)
)
assert result._user_config_rel_path == os.path.join(
".openjd", "adaptors", adaptor_name, f"{adaptor_name}.json"
)
assert isinstance(result._schema_path, list)
assert len(result._schema_path) == 1
assert result._schema_path[0] == os.path.abspath(
os.path.join(_configuration_manager_dir, "_adaptor_configuration.schema.json")
)


class TestCreateAdaptorConfigurationManager:
"""
Tests for the create_adaptor_configuration_manager function.
"""

def test_accepts_single_schema(self):
# GIVEN
adaptor_name = "adaptor"
Expand Down Expand Up @@ -499,6 +544,19 @@ def test_gets_linux_path(self, mock_system: MagicMock):
mock_system.assert_called_once()
assert result == expected

@patch.object(osname.platform, "system")
def test_gets_windows_path(self, mock_system: MagicMock):
# GIVEN
mock_system.return_value = "Windows"
expected = "path\\to\\windows\\system\\config"
manager = ConfigurationManagerMock(system_config_path_map={"Windows": expected})

# WHEN
result = manager.get_system_config_path()

# THEN
assert result == expected

@patch.object(osname.platform, "system")
def test_raises_on_nonvalid_os(self, mock_system: MagicMock):
"""
Expand Down

0 comments on commit a9171dd

Please sign in to comment.