merge
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 22 Oct 2010 13:10:37 +0200
changeset 6586 207dc5111af2
parent 6584 c4aa6186d3a3 (current diff)
parent 6585 9af22f2c0c4c (diff)
child 6588 f8320a8c3c9d
merge
devtools/__init__.py
devtools/testlib.py
--- a/devtools/__init__.py	Fri Oct 22 13:09:09 2010 +0200
+++ b/devtools/__init__.py	Fri Oct 22 13:10:37 2010 +0200
@@ -100,7 +100,14 @@
           }),
         ))
 
-    def __init__(self, appid, log_threshold=logging.CRITICAL+10):
+    def __init__(self, appid, apphome=None, log_threshold=logging.CRITICAL+10):
+        # must be set before calling parent __init__
+        if apphome is None:
+            if exists(self.appid):
+                apphome = abspath(self.appid)
+            else: # cube test
+                apphome = abspath('..')
+        self._apphome = apphome
         ServerConfiguration.__init__(self, appid)
         self.init_log(log_threshold, force=True)
         # need this, usually triggered by cubicweb-ctl
@@ -110,10 +117,7 @@
 
     @property
     def apphome(self):
-        if exists(self.appid):
-            return abspath(self.appid)
-        # cube test
-        return abspath('..')
+        return self._apphome
     appdatahome = apphome
 
     def load_configuration(self):
@@ -187,8 +191,10 @@
 # XXX merge with BaseApptestConfiguration ?
 class ApptestConfiguration(BaseApptestConfiguration):
 
-    def __init__(self, appid, log_threshold=logging.CRITICAL, sourcefile=None):
-        BaseApptestConfiguration.__init__(self, appid, log_threshold=log_threshold)
+    def __init__(self, appid, apphome=None,
+                 log_threshold=logging.CRITICAL, sourcefile=None):
+        BaseApptestConfiguration.__init__(self, appid, apphome,
+                                          log_threshold=log_threshold)
         self.init_repository = sourcefile is None
         self.sourcefile = sourcefile
 
--- a/devtools/test/unittest_dbfill.py	Fri Oct 22 13:09:09 2010 +0200
+++ b/devtools/test/unittest_dbfill.py	Fri Oct 22 13:10:37 2010 +0200
@@ -16,9 +16,7 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""unit tests for database value generator
-
-"""
+"""unit tests for database value generator"""
 
 import os.path as osp
 import re
@@ -56,7 +54,7 @@
         return [f.strip() for f in file(osp.join(DATADIR, 'firstnames.txt'))]
 
     def setUp(self):
-        config = ApptestConfiguration('data')
+        config = ApptestConfiguration('data', apphome=DATADIR)
         config.bootstrap_cubes()
         schema = config.load_schema()
         e_schema = schema.eschema('Person')
--- a/devtools/testlib.py	Fri Oct 22 13:09:09 2010 +0200
+++ b/devtools/testlib.py	Fri Oct 22 13:10:37 2010 +0200
@@ -24,8 +24,9 @@
 import os
 import sys
 import re
+import urlparse
+from os.path import dirname
 from urllib import unquote
-import urlparse
 from math import log
 from contextlib import contextmanager
 from warnings import warn
@@ -198,7 +199,9 @@
         try:
             return cls.__dict__['_config']
         except KeyError:
-            config = cls._config = cls.configcls(cls.appid)
+            home = join(dirname(sys.modules[self.__class__.__module__].__file__),
+                        cls.appid)
+            config = cls._config = cls.configcls(cls.appid, apphome=home)
             config.mode = 'test'
             return config