From 6d799ab2a905d202bb5c244568e27858b97e4680 Mon Sep 17 00:00:00 2001 From: Timm Fitschen <timm.fitschen@ds.mpg.de> Date: Thu, 28 Mar 2019 11:11:23 +0100 Subject: [PATCH] TST: add tests for envvar configuration --- src/caosdb/configuration.py | 6 ++++- unittests/test_add_property.py | 5 ----- unittests/test_configuration.py | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 unittests/test_configuration.py diff --git a/src/caosdb/configuration.py b/src/caosdb/configuration.py index 3933845c..085ddff7 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 267e7f00..bd68f31b 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 00000000..6db63f6c --- /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")] -- GitLab