Skip to content
Snippets Groups Projects
Unverified Commit 6d799ab2 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

TST: add tests for envvar configuration

parent b1344dd4
Branches
Tags
No related merge requests found
...@@ -35,12 +35,16 @@ def _reset_config(): ...@@ -35,12 +35,16 @@ def _reset_config():
def configure(inifile): def configure(inifile):
""" read config from file.
Return a list of files which have successfully been parsed.
"""
global _pycaosdbconf global _pycaosdbconf
if "_pycaosdbconf" not in globals(): if "_pycaosdbconf" not in globals():
_pycaosdbconf = None _pycaosdbconf = None
if _pycaosdbconf is None: if _pycaosdbconf is None:
_reset_config() _reset_config()
_pycaosdbconf.read(inifile) return _pycaosdbconf.read(inifile)
def get_config(): def get_config():
......
...@@ -21,12 +21,7 @@ ...@@ -21,12 +21,7 @@
# #
# ** end header # ** end header
# #
"""Created on 19.06.2017.
@author: tf
"""
import caosdb as db import caosdb as db
# @UnresolvedImport
from nose.tools import assert_is, assert_is_none, assert_equals, assert_is_not_none, assert_raises from nose.tools import assert_is, assert_is_none, assert_equals, assert_is_not_none, assert_raises
......
# -*- encoding: utf-8 -*-
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
import caosdb as db
from pytest import raises
def test_config_ini_via_envvar():
from os import environ
from os.path import expanduser
with raises(KeyError):
environ["PYCAOSDBINI"]
environ["PYCAOSDBINI"] = "bla bla"
assert environ["PYCAOSDBINI"] == "bla bla"
assert db.configuration.configure(environ["PYCAOSDBINI"]) == []
environ["PYCAOSDBINI"] = "~/.pycaosdb.ini"
assert db.configuration.configure(expanduser(environ["PYCAOSDBINI"])) == [expanduser("~/.pycaosdb.ini")]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment