~oubiwann/pymx/dev

« back to all changes in this revision

Viewing changes to test/util.py

  • Committer: duncan.mcgreggor
  • Date: 2008-03-20 20:18:32 UTC
  • Revision ID: svn-v3-trunk0:e789c851-bc48-0410-838f-eba945681aae:trunk:4
2008.03.20

* Added placeholder files and lib dir.
* Added admin script dir and basic scripts.
* Added test dir and harnesses.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Utility functions for testing.
 
3
"""
 
4
import os
 
5
from unittest import TestCase
 
6
from StringIO import StringIO
 
7
 
 
8
def importModule(name):
 
9
    mod = __import__(name)
 
10
    components = name.split('.')
 
11
    for comp in components[1:]:
 
12
        mod = getattr(mod, comp)
 
13
    return mod
 
14
 
 
15
def fileIsTest(path, skipFiles=[]):
 
16
    if not os.path.isfile(path):
 
17
        return False
 
18
    filename = os.path.basename(path)
 
19
    if filename in skipFiles:
 
20
        return False
 
21
    if filename.startswith('test') and filename.endswith('.py'):
 
22
        return True
 
23
 
 
24
def find(start, func, skip=[]):
 
25
    for item in [os.path.join(start, x) for x in os.listdir(start)]:
 
26
        if func(item, skip):
 
27
            yield item
 
28
        if os.path.isdir(item):
 
29
            for subItem in find(item, func, skip):
 
30
                yield subItem
 
31
 
 
32
def findTests(startDir, skipFiles=[]):
 
33
    return find(startDir, fileIsTest, skipFiles)
 
34