Created
March 20, 2010 20:13
-
-
Save gabrielfalcao/338869 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Copyright (C) <2009> Gabriel Falcão <[email protected]> | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
import os | |
import sys | |
import nose | |
from fnmatch import fnmatch | |
from django.conf import settings | |
def get_local_imports_by_pattern(pattern): | |
imports = [] | |
for root, dirs, files in os.walk(os.curdir): | |
for d in dirs: | |
path = os.path.join(root, d) | |
if pattern in path: | |
imports.append(path.replace("/", ".").lstrip(".")) | |
return imports | |
def run_tests(test_labels, verbosity=2, interactive=True, extra_tests=[]): | |
# Pretend it's a production environment. | |
settings.DEBUG = False | |
nose_argv = [ | |
'nosetests', '-s', '--verbosity=2', '--exe', '--with-coverage' | |
] | |
# no logging, please | |
nose_argv.append('--nologcapture') | |
last_arg = sys.argv[-1] | |
if last_arg in ('functional', 'unit'): | |
nose_argv.extend(get_local_imports_by_pattern(last_arg)) | |
elif last_arg == 'all': | |
for appname in settings.INSTALLED_APPS: | |
for import_path in get_local_imports_by_pattern("*%s" % appname): | |
if all([x in import_path for x in ('unit', 'functional')]): | |
nose_argv.append(import_path) | |
elif last_arg != "test": | |
nose_argv.append(last_arg) | |
else: | |
print "Faltou um dos seguintes parâmetros: unit, funcional ou all" | |
print "Exemplo: python manage.py test unit" | |
raise SystemExit(2) | |
nose.run(argv=nose_argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment