-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Boxed plugin can only get a static hard-coded configuration, delivered as a resource inside a Python package. It cannot be overridden without explicit change of a package-delivered data. This is also makes it impossible to programmatically integrate it with Kiwi as a library. Under these circumstances, a cascading mechanism is required, which is searching for the configuration file in the following order: * $KIWI_BOXED_PLUGIN_CFG full path, the name can be anything * Current directory, from where a software was called * $HOME/.config/kiwi/kiwi_boxed_plugin.yml * /etc/kiwi_boxed_plugin.yml * Resource (default config, coming with the package)
- Loading branch information
Showing
3 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,6 @@ doc/xml/ | |
|
||
# man pages | ||
*.1.gz | ||
|
||
# VSC | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,52 @@ | ||
from pkg_resources import resource_filename | ||
|
||
from kiwi_boxed_plugin.defaults import Defaults | ||
from mock import patch | ||
import os | ||
|
||
|
||
class MockedPath: | ||
def __init__(self): | ||
self.p: str | None = None | ||
|
||
def home(self): | ||
return self | ||
|
||
@staticmethod | ||
def exists(): | ||
return True | ||
|
||
def joinpath(self, f: str): | ||
self.p = os.path.join("/home/zoidberg", f) | ||
return self | ||
|
||
def as_posix(self): | ||
return self.p | ||
|
||
|
||
class TestDefaults: | ||
def test_get_plugin_config_file(self): | ||
assert Defaults.get_plugin_config_file() == resource_filename( | ||
'kiwi_boxed_plugin', 'config/kiwi_boxed_plugin.yml' | ||
) | ||
|
||
@patch("os.path.exists", lambda f: True) | ||
@patch.dict(os.environ, KIWI_BOXED_PLUGIN_CFG="aarchderwelt.conf") | ||
def test_get_plugin_config_file_env(self): | ||
assert Defaults.get_plugin_config_file() == "aarchderwelt.conf", \ | ||
"aarch64 aonfiguration from the environment variable do not match" | ||
|
||
@patch("os.path.abspath", lambda f: "/highway/to/hell.conf") | ||
@patch("os.path.exists", lambda f: True) | ||
def test_get_plugin_config_file_currdir(self): | ||
assert Defaults.get_plugin_config_file() == "/highway/to/hell.conf", \ | ||
"Should contain absolute path to the config" | ||
|
||
@patch("pathlib.Path", MockedPath()) | ||
def test_get_plugin_config_file_local_kiwi(self): | ||
assert Defaults.get_plugin_config_file() == "/home/zoidberg/.config/kiwi/kiwi_boxed_plugin.yml", \ | ||
"Should contain local Kiwi Box config" | ||
|
||
@patch("os.path.exists", lambda f: f == "/etc/kiwi_boxed_plugin.yml") | ||
def test_get_plugin_config_file_etc(self): | ||
assert Defaults.get_plugin_config_file() == "/etc/kiwi_boxed_plugin.yml", \ | ||
"Should contain Kiwi Box config in /etc dir" |