Skip to content

Commit

Permalink
Merge pull request #152 from indralab/config
Browse files Browse the repository at this point in the history
Testing config fix
  • Loading branch information
pagreene committed Nov 24, 2020
2 parents 8e7a486 + ef65cc2 commit 56df7db
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions indra_db/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def _get_urls_from_env(prefix):


def _load_config():
global CONFIG
assert isinstance(CONFIG, dict)
parser = ConfigParser()
parser.read(DB_CONFIG_PATH)
for section in parser.sections():
Expand All @@ -87,6 +89,10 @@ def _load_config():

# Handle general parameters
if section == 'general':
if def_dict.pop('testing', None) == 'true':
CONFIG['testing'] = True
else:
CONFIG['testing'] = False
CONFIG.update(def_dict)
continue

Expand Down Expand Up @@ -125,11 +131,8 @@ def _load_env_config():
env_is_testing = environ[TESTING_ENV_VAR].lower()
if env_is_testing == 'true':
CONFIG['testing'] = True
elif env_is_testing == 'false':
CONFIG['testing'] = False
else:
raise ValueError(f"Unknown option: {environ[TESTING_ENV_VAR]}, "
f"should be \"true\" or \"false\"")
CONFIG['testing'] = False

return

Expand Down Expand Up @@ -181,6 +184,7 @@ def run_in_test_mode(func):
@wraps(func)
def wrap_func(*args, **kwargs):
global CONFIG
assert isinstance(CONFIG, dict)
global TEST_RECORDS
TEST_RECORDS = []
orig_value = CONFIG['testing']
Expand All @@ -195,7 +199,8 @@ def wrap_func(*args, **kwargs):

def is_db_testing():
"""Check whether we are in testing mode."""
return CONFIG['testing']
assert isinstance(CONFIG, dict)
return CONFIG.get('testing', False)


class WontDoIt(Exception):
Expand Down

0 comments on commit 56df7db

Please sign in to comment.