diff --git a/mutalyzer/config/__init__.py b/mutalyzer/config/__init__.py index 6956473134c8ee44bcbcecf1dd8522d95e9ab0ee..5617162b2061833f53d54827d3c1bdb98dfa9264 100644 --- a/mutalyzer/config/__init__.py +++ b/mutalyzer/config/__init__.py @@ -6,8 +6,9 @@ module and overridden by any values from the module specified by the `MUTALYZER_SETTINGS`. Alternatively, the default values can be overridden manually using the -:meth:`settings.configure` method, in which case the `MUTALYZER_SETTINGS` -environment variable will not be used. +:meth:`settings.configure` method before the first use of a configuration +value, in which case the `MUTALYZER_SETTINGS` environment variable will not be +used. """ @@ -40,28 +41,24 @@ class LazySettings(util.LazyObject): .. note:: Django also does some logging config magic here, we did not copy that. """ - def _setup(self, settings=None): + def _setup(self, from_environment=True): """ Load the settings module pointed to by the environment variable. This is used the first time we need any settings at all, if the user has not - previously configured the settings manually. + previously configured the settings manually with :meth:`configure`. """ self._wrapped = Settings() self._wrapped.from_object('mutalyzer.config.default_settings') - if settings is None: + if from_environment: self._wrapped.from_envvar(ENVIRONMENT_VARIABLE) - else: - self._wrapped.update(settings) def configure(self, settings): """ - Called to manually configure the settings. The 'default_settings' - parameter sets where to retrieve any unspecified values from (its - argument must support attribute access (__getattr__)). + Called to manually configure the settings. """ - if self._wrapped is not None: - raise RuntimeError('settings already configured') - self._setup(settings) + if self._wrapped is None: + self._setup(from_environment=False) + self._wrapped.update(settings) @property def configured(self): diff --git a/mutalyzer/config/default_settings.py b/mutalyzer/config/default_settings.py index bc4b12cf9ab2d0d9298b888bb58f848422e3045a..3d2e33cdeffb2505a50ae39b8226b92ee663440a 100644 --- a/mutalyzer/config/default_settings.py +++ b/mutalyzer/config/default_settings.py @@ -7,6 +7,9 @@ pointed-to by the `MUTALYZER_SETTINGS` environment variable. # Use Mutalyzer in debug mode. DEBUG = True +# We are running unit tests. +TESTING = False + # This address is used in contact information on the website, as sender in # batch job notifications, and with retrieval of records at the NCBI using # Entrez. diff --git a/tests/test_crossmap.py b/tests/test_crossmap.py index 230a70835978596ab431a733349cd87ce68323fc..d0f604111f5156cc64d61a03db3ee52dcdcd5551 100644 --- a/tests/test_crossmap.py +++ b/tests/test_crossmap.py @@ -3,6 +3,10 @@ Tests for the Crossmap module. """ +from utils import TEST_SETTINGS +from mutalyzer.config import settings +settings.configure(TEST_SETTINGS) + #import logging; logging.basicConfig() from nose.tools import * diff --git a/tests/test_describe.py b/tests/test_describe.py index c7a5560f52093ab25ac166fe9da4a7490f2f3dd3..d4a3a96c5c3af4febd5bdeab351d5c8af9a7f73e 100644 --- a/tests/test_describe.py +++ b/tests/test_describe.py @@ -3,6 +3,10 @@ Tests for the mutalyzer.describe module. """ +from utils import TEST_SETTINGS +from mutalyzer.config import settings +settings.configure(TEST_SETTINGS) + #import logging; logging.basicConfig() import os from nose.tools import * diff --git a/tests/test_grammar.py b/tests/test_grammar.py index a27b473d1da39d3ff103222ee22d7fa83065af74..2a20abd567befc512319f51081b5421f8bdcc64c 100644 --- a/tests/test_grammar.py +++ b/tests/test_grammar.py @@ -3,6 +3,10 @@ Tests for the mutalyzer.grammar module. """ +from utils import TEST_SETTINGS +from mutalyzer.config import settings +settings.configure(TEST_SETTINGS) + #import logging; logging.basicConfig() import os from nose.tools import * diff --git a/tests/test_mapping.py b/tests/test_mapping.py index 1732d9aff37ccdb86c257dc5b2e3a0885874389c..33674e0ce30c2f92de860a6dd5dc494db8cb010f 100644 --- a/tests/test_mapping.py +++ b/tests/test_mapping.py @@ -3,6 +3,10 @@ Tests for the mapping module. """ +from utils import TEST_SETTINGS +from mutalyzer.config import settings +settings.configure(TEST_SETTINGS) + #import logging; logging.basicConfig() from nose.tools import * diff --git a/tests/test_mutator.py b/tests/test_mutator.py index f6ff2dfcf99b893c89dd47783c701a1f063f9aa0..8b32e8f6cf9f510068201fe5c8d340ab625d49ac 100644 --- a/tests/test_mutator.py +++ b/tests/test_mutator.py @@ -3,6 +3,10 @@ Tests for the mutalyzer.mutator module. """ +from utils import TEST_SETTINGS +from mutalyzer.config import settings +settings.configure(TEST_SETTINGS) + #import logging; logging.basicConfig() import re import os diff --git a/tests/test_parsers_genbank.py b/tests/test_parsers_genbank.py index c7da5791480c540542d7f91d72eb0abfb85332f3..a04aa5fa92ada0161661166d7f9a3faa6ff03ae5 100644 --- a/tests/test_parsers_genbank.py +++ b/tests/test_parsers_genbank.py @@ -3,6 +3,10 @@ Tests for the mutalyzer.parsers.genbank module. """ +from utils import TEST_SETTINGS +from mutalyzer.config import settings +settings.configure(TEST_SETTINGS) + #import logging; logging.basicConfig() from nose.tools import * diff --git a/tests/test_services_json.py b/tests/test_services_json.py index 0b2357812aec870e252dbdec6147921baa1c6096..35bbd180779c9c47ac87c052873b8d0f75a16d5d 100644 --- a/tests/test_services_json.py +++ b/tests/test_services_json.py @@ -3,6 +3,10 @@ Tests for the JSON interface to Mutalyzer. """ +from utils import TEST_SETTINGS +from mutalyzer.config import settings +settings.configure(TEST_SETTINGS) + from nose.tools import * import simplejson as json from spyne.server.null import NullServer diff --git a/tests/test_services_soap.py b/tests/test_services_soap.py index 09f9961528f6de650b03a82af854c4fecfefe6d1..cea1ca25be976e2e633ac11c0393e2c216661d12 100644 --- a/tests/test_services_soap.py +++ b/tests/test_services_soap.py @@ -3,6 +3,10 @@ Tests for the SOAP interface to Mutalyzer. """ +from utils import TEST_SETTINGS +from mutalyzer.config import settings +settings.configure(TEST_SETTINGS) + import datetime import logging import os diff --git a/tests/test_variantchecker.py b/tests/test_variantchecker.py index a9d44a86e6c7e354bade8bff1b23dc1ce57a89ee..78033e3fe3151a4a719049396574b118e71c0b31 100644 --- a/tests/test_variantchecker.py +++ b/tests/test_variantchecker.py @@ -3,6 +3,10 @@ Tests for the variantchecker module. """ +from utils import TEST_SETTINGS +from mutalyzer.config import settings +settings.configure(TEST_SETTINGS) + #import logging; logging.basicConfig() from nose.tools import * diff --git a/tests/test_website.py b/tests/test_website.py index 52e507950cbc5537561b4582ee5f7fba918e214f..02b1de9f1151bf53c567eecf7f13a65731a8868e 100644 --- a/tests/test_website.py +++ b/tests/test_website.py @@ -11,6 +11,10 @@ I just installed webtest by 'easy_install webtest'. """ +from utils import TEST_SETTINGS +from mutalyzer.config import settings +settings.configure(TEST_SETTINGS) + #import logging; logging.basicConfig() import os import re diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..c119d67b57149e95435f302dc0f17a98be30bad9 --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,14 @@ +import os +import tempfile + + +log_handle, log_filename = tempfile.mkstemp() +os.close(log_handle) + + +TEST_SETTINGS = dict( + DEBUG = True, + TESTING = True, + CACHE_DIR = tempfile.mkdtemp(), + LOG_FILE = log_filename +)