Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions moban/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,17 @@ def get_data(self, file_name):
data = utils.open_json(self.context_dirs, file_name)
elif file_extension in [".yml", ".yaml"]:
data = utils.open_yaml(self.context_dirs, file_name)
utils.merge(data, self.__cached_environ_variables)
else:
raise exceptions.IncorrectDataInput
utils.merge(data, self.__cached_environ_variables)
return data
except Exception as exception:
except (IOError, exceptions.IncorrectDataInput) as exception:
# If data file doesn't exist:
# 1. Alert the user of their (potential) mistake
# 2. Attempt to use environment vars as data
reporter.report_info_message(str(exception))
reporter.report_warning_message(str(exception))
reporter.report_using_env_vars()
data = os.environ
return data
return self.__cached_environ_variables


def make_sure_all_pkg_are_loaded():
Expand Down
18 changes: 18 additions & 0 deletions tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,21 @@ def test_environ_variables():
context = Context(os.path.join("tests", "fixtures"))
data = context.get_data("simple.yaml")
eq_(data[test_var], test_value)


def test_json_data_overrides_environ_variables():
test_var = "TEST_ENVIRONMENT_VARIABLE"
test_value = "am I found"
os.environ[test_var] = test_value
context = Context(os.path.join("tests", "fixtures"))
data = context.get_data("simple.json")
eq_(data[test_var], test_value)


def test_unknown_data_file():
test_var = "TEST_ENVIRONMENT_VARIABLE"
test_value = "am I found"
os.environ[test_var] = test_value
context = Context(os.path.join("tests", "fixtures"))
data = context.get_data("unknown.data")
eq_(data[test_var], test_value)