Skip to content

Commit

Permalink
clean up pep8 formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Balogh committed Aug 2, 2011
1 parent dbab259 commit 528e786
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
13 changes: 8 additions & 5 deletions django_nose/plugin.py
Expand Up @@ -6,6 +6,7 @@
from django.db.models import signals
from django.db.models.loading import get_apps, get_models, load_app


class ResultPlugin(object):
"""
Captures the TestResult object for later inspection.
Expand Down Expand Up @@ -47,7 +48,7 @@ def beforeImport(self, filename, module):
module = module.rsplit('.', 1)[0]
else:
filepath = filename

models_path = os.path.join(filepath, 'models.py')
if os.path.exists(models_path):
self.add_apps.add(module)
Expand Down Expand Up @@ -75,8 +76,8 @@ def prepareTestRunner(self, test):

self.runner.setup_test_environment()

# HACK: We need to kill post_syncdb receivers to stop them from sending when the databases
# arent fully ready.
# HACK: We need to kill post_syncdb receivers to stop them from sending
# when the databases arent fully ready.
post_syncdb_receivers = signals.post_syncdb.receivers
signals.post_syncdb.receivers = []
self.old_names = self.runner.setup_databases()
Expand All @@ -85,10 +86,12 @@ def prepareTestRunner(self, test):
for app in get_apps():
app_models = list(get_models(app, include_auto_created=True))
for db in connections:
all_models = [m for m in app_models if router.allow_syncdb(db, m)]
all_models = [m for m in app_models
if router.allow_syncdb(db, m)]
if not all_models:
continue
signals.post_syncdb.send(app=app, created_models=all_models, verbosity=self.runner.verbosity,
signals.post_syncdb.send(app=app, created_models=all_models,
verbosity=self.runner.verbosity,
db=db, sender=app, interactive=False)

sys.stdout = sys_stdout
Expand Down
26 changes: 15 additions & 11 deletions django_nose/runner.py
Expand Up @@ -65,7 +65,8 @@ def run_tests(self, test_labels, extra_tests=None):
Returns the number of tests that failed.
"""
nose_argv = ['nosetests', '--verbosity', str(self.verbosity)] + list(test_labels)
nose_argv = (['nosetests', '--verbosity', str(self.verbosity)]
+ list(test_labels))
if hasattr(settings, 'NOSE_ARGS'):
nose_argv.extend(settings.NOSE_ARGS)

Expand All @@ -75,9 +76,10 @@ def run_tests(self, test_labels, extra_tests=None):
django_opts.extend(opt._long_opts)
django_opts.extend(opt._short_opts)

nose_argv.extend(OPTION_TRANSLATION.get(opt, opt)
for opt in sys.argv[1:]
if opt.startswith('-') and not any(opt.startswith(d) for d in django_opts))
nose_argv.extend(
OPTION_TRANSLATION.get(opt, opt) for opt in sys.argv[1:]
if opt.startswith('-')
and not any(opt.startswith(d) for d in django_opts))

if self.verbosity >= 1:
print ' '.join(nose_argv)
Expand All @@ -98,26 +100,28 @@ def _get_options():
return tuple(o for o in options if o.dest not in django_opts and
o.action != 'help')


def _get_plugins_from_settings():
if hasattr(settings, 'NOSE_PLUGINS'):
for plg_path in settings.NOSE_PLUGINS:
try:
dot = plg_path.rindex('.')
except ValueError:
raise exceptions.ImproperlyConfigured(
'%s isn\'t a Nose plugin module' % plg_path)
msg = "%s isn't a Nose plugin module" % plg_path
raise exceptions.ImproperlyConfigured(msg)
p_mod, p_classname = plg_path[:dot], plg_path[dot+1:]
try:
mod = import_module(p_mod)
except ImportError, e:
raise exceptions.ImproperlyConfigured(
'Error importing Nose plugin module %s: "%s"' % (p_mod, e))
msg = ('Error importing Nose plugin module %s: "%s"' %
(p_mod, e))
raise exceptions.ImproperlyConfigured(msg)
try:
p_class = getattr(mod, p_classname)
except AttributeError:
raise exceptions.ImproperlyConfigured(
'Nose plugin module "%s" does not define a "%s" class' % (
p_mod, p_classname))
msg = ('Nose plugin module "%s" does not define a "%s" class' %
(p_mod, p_classname))
raise exceptions.ImproperlyConfigured(msg)
yield p_class()

# Replace the builtin command options with the merged django/nose options.
Expand Down

0 comments on commit 528e786

Please sign in to comment.