Improve unittest to run test_suite inside setuptools
This commit is contained in:
1 parent
473f94dc2b
commit
9eedc60aa0
11 files changed
+41
-69
No files matched your search
@@ -62,4 +62,6 @@ setup(name=PACKAGE,
|
||||
'timezone': ['pytz'],
|
||||
},
|
||||
zip_safe=False,
|
||||
test_suite='trytond.tests',
|
||||
test_loader='trytond.test_loader:Loader',
|
||||
)
|
||||
@@ -11,7 +11,7 @@ import traceback
|
||||
import logging
|
||||
|
||||
OPJ = os.path.join
|
||||
MODULES_PATH = os.path.dirname(__file__)
|
||||
MODULES_PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
MODULES = []
|
||||
|
||||
@@ -134,7 +134,8 @@ def create_graph(module_list, force=None):
|
||||
tryton_file = OPJ(MODULES_PATH, module, '__tryton__.py')
|
||||
mod_path = OPJ(MODULES_PATH, module)
|
||||
if module in ('ir', 'workflow', 'res', 'webdav', 'test'):
|
||||
root_path = os.path.dirname(os.path.dirname(__file__))
|
||||
root_path = os.path.abspath(os.path.dirname(
|
||||
os.path.dirname(__file__)))
|
||||
tryton_file = OPJ(root_path, module, '__tryton__.py')
|
||||
mod_path = OPJ(root_path, module)
|
||||
elif module in EGG_MODULES:
|
||||
@@ -142,6 +143,11 @@ def create_graph(module_list, force=None):
|
||||
tryton_file = OPJ(ep.dist.location, 'trytond', 'modules', module,
|
||||
'__tryton__.py')
|
||||
mod_path = OPJ(ep.dist.location, 'trytond', 'modules', module)
|
||||
if not os.path.isfile(tryton_file) or not os.path.isdir(mod_path):
|
||||
# When testing modules from setuptools location is the module
|
||||
# directory
|
||||
tryton_file = OPJ(ep.dist.location, '__tryton__.py')
|
||||
mod_path = os.path.dirname(ep.dist.location)
|
||||
if os.path.isfile(tryton_file) or zipfile.is_zipfile(mod_path+'.zip'):
|
||||
try:
|
||||
info = tools.safe_eval(tools.file_open(tryton_file,
|
||||
@@ -375,6 +381,10 @@ def register_classes(reload_p=False):
|
||||
ep = EGG_MODULES[module]
|
||||
mod_path = os.path.join(ep.dist.location,
|
||||
*ep.module_name.split('.')[:-1])
|
||||
if not os.path.isdir(mod_path):
|
||||
# When testing modules from setuptools location is the module
|
||||
# directory
|
||||
mod_path = os.path.dirname(ep.dist.location)
|
||||
mod_file, pathname, description = imp.find_module(module,
|
||||
[mod_path])
|
||||
try:
|
||||
|
||||
+4
-3
@@ -4,9 +4,6 @@
|
||||
%prog [options]
|
||||
"""
|
||||
import logging
|
||||
FORMAT = '[%(asctime)s] %(levelname)s:%(name)s:%(message)s'
|
||||
DATEFMT = '%a %b %d %H:%M:%S %Y'
|
||||
logging.basicConfig(level=logging.DEBUG, format=FORMAT, datefmt=DATEFMT)
|
||||
import logging.handlers
|
||||
import sys, os, signal
|
||||
import time
|
||||
@@ -25,6 +22,10 @@ import random
|
||||
class TrytonServer(object):
|
||||
|
||||
def __init__(self):
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
format='[%(asctime)s] %(levelname)s:%(name)s:%(message)s',
|
||||
datefmt='%a %b %d %H:%M:%S %Y')
|
||||
|
||||
CONFIG.parse()
|
||||
|
||||
if CONFIG['logfile']:
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
|
||||
from unittest import TestLoader
|
||||
|
||||
|
||||
class Loader(TestLoader):
|
||||
|
||||
def loadTestsFromModule(self, module):
|
||||
return module.suite()
|
||||
@@ -1,2 +1,4 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
|
||||
from test_tryton import all_suite as suite
|
||||
@@ -3,9 +3,6 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
|
||||
import logging
|
||||
logging.basicConfig(level=logging.FATAL)
|
||||
|
||||
import unittest
|
||||
import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
|
||||
import logging
|
||||
logging.basicConfig(level=logging.FATAL)
|
||||
|
||||
import unittest
|
||||
from trytond.tests.test_tryton import POOL, DB, USER, CONTEXT, install_module
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
|
||||
import logging
|
||||
logging.basicConfig(level=logging.FATAL)
|
||||
|
||||
import unittest
|
||||
from trytond.tests.test_tryton import POOL, DB, USER, CONTEXT, install_module
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
|
||||
import logging
|
||||
logging.basicConfig(level=logging.FATAL)
|
||||
|
||||
import unittest
|
||||
from trytond.tests.test_tryton import POOL, DB, USER, CONTEXT, install_module
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
|
||||
import logging
|
||||
logging.basicConfig(level=logging.FATAL)
|
||||
|
||||
import sys, os
|
||||
DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
|
||||
'..', '..', '..', 'trytond')))
|
||||
@@ -49,19 +46,6 @@ Pool.test = True
|
||||
POOL = Pool(DB_NAME)
|
||||
|
||||
|
||||
class DBTestCase(unittest.TestCase):
|
||||
'''
|
||||
Test DB service.
|
||||
'''
|
||||
|
||||
def test0010create(self):
|
||||
'''
|
||||
Create database.
|
||||
'''
|
||||
self.assert_(create(DB_NAME, USER_PASSWORD, 'en_US',
|
||||
CONFIG['admin_passwd']))
|
||||
|
||||
|
||||
class ModelViewTestCase(unittest.TestCase):
|
||||
'''
|
||||
Test ModelView
|
||||
@@ -104,7 +88,7 @@ def install_module(name):
|
||||
database = Database().connect()
|
||||
cursor = database.cursor()
|
||||
if DB_NAME not in database.list(cursor):
|
||||
create(DB_NAME, 'admin', 'en_US', CONFIG['admin_passwd'])
|
||||
create(DB_NAME, USER_PASSWORD, 'en_US', CONFIG['admin_passwd'])
|
||||
cursor.close()
|
||||
cursor = DB.cursor()
|
||||
module_obj = POOL.get('ir.module.module')
|
||||
@@ -162,10 +146,7 @@ def suite():
|
||||
'''
|
||||
Return test suite for other modules
|
||||
'''
|
||||
# import module from root directory to be the same as in modules
|
||||
import trytond.tests.test_tryton
|
||||
return unittest.TestLoader().loadTestsFromTestCase(
|
||||
trytond.tests.test_tryton.DBTestCase)
|
||||
return unittest.TestSuite()
|
||||
|
||||
def all_suite():
|
||||
'''
|
||||
@@ -206,39 +187,12 @@ def modules_suite():
|
||||
test_mod = zimp.load_module(test_module)
|
||||
except zipimport.ZipImportError:
|
||||
continue
|
||||
elif os.path.isdir(os.path.join(MODULES_PATH, module)):
|
||||
elif os.path.isdir(os.path.join(MODULES_PATH, module)) or \
|
||||
module in EGG_MODULES:
|
||||
try:
|
||||
mod_file, pathname, description = imp.find_module(
|
||||
'tests', [os.path.join(MODULES_PATH, module)])
|
||||
test_mod = __import__(test_module, fromlist=[''])
|
||||
except ImportError:
|
||||
continue
|
||||
try:
|
||||
try:
|
||||
test_mod = imp.load_module(test_module, mod_file, pathname,
|
||||
description)
|
||||
except ImportError:
|
||||
continue
|
||||
finally:
|
||||
if mod_file is not None:
|
||||
mod_file.close()
|
||||
elif module in EGG_MODULES:
|
||||
egg_p = EGG_MODULES[module]
|
||||
mod_path = os.path.join(egg_p.dist.location,
|
||||
*egg_p.module_name.split('.')[:-1])
|
||||
try:
|
||||
mod_file, pathname, description = imp.find_module(
|
||||
'tests', [os.path.join(mod_path, module)])
|
||||
except ImportError:
|
||||
continue
|
||||
try:
|
||||
try:
|
||||
test_mod = imp.load_module(test_module, mod_file, pathname,
|
||||
description)
|
||||
except ImportError:
|
||||
continue
|
||||
finally:
|
||||
if mod_file is not None:
|
||||
mod_file.close()
|
||||
else:
|
||||
continue
|
||||
for test in test_mod.suite():
|
||||
|
||||
@@ -78,7 +78,7 @@ def exec_command_pipe(name, *args):
|
||||
def file_open(name, mode="r", subdir='modules'):
|
||||
"""Open a file from the root dir, using a subdir folder."""
|
||||
from trytond.modules import EGG_MODULES
|
||||
root_path = os.path.dirname(os.path.dirname(__file__))
|
||||
root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
name3 = False
|
||||
if subdir == 'modules':
|
||||
@@ -88,6 +88,11 @@ def file_open(name, mode="r", subdir='modules'):
|
||||
mod_path = os.path.join(epoint.dist.location,
|
||||
*epoint.module_name.split('.')[:-1])
|
||||
name3 = os.path.join(mod_path, name)
|
||||
if not os.path.isfile(name3):
|
||||
# When testing modules from setuptools location is the module
|
||||
# directory
|
||||
name3 = os.path.join(os.path.dirname(epoint.dist.location),
|
||||
name)
|
||||
|
||||
if subdir:
|
||||
if subdir == 'modules'\
|
||||
|
||||
Reference in new issue
Block a user