| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
"""Utilitaires et tests à effectuer avant de publier une nouvelle version de WxGéométrie. |
| 23 |
|
| 24 |
La suite de tests suivante est librement inspirée de Sympy. |
| 25 |
|
| 26 |
python test.py audit -> will run pyflakes checker on source code |
| 27 |
python test.py bench -> will run the complete benchmark suite |
| 28 |
python test.py clean -> will clean all trash (*.pyc and stuff) |
| 29 |
python test.py test -> will run the complete test suite |
| 30 |
""" |
| 31 |
|
| 32 |
import sys, os |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
_module_path = os.path.split(os.path.realpath(sys._getframe().f_code.co_filename))[0] |
| 37 |
ROOTDIR = os.path.abspath(_module_path + '/..') |
| 38 |
WXGEODIR = ROOTDIR + '/wxgeometrie' |
| 39 |
SKIP_DIRS = ['sympy/', 'sympy_OLD/', 'sympy_old/', 'pylib/decorator.py', |
| 40 |
'modules/OLD', 'BAZAR/'] |
| 41 |
|
| 42 |
sys.path.insert(0, WXGEODIR) |
| 43 |
sys.path.insert(0, ROOTDIR) |
| 44 |
|
| 45 |
print(ROOTDIR) |
| 46 |
|
| 47 |
try: |
| 48 |
import sip |
| 49 |
|
| 50 |
sip.setapi('QDate', 2) |
| 51 |
sip.setapi('QDateTime', 2) |
| 52 |
sip.setapi('QString', 2) |
| 53 |
sip.setapi('QTextStream', 2) |
| 54 |
sip.setapi('QTime', 2) |
| 55 |
sip.setapi('QUrl', 2) |
| 56 |
sip.setapi('QVariant', 2) |
| 57 |
except ValueError: |
| 58 |
print("Warning: SIP API has already been set.") |
| 59 |
|
| 60 |
from wxgeometrie import param |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
if sys.version_info[:2] < param.python_version_min: |
| 65 |
print("Python %d.%d or newer is required. Python %d.%d detected." % \ |
| 66 |
(param.python_min + sys.version_info[:2])) |
| 67 |
sys.exit(-1) |
| 68 |
|
| 69 |
|
| 70 |
e. |
| 71 |
|
| 72 |
actions = {'u': 'audit', 'c': 'clean', 't': 'test', 'd': 'doc', 'a': 'all', 'h': 'help'} |
| 73 |
|
| 74 |
args = sys.argv[1:] |
| 75 |
|
| 76 |
|
| 77 |
def audit(): |
| 78 |
"""Audit WxGeometrie's source with PyFlakes. |
| 79 |
|
| 80 |
Audit WxGeometrie source code for following issues: |
| 81 |
- Names which are used but not defined or used before they are defined. |
| 82 |
- Names which are redefined without having been used. |
| 83 |
""" |
| 84 |
os.chdir(WXGEODIR) |
| 85 |
try: |
| 86 |
import pyflakes.scripts.pyflakes as flakes |
| 87 |
except ImportError: |
| 88 |
print("""In order to run the audit, you need to have PyFlakes installed.""") |
| 89 |
sys.exit(-1) |
| 90 |
print('\n == Auditing files... ==') |
| 91 |
warns = 0 |
| 92 |
for dirpath, dirnames, filenames in os.walk('.'): |
| 93 |
if not any((dirpath.startswith('./' + dir) or dir + '/' == dirpath) for dir in SKIP_DIRS): |
| 94 |
print('\nAuditing ' + dirpath + '...') |
| 95 |
print([('./' + dir, dirpath.startswith('./' + dir)) for dir in SKIP_DIRS]) |
| 96 |
for filename in filenames: |
| 97 |
if filename.endswith('.py') and filename != '__init__.py': |
| 98 |
warns += flakes.checkPath(os.path.join(dirpath, filename)) |
| 99 |
if warns > 0: |
| 100 |
print("Audit finished with total %d warnings" % warns) |
| 101 |
else: |
| 102 |
print("Audit finished without any warning. :)") |
| 103 |
|
| 104 |
|
| 105 |
def clean(): |
| 106 |
"""Cleans *.pyc and debian trashs.""" |
| 107 |
os.chdir(ROOTDIR) |
| 108 |
os.system("py.cleanup --remove=.py~,.bak,.pyc,.txt~") |
| 109 |
|
| 110 |
|
| 111 |
def test(*args): |
| 112 |
"Run all unit tests." |
| 113 |
os.chdir(ROOTDIR) |
| 114 |
param.debug = False |
| 115 |
param.verbose = False |
| 116 |
from runtests import test |
| 117 |
test(*args, blacklist = SKIP_DIRS) |
| 118 |
|
| 119 |
|
| 120 |
def doctest(*args): |
| 121 |
"Run all doctests." |
| 122 |
os.chdir(WXGEODIR) |
| 123 |
|
| 124 |
param.debug = False |
| 125 |
param.verbose = False |
| 126 |
sys.argv = [sys.argv[0], '--defaut'] |
| 127 |
from runtests import doctest |
| 128 |
doctest(*args, blacklist = SKIP_DIRS) |
| 129 |
|
| 130 |
doc = doctest |
| 131 |
|
| 132 |
def all(*args): |
| 133 |
"Run all tests and doctests." |
| 134 |
test(*args) |
| 135 |
doctest(*args) |
| 136 |
|
| 137 |
|
| 138 |
def help(): |
| 139 |
print("""\n === Usage ===\n |
| 140 |
- Launch all unit tests: |
| 141 |
$ ./tools/test.py |
| 142 |
- Launch all doctests: |
| 143 |
$ ./tools/test.py --doc |
| 144 |
- Launch all unit tests and doctests: |
| 145 |
$ ./tools/test.py --all |
| 146 |
- Clear working wxgeometrie directories: |
| 147 |
$ ./tools/test.py --clear |
| 148 |
- Audit code using PyFlakes: |
| 149 |
$ ./tools/test.py --audit |
| 150 |
|
| 151 |
Note that you may test only a few modules. |
| 152 |
For example: |
| 153 |
- Launch all unit tests concerning geolib: |
| 154 |
$ ./tools/test.py geolib |
| 155 |
- Launch all unit tests contained in geolib/test_objets.py |
| 156 |
$ ./tools/test.py objets |
| 157 |
""") |
| 158 |
sys.exit() |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
if args: |
| 164 |
if args[0].startswith('--'): |
| 165 |
action = args[0][2:] |
| 166 |
args = args[1:] |
| 167 |
elif args[0].startswith('-'): |
| 168 |
act = args[0][1:] |
| 169 |
args = args[1:] |
| 170 |
if act in actions: |
| 171 |
action = actions[act] |
| 172 |
else: |
| 173 |
help() |
| 174 |
else: |
| 175 |
action = 'test' |
| 176 |
if action in actions.values(): |
| 177 |
locals()[action](*args) |
| 178 |
else: |
| 179 |
help() |
| 180 |
else: |
| 181 |
test() |