~openerp-dev/openobject-server/trunk-imp-onchange-behave-darshan

« back to all changes in this revision

Viewing changes to openerp/modules/module.py

  • Committer: Darshan Kalola(OpenERP)
  • Date: 2014-04-09 08:44:52 UTC
  • mfrom: (4936.1.232 openobject-server)
  • Revision ID: dka@tinyerp.com-20140409084452-w1e499j21i3eli9d
[MERGE]sync with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from openerp.tools.safe_eval import safe_eval as eval
39
39
 
40
40
_logger = logging.getLogger(__name__)
41
 
_test_logger = logging.getLogger('openerp.tests')
42
41
 
43
42
# addons path as a list
44
43
ad_paths = []
170
169
        return ('/' + module + '/') + '/'.join(iconpath)
171
170
    return '/base/'  + '/'.join(iconpath)
172
171
 
173
 
def load_information_from_description_file(module):
 
172
def load_information_from_description_file(module, mod_path=None):
174
173
    """
175
174
    :param module: The name of the module (sale, purchase, ...)
 
175
    :param mod_path: Physical path of module, if not providedThe name of the module (sale, purchase, ...)
176
176
    """
177
177
 
178
 
    terp_file = get_module_resource(module, '__openerp__.py')
179
 
    mod_path = get_module_path(module)
 
178
    if not mod_path:
 
179
        mod_path = get_module_path(module)
 
180
    terp_file = opj(mod_path, '__openerp__.py')
180
181
    if terp_file:
181
182
        info = {}
182
183
        if os.path.isfile(terp_file):
340
341
 
341
342
# Use a custom stream object to log the test executions.
342
343
class TestStream(object):
343
 
    def __init__(self):
 
344
    def __init__(self, logger_name='openerp.tests'):
 
345
        self.logger = logging.getLogger(logger_name)
344
346
        self.r = re.compile(r'^-*$|^ *... *$|^ok$')
345
347
    def flush(self):
346
348
        pass
352
354
            if not first:
353
355
                c = '` ' + c
354
356
            first = False
355
 
            _test_logger.info(c)
 
357
            self.logger.info(c)
356
358
 
357
359
current_test = None
358
360
 
359
 
def run_unit_tests(module_name, dbname):
 
361
def runs_at(test, hook, default):
 
362
    # by default, tests do not run post install
 
363
    test_runs = getattr(test, hook, default)
 
364
 
 
365
    # for a test suite, we're done
 
366
    if not isinstance(test, unittest.TestCase):
 
367
        return test_runs
 
368
 
 
369
    # otherwise check the current test method to see it's been set to a
 
370
    # different state
 
371
    method = getattr(test, test._testMethodName)
 
372
    return getattr(method, hook, test_runs)
 
373
 
 
374
runs_at_install = functools.partial(runs_at, hook='at_install', default=True)
 
375
runs_post_install = functools.partial(runs_at, hook='post_install', default=False)
 
376
 
 
377
def run_unit_tests(module_name, dbname, position=runs_at_install):
360
378
    """
361
379
    :returns: ``True`` if all of ``module_name``'s tests succeeded, ``False``
362
380
              if any of them failed.
368
386
    r = True
369
387
    for m in mods:
370
388
        tests = unwrap_suite(unittest2.TestLoader().loadTestsFromModule(m))
371
 
        suite = unittest2.TestSuite(itertools.ifilter(runs_at_install, tests))
372
 
        _logger.info('module %s: running test %s.', module_name, m.__name__)
 
389
        suite = unittest2.TestSuite(itertools.ifilter(position, tests))
 
390
        _logger.info('running %s tests.', m.__name__)
373
391
 
374
 
        result = unittest2.TextTestRunner(verbosity=2, stream=TestStream()).run(suite)
 
392
        result = unittest2.TextTestRunner(verbosity=2, stream=TestStream(m.__name__)).run(suite)
375
393
 
376
394
        if not result.wasSuccessful():
377
395
            r = False
380
398
    current_test = None
381
399
    return r
382
400
 
383
 
def runs_at(test, hook, default):
384
 
    # by default, tests do not run post install
385
 
    test_runs = getattr(test, hook, default)
386
 
 
387
 
    # for a test suite, we're done
388
 
    if not isinstance(test, unittest.TestCase):
389
 
        return test_runs
390
 
 
391
 
    # otherwise check the current test method to see it's been set to a
392
 
    # different state
393
 
    method = getattr(test, test._testMethodName)
394
 
    return getattr(method, hook, test_runs)
395
 
 
396
 
runs_at_install = functools.partial(runs_at, hook='at_install', default=True)
397
 
runs_post_install = functools.partial(runs_at, hook='post_install', default=False)
398
 
 
399
401
def unwrap_suite(test):
400
402
    """
401
403
    Attempts to unpack testsuites (holding suites or cases) in order to