Skip to content

Commit

Permalink
Merge pull request #32 from Dandb79/master
Browse files Browse the repository at this point in the history
Fixed environment overriding default within a subclass issue
  • Loading branch information
AdmiralObvious authored Mar 25, 2020
2 parents 2bd9592 + 5a6d672 commit ddc6141
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
13 changes: 13 additions & 0 deletions tests/test_vyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,19 @@ def test_toml(self):
self._init_toml()
self.assertEqual("TOML Example", self.v.get("title"))

def test_env_override_default_subclass(self):
os.environ['CLASS.KEY2'] = 'newval2'

self.v.set_default('class.key1', 'val1')
self.v.set_default('class.key2', 'val2')
self.v.set_default('class.key3', 'val3')

self.v.bind_env('class.key1')
self.v.bind_env('class.key2')
self.v.bind_env('class.key3')

self.assertEqual('val1', self.v.get('class.key1'))

def test_env(self):
self._init_json()

Expand Down
16 changes: 9 additions & 7 deletions vyper/vyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,14 @@ def _find_insensitive(self, key, source):
return source.get(real_key)

def _set_insensitive(self, key, val, source):
real_key = self._find_real_key(key, source)
if real_key is None:
msg = "No case insensitive variant of {0} found.".format(key)
raise KeyError(msg)
if source:
real_key = self._find_real_key(key, source)
if real_key is None:
msg = "No case insensitive variant of {0} found.".format(key)
raise KeyError(msg)

source[real_key] = val
source[real_key] = val
return True

def _find(self, key):
"""Given a key, find the value
Expand Down Expand Up @@ -385,8 +387,8 @@ def _find(self, key):
real_key = self._find_real_key(path, temp)
temp = temp[real_key]

self._set_insensitive(item["final_key"], val, temp)
found_in_env = True
if self._set_insensitive(item["final_key"], val, temp):
found_in_env = True
else:
log.debug("{0} env value unset".format(item["env_key"]))

Expand Down

0 comments on commit ddc6141

Please sign in to comment.