Skip to content
This repository has been archived by the owner on Oct 3, 2021. It is now read-only.

Commit

Permalink
Colorize terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
rednafi committed Nov 5, 2020
1 parent ac25895 commit e288455
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 12 additions & 4 deletions konfik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ def _load_config(self):
return self._load_yaml(config_path)

else:
raise NotImplementedError(f"Config type '{self._config_ext}' is not supported")
raise NotImplementedError(
f"Config type '{self._config_ext}' is not supported"
)

@staticmethod
def _load_env(config_path):
Expand All @@ -187,7 +189,9 @@ def _load_env(config_path):
try:
# Instead of using load_dotenv(), this is done to avoid recursively searching for dotenv file.
# There is no element of surprise. If the file is not found in the explicit path, this will raise an error!
dotenv_file = find_dotenv(filename=config_path, raise_error_if_not_found=True, usecwd=True)
dotenv_file = find_dotenv(
filename=config_path, raise_error_if_not_found=True, usecwd=True
)

if dotenv_file:
config = dotenv_values(dotenv_file)
Expand Down Expand Up @@ -233,15 +237,19 @@ def get_by_path(dct, key_list):
try:
return reduce(operator.getitem, key_list, dct)
except KeyError as e:
raise MissingVariableError(f"No such variable '{e.args[0]}' exists") from None
raise MissingVariableError(
f"No such variable '{e.args[0]}' exists"
) from None


class KonfikCLI:
"""Access and show config variables using CLI."""

def build_parser(self):
parser = argparse.ArgumentParser(
description=colorize.colorize_title("\nKonfik -- The strangely familiar config parser ⚙️\n")
description=colorize.colorize_title(
"\nKonfik -- The strangely familiar config parser ⚙️\n"
)
)

# Add arguments
Expand Down
6 changes: 1 addition & 5 deletions tests/test_konfik.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ def test_konfik(tmp_path, toml_str):
assert konfik._config_ext == "toml"



def test_konfik_toml(tmp_path, toml_str, capfd):
"""Test the Konfik class for toml."""

Expand Down Expand Up @@ -262,7 +261,6 @@ def test_konfik_env(tmp_path, dotenv_str):
assert config.IP == "10.0.0.1"
assert config.DC == "eqdc10"


with pytest.raises(MissingVariableError):
config.fakekey

Expand Down Expand Up @@ -307,7 +305,6 @@ def test_konfik_json(tmp_path, json_str, capfd):

assert config.clients.data == [["gamma", "delta"], [1, 2]]


with pytest.raises(MissingVariableError):
config.fakekey

Expand Down Expand Up @@ -350,7 +347,6 @@ def test_konfik_yaml(tmp_path, yaml_str, capfd):

assert config.clients.data == [["gamma", "delta"], [1, 2]]


with pytest.raises(MissingVariableError):
config.fakekey

Expand All @@ -363,4 +359,4 @@ def test_konfik_cli(tmp_path, toml_str, capfd):
# Load toml from the test toml path
konfik_cli = KonfikCLI()
parser = konfik_cli.build_parser()
#args = parser.parse_args()
# args = parser.parse_args()

0 comments on commit e288455

Please sign in to comment.