Skip to content

Commit

Permalink
Bug correct
Browse files Browse the repository at this point in the history
  • Loading branch information
Net-Mist committed Aug 27, 2019
1 parent 2b57c9a commit 505fe18
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ set1:
- When loading configuration using Config.load_conf(), you can specify the name of the config file you want to create or load, and you can also specify if you don't want a config file to be create or if you want to update the content of the current config file (usefull when adding new features)

## Tests
nosetest -v
nosetests -v



4 changes: 2 additions & 2 deletions distribute_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self):
def define_var(self, name, default, description, type, is_list=False, possible_values=None):
if self.namespace:
name = self.namespace + "." + name
name = name.lower()
name = name.lower()
variable = Variable(name, default, description, type, is_list, possible_values)
self.__add_variables(variable)

Expand Down Expand Up @@ -113,7 +113,7 @@ def get_var(cls, name):
path = name.split(".")
variables = cls.__instance.variables
for sub_path in path:
variables = variables[sub_path]
variables = variables[sub_path.lower()]

if type(variables) == Variable:
return variables.get_value()
Expand Down
10 changes: 10 additions & 0 deletions distribute_config/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def test_load_conf_4(self, mock_args):
self.assertEqual(Config.get_var("n1.v2"), 3)
self.assertEqual(Config.get_var("n1.v3"), False)


@mock.patch.dict(os.environ, {"N1__V3": "false"})
@mock.patch('argparse.ArgumentParser.parse_args',
return_value=argparse.Namespace(**{"n1.v1": 2, "n1.v2": 3}, c="conf.yml"))
Expand All @@ -144,3 +145,12 @@ def test_load_conf_5(self, mock_args):
self.assertEqual(Config.get_var("n1.v1"), 2)
self.assertEqual(Config.get_var("n1.v2"), 3)
self.assertEqual(Config.get_var("n1.v3"), False)

@mock.patch.dict(os.environ, {"VAR": "false"})
@mock.patch('argparse.ArgumentParser.parse_args',
return_value=argparse.Namespace(c="conf.yml"))
def test_load_bool(self, mock_args):
Config.clear()
Config.define_bool("VAR", True, "turn me false")
Config.load_conf(no_conf_file=True)
self.assertEqual(Config.get_var("VAR"), False)
3 changes: 3 additions & 0 deletions distribute_config/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def __init__(self, name, default, description, type, is_list=False, possible_val
self._possible_values = possible_values
self.set_value(default)

def __str__(self):
return f"name: {self.name}"

def get_value(self):
return self._value

Expand Down

0 comments on commit 505fe18

Please sign in to comment.