summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2013-07-29 17:06:55 +0200
committerniv-openerp <nicolas.vanhoren@openerp.com>2013-07-29 17:06:55 +0200
commite12b980f4622b3abc5fa93efe5ebc2633496dc5b (patch)
treefd243bd18b372bb89f6fd66af2580f83e19d69cd
parent34c97e980205c083f24ade2430f460b122a31c4d (diff)
parentf1b47a3e0e0ae93d7c6450214e639aa0fd8cf527 (diff)
[IMP] Added command in openerp command to launch tests with grunt.
bzr revid: nicolas.vanhoren@openerp.com-20130729150655-z25icrvpmd045thf
-rw-r--r--openerpcommand/__init__.py3
-rw-r--r--openerpcommand/grunt_tests.py50
2 files changed, 52 insertions, 1 deletions
diff --git a/openerpcommand/__init__.py b/openerpcommand/__init__.py
index 6d41c2842dc..9d5e81f0327 100644
--- a/openerpcommand/__init__.py
+++ b/openerpcommand/__init__.py
@@ -19,9 +19,10 @@ from . import scaffold
from . import uninstall
from . import update
from . import web
+from . import grunt_tests
command_list_server = (conf, cron, drop, initialize, model, module, read, run_tests,
- scaffold, uninstall, update, web, )
+ scaffold, uninstall, update, web, grunt_tests, )
command_list_client = (Call, Open, Show, ConsumeNothing, ConsumeMemory,
LeakMemory, ConsumeCPU, Bench, BenchRead,
diff --git a/openerpcommand/grunt_tests.py b/openerpcommand/grunt_tests.py
new file mode 100644
index 00000000000..db2513f2bc0
--- /dev/null
+++ b/openerpcommand/grunt_tests.py
@@ -0,0 +1,50 @@
+"""
+Search for Gruntfile.js files in all the addons and launch them using the 'grunt test' command.
+"""
+
+import common
+import fnmatch
+import os
+import re
+import sys
+import subprocess
+
+def grunt_tester(directories, log = sys.stdout):
+ result = 0
+
+ matches = []
+ for direc in directories:
+ for root, dirnames, filenames in os.walk(direc):
+ for filename in fnmatch.filter(filenames, 'Gruntfile.js'):
+ full = os.path.join(root, filename)
+ if re.match(r"(^.*?/node_modules/.*$)|(^.*?/lib/.*$)", full):
+ continue
+ matches.append(full)
+
+ for file_ in matches:
+ folder = os.path.dirname(file_)
+ p = subprocess.Popen(['npm', 'install'], cwd=folder)
+ if p.wait() != 0:
+ raise Exception("Failed to install dependencies for Gruntfile located in folder %s" % folder)
+
+ p = subprocess.Popen(['grunt', 'test', '--no-color'], cwd=folder, stdout=log, stderr=log)
+ if p.wait() != 0:
+ result = 1
+
+ return result
+
+def run(args):
+ if args.addons:
+ args.addons = args.addons.split(':')
+ else:
+ args.addons = []
+ result = grunt_tester(args.addons)
+ if result != 0:
+ sys.exit(result)
+
+def add_parser(subparsers):
+ parser = subparsers.add_parser('grunt-tests',
+ description='Run the tests contained in Gruntfile.js files.')
+ common.add_addons_argument(parser)
+
+ parser.set_defaults(run=run)