[test] fix tests when executed in an apycot environment
authorDavid Douard <david.douard@logilab.fr>
Wed, 14 May 2014 22:28:57 +0200
changeset 1520 0abe241164e2
parent 1519 2a8d6cfd864b
child 1521 2f7557eabc54
[test] fix tests when executed in an apycot environment ie. when tests are executed from sources towards an installed apycot. The fix consist mainly in "moving" the input_path function from testutils.py (which is part of the installed modules) into unittest_checkers.py so we are sure we look for test data files relatively to the test directory (and not the location of the installation).
test/unittest_checkers.py
test/unittest_checkers_pyunit.py
test/unittest_hooks.py
test/unittest_task.py
testutils.py
--- a/test/unittest_checkers.py	Wed May 14 22:11:38 2014 +0200
+++ b/test/unittest_checkers.py	Wed May 14 22:28:57 2014 +0200
@@ -8,18 +8,21 @@
 import os
 import tarfile
 import shutil
-from os.path import join
+from os.path import join, dirname, abspath
 
 from logilab.common.testlib import unittest_main, TestCase, TestSuite
 
 import cubicweb.devtools
-from cubes.apycot.testutils import MockTest, MockRepository, MockCheckWriter, input_path
-
+from cubes.apycot.testutils import MockTest, MockRepository, MockCheckWriter
 
 from apycotlib import SUCCESS, FAILURE, PARTIAL, NODATA, ERROR
+
 from checkers.apycot.python import *
 from checkers.apycot.debcheck import *
 
+def input_path(path=''):
+    return join(dirname(abspath(__file__)), 'data', path)
+
 WRITER = MockCheckWriter()
 
 
--- a/test/unittest_checkers_pyunit.py	Wed May 14 22:11:38 2014 +0200
+++ b/test/unittest_checkers_pyunit.py	Wed May 14 22:28:57 2014 +0200
@@ -9,11 +9,13 @@
 from logilab.common.testlib import unittest_main, TestCase, mock_object
 
 import cubicweb.devtools
-from cubes.apycot.testutils import MockCheckWriter, input_path
+from cubes.apycot.testutils import MockCheckWriter
 
 from apycotlib import SUCCESS, FAILURE, ERROR, PARTIAL, NODATA
 from checkers.apycot import python
 
+from unittest_checkers import input_path
+
 def _test_cmd(self, cmd, status, success=0, failures=0, errors=0, skipped=0):
 
     for name, got, expected in (
--- a/test/unittest_hooks.py	Wed May 14 22:11:38 2014 +0200
+++ b/test/unittest_hooks.py	Wed May 14 22:28:57 2014 +0200
@@ -9,7 +9,7 @@
 
 from cubes.vcsfile import bridge
 from cubes.apycot.hooks import start_period_tests
-from cubes.apycot.testutils import INPUTS_DIR, ApycotBaseTC
+from cubes.apycot.testutils import ApycotBaseTC
 
 
 def clean_str(string):
--- a/test/unittest_task.py	Wed May 14 22:11:38 2014 +0200
+++ b/test/unittest_task.py	Wed May 14 22:28:57 2014 +0200
@@ -10,13 +10,14 @@
 
 # import this first will set import machinery on
 import cubicweb.devtools
-from cubes.apycot.testutils import MockTestWriter, MockRepository, MockConnection, MockVCSFile, input_path
+from cubes.apycot.testutils import MockTestWriter, MockRepository, MockConnection, MockVCSFile
 
 from apycotlib import SetupException
 from apycotlib import SUCCESS, FAILURE, PARTIAL, SKIPPED
 from apycotlib.atest import Test as BaseTest
 from apycotlib.repositories import SVNRepository
 
+from unittest_checkers import input_path
 # manage temporary repo
 def setUpModule():
     for repo in ('badpkg2_svn', 'goodpkg_svn'):
--- a/testutils.py	Wed May 14 22:11:38 2014 +0200
+++ b/testutils.py	Wed May 14 22:28:57 2014 +0200
@@ -4,12 +4,6 @@
 from datetime import datetime
 from os.path import join, dirname, abspath
 
-# MUST be done BEFORE importing narvalbot
-INPUTS_DIR = abspath(join(dirname(__file__), 'test', 'data'))
-def input_path(file=''):
-    return join(INPUTS_DIR, file)
-os.environ['NARVALSOURCES'] = input_path('narval-cw-sources.ini')
-
 from logilab.common.testlib import mock_object
 
 from cubicweb.devtools.testlib import CubicWebTC
@@ -24,8 +18,13 @@
     from cubes.apycot import _apycotlib as apycotlib
 sys.modules['apycotlib'] = apycotlib
 
-sys.path.append(join(dirname(__file__), '_narval'))
-
+import narvalbot
+if narvalbot.MODE == 'dev':
+    PLUGINSDIR = join(dirname(__file__), '_narval')
+else:
+    from cubes.narval.__pkginfo__ import NARVAL_DIR
+    PLUGINSDIR = join(narvalbot.INSTALL_PREFIX, NARVAL_DIR)
+sys.path.append(PLUGINSDIR)
 
 from apycotlib.writer import CheckDataWriter, BaseDataWriter