diff --git a/src/caosdb/configuration.py b/src/caosdb/configuration.py index 3933845c448da8d6164447aeec76b3aa2c65a929..085ddff7fd9919d35379a1ff6a6fe09146493d89 100644 --- a/src/caosdb/configuration.py +++ b/src/caosdb/configuration.py @@ -35,12 +35,16 @@ def _reset_config(): def configure(inifile): + """ read config from file. + + Return a list of files which have successfully been parsed. + """ global _pycaosdbconf if "_pycaosdbconf" not in globals(): _pycaosdbconf = None if _pycaosdbconf is None: _reset_config() - _pycaosdbconf.read(inifile) + return _pycaosdbconf.read(inifile) def get_config(): diff --git a/unittests/test_add_property.py b/unittests/test_add_property.py index 267e7f00011d55dba4ca5876df383f26dbed1e4a..bd68f31b89c439c2bd333586b65d9f012b09d7e3 100644 --- a/unittests/test_add_property.py +++ b/unittests/test_add_property.py @@ -21,12 +21,7 @@ # # ** end header # -"""Created on 19.06.2017. - -@author: tf -""" import caosdb as db -# @UnresolvedImport from nose.tools import assert_is, assert_is_none, assert_equals, assert_is_not_none, assert_raises diff --git a/unittests/test_configuration.py b/unittests/test_configuration.py new file mode 100644 index 0000000000000000000000000000000000000000..6db63f6cf4839c6d4a606bda43c010e11c7b5451 --- /dev/null +++ b/unittests/test_configuration.py @@ -0,0 +1,39 @@ +# -*- 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")]