~justas.sadzevicius/schooltool/flourish_timetables

« back to all changes in this revision

Viewing changes to src/schooltool/testing/test.py

  • Committer: mg
  • Date: 2005-09-15 18:06:46 UTC
  • Revision ID: mg-20080508132157-83gi3e3essjkstj7
Moved the test safety net (checks.py) into a top-level 'testsupport' directory.
Taught the test runner to look for this new directory (somewhat hackily, I'm
afraid).

Show diffs side-by-side

added added

removed removed

Lines of Context:
223
223
def import_module(filename, cfg, tracer=None):
224
224
    """Import and return a module."""
225
225
    filename = os.path.splitext(filename)[0]
226
 
    assert filename.startswith(cfg.basedir)
227
 
    modname = filename[len(cfg.basedir):].replace(os.path.sep, '.')
 
226
    if filename.startswith(cfg.basedir):
 
227
        filename = filename[len(cfg.basedir):]
 
228
    modname = filename.replace(os.path.sep, '.')
228
229
    if modname.startswith('.'):
229
230
        modname = modname[1:]
230
231
    if tracer is not None:
357
358
 
358
359
def get_test_hooks(test_files, cfg, tracer=None):
359
360
    """Return a list of test hooks from a given list of test modules."""
360
 
    results = []
361
361
    dirs = Set(map(os.path.dirname, test_files))
362
362
    for dir in list(dirs):
363
363
        if os.path.basename(dir) == 'ftests':
364
364
            dirs.add(os.path.join(os.path.dirname(dir), 'tests'))
365
365
    dirs = list(dirs)
366
366
    dirs.sort()
 
367
    hook_modules = []
367
368
    for dir in dirs:
368
369
        filename = os.path.join(dir, 'checks.py')
369
370
        if os.path.exists(filename):
370
371
            module = import_module(filename, cfg, tracer=tracer)
371
 
            if tracer is not None:
372
 
                hooks = tracer.runfunc(module.test_hooks)
373
 
            else:
374
 
                hooks = module.test_hooks()
375
 
            results.extend(hooks)
 
372
            hook_modules.append(module)
 
373
    # Also look in a a directory 'testsupport' which is a sibling of
 
374
    # cfg.basedir
 
375
    dir = os.path.join(os.path.dirname(cfg.basedir), 'testsupport')
 
376
    filename = os.path.join(dir, 'checks.py')
 
377
    if os.path.exists(filename):
 
378
        sys.path.insert(0, dir)
 
379
        try:
 
380
            module = import_module('checks.py', cfg, tracer=tracer)
 
381
            hook_modules.append(module)
 
382
        finally:
 
383
            del sys.path[0]
 
384
    results = []
 
385
    for module in hook_modules:
 
386
        if tracer is not None:
 
387
            hooks = tracer.runfunc(module.test_hooks)
 
388
        else:
 
389
            hooks = module.test_hooks()
 
390
        results.extend(hooks)
376
391
    return results
377
392
 
378
393