Parcourir la source

Forced to commit!

version-14
Anand Doshi il y a 14 ans
Parent
révision
17809f1905
1 fichiers modifiés avec 64 ajouts et 0 suppressions
  1. +64
    -0
      cgi-bin/webnotes/tests.py

+ 64
- 0
cgi-bin/webnotes/tests.py Voir le fichier

@@ -0,0 +1,64 @@
"""
Run tests from modules. Sets up database connection, modules path and session before running test

Usage: from shell, run

python tests.py [test modules]

Options:
test modules: list of modules separated by space
if no modules are specified, it will run all "tests.py" files from all modules
"""

import sys, os
import unittest

# webnotes path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

# modules path
import webnotes
import webnotes.defs

if webnotes.defs.__dict__.get('modules_path'):
sys.path.append(webnotes.defs.modules_path)

def get_tests():
"""
Returns list of test modules identified by "tests.py"
"""
ret = []
for walk_tuple in os.walk(webnotes.defs.modules_path):
if 'tests.py' in walk_tuple[2]:
dir_path = os.path.relpath(walk_tuple[0], webnotes.defs.modules_path)
if dir_path=='.':
ret.append('tests')
else:
ret.append(dir_path.replace('/', '.') + '.tests')
return ret

def setup():
"""
Sets up connection and session
"""
from webnotes.db import Database
webnotes.conn = Database()
webnotes.session = {'user':'Administrator'}

if __name__=='__main__':
setup()
if len(sys.argv) > 1:
tests_list = sys.argv[1:]
# for unittest.main
sys.argv = sys.argv[:1]
else:
tests_list = get_tests()
for tests in tests_list:
exec 'from %s import *' % str(tests)

unittest.main()

Chargement…
Annuler
Enregistrer