mrunge pushed to python-django-nose (f22). "Make django-nose work with python-django-1.8"

notifications at fedoraproject.org notifications at fedoraproject.org
Tue Apr 14 11:37:02 UTC 2015


>From 08cb9e8c47a033091e3b9e63cc6e4c340714e90b Mon Sep 17 00:00:00 2001
From: Matthias Runge <mrunge at redhat.com>
Date: Tue, 14 Apr 2015 13:29:49 +0200
Subject: Make django-nose work with python-django-1.8


diff --git a/10568067acde9a5bcb83be609de6bdeb3c07ae01.patch b/10568067acde9a5bcb83be609de6bdeb3c07ae01.patch
new file mode 100644
index 0000000..1eb2365
--- /dev/null
+++ b/10568067acde9a5bcb83be609de6bdeb3c07ae01.patch
@@ -0,0 +1,59 @@
+From 10568067acde9a5bcb83be609de6bdeb3c07ae01 Mon Sep 17 00:00:00 2001
+From: st4lk <myhappydo at gmail.com>
+Date: Mon, 2 Mar 2015 14:04:24 +0300
+Subject: [PATCH] set runner by option
+
+---
+ django_nose/runner.py    | 6 +++++-
+ runtests.sh              | 1 +
+ testapp/custom_runner.py | 5 +++++
+ 3 files changed, 11 insertions(+), 1 deletion(-)
+ create mode 100644 testapp/custom_runner.py
+
+diff --git a/django_nose/runner.py b/django_nose/runner.py
+index bd3c767..b99d7fb 100644
+--- a/django_nose/runner.py
++++ b/django_nose/runner.py
+@@ -156,6 +156,10 @@ class BasicNoseRunner(DiscoverRunner):
+     # Replace the builtin command options with the merged django/nose options:
+     options = _get_options()
+ 
++    # Not add following options to nosetests
++    django_opts = ['--noinput', '--liveserver', '-p', '--pattern',
++        '--testrunner']
++
+     def run_suite(self, nose_argv):
+         result_plugin = ResultPlugin()
+         plugins_to_add = [DjangoSetUpPlugin(self),
+@@ -208,7 +212,7 @@ def run_tests(self, test_labels, extra_tests=None):
+             nose_argv.extend(settings.NOSE_ARGS)
+ 
+         # Skip over 'manage.py test' and any arguments handled by django.
+-        django_opts = ['--noinput', '--liveserver', '-p', '--pattern']
++        django_opts = self.django_opts[:]
+         for opt in BaseCommand.option_list:
+             django_opts.extend(opt._long_opts)
+             django_opts.extend(opt._short_opts)
+diff --git a/runtests.sh b/runtests.sh
+index 7a0c2ce..7066672 100755
+--- a/runtests.sh
++++ b/runtests.sh
+@@ -47,6 +47,7 @@ django_test 'django-admin.py test --settings=testapp.settings_old_style' '2' 'dj
+ django_test 'testapp/runtests.py testapp.test_only_this' '1' 'via run_tests API'
+ django_test 'django-admin.py test --settings=testapp.settings_with_plugins testapp/plugin_t' '1' 'with plugins'
+ django_test 'django-admin.py test --settings=testapp.settings unittests' '4' 'unittests'
++django_test 'django-admin.py test --settings=testapp.settings unittests  --testrunner=testapp.custom_runner.CustomNoseTestSuiteRunner' '4' 'unittests'
+ if ! [ $(version $PYTHONVERSION) \> $(version 3.0.0) ]
+ then
+ # Python 3 doesn't support the hotshot profiler. See nose#842.
+diff --git a/testapp/custom_runner.py b/testapp/custom_runner.py
+new file mode 100644
+index 0000000..b7e83ae
+--- /dev/null
++++ b/testapp/custom_runner.py
+@@ -0,0 +1,5 @@
++from django_nose import NoseTestSuiteRunner
++
++
++class CustomNoseTestSuiteRunner(NoseTestSuiteRunner):
++    pass
diff --git a/convert-nose-optparse-options.patch b/convert-nose-optparse-options.patch
new file mode 100644
index 0000000..786376d
--- /dev/null
+++ b/convert-nose-optparse-options.patch
@@ -0,0 +1,169 @@
+From 5c936915b3964e7f71c568219693e43f319b50ca Mon Sep 17 00:00:00 2001
+From: John Whitlock <John-Whitlock at ieee.org>
+Date: Wed, 8 Apr 2015 17:19:43 -0500
+Subject: [PATCH] Convert nose optparse options to argparse
+
+When django.core.management.base.BaseCommand includes 'use_argparse',
+then nose's optparse options are merged using argparse's
+parser.add_argument in BaseCommand's overriden add_arguments method.
+
+For Django 1.7 and earlier, the current .options method is used to set
+the options.
+
+Fixes #178.
+---
+ django_nose/runner.py | 134 +++++++++++++++++++++++++++++++++++++++++++++++---
+ 1 file changed, 126 insertions(+), 8 deletions(-)
+
+diff --git a/django_nose/runner.py b/django_nose/runner.py
+index b99d7fb..b30fdb3 100644
+--- a/django_nose/runner.py
++++ b/django_nose/runner.py
+@@ -143,7 +143,132 @@ def _get_options():
+                                        o.action != 'help')
+ 
+ 
+-class BasicNoseRunner(DiscoverRunner):
++if hasattr(BaseCommand, 'use_argparse'):
++    # Django 1.8 and later uses argparse.ArgumentParser
++    # Translate nose optparse arguments to argparse
++    class BaseRunner(DiscoverRunner):
++
++        # Don't pass the following options to nosetests
++        django_opts = [
++            '--noinput', '--liveserver', '-p', '--pattern', '--testrunner',
++            '--settings']
++
++        #
++        # For optparse -> argparse conversion
++        #
++        # Option strings to remove from Django options if found
++        _argparse_remove_options = (
++            '-p',  # Short arg for nose's --plugins, not Django's --patterns
++            '-d',  # Short arg for nose's --detailed-errors, not Django's
++                   #  --debug-sql
++        )
++
++        # Convert nose optparse options to argparse options
++        _argparse_type = {
++            'int': int,
++            'float': float,
++            'complex': complex,
++            'string': str,
++        }
++        # If optparse has a None argument, omit from call to add_argument
++        _argparse_omit_if_none = (
++            'action', 'nargs', 'const', 'default', 'type', 'choices',
++            'required', 'help', 'metavar', 'dest', 'callback', 'callback_args',
++            'callback_kwargs')
++
++        # Translating callbacks is not supported, because none of the built-in
++        # plugins uses one.  If you have a plugin that uses a callback, please
++        # open a ticket or submit a working implementation.
++        _argparse_fail_if_not_none = (
++            'callback', 'callback_args', 'callback_kwargs')
++
++        @classmethod
++        def add_arguments(cls, parser):
++            """Convert nose's optparse arguments to argparse"""
++            super(BaseRunner, cls).add_arguments(parser)
++
++            # Read optparse options for nose and plugins
++            cfg_files = nose.core.all_config_files()
++            manager = nose.core.DefaultPluginManager()
++            config = nose.core.Config(
++                env=os.environ, files=cfg_files, plugins=manager)
++            config.plugins.addPlugins(list(_get_plugins_from_settings()))
++            options = config.getParser()._get_all_options()
++
++            # Gather existing option strings`
++            django_options = set()
++            for action in parser._actions:
++                for override in cls._argparse_remove_options:
++                    if override in action.option_strings:
++                        # Emulate parser.conflict_handler='resolve'
++                        parser._handle_conflict_resolve(
++                            None, ((override, action),))
++                django_options.update(action.option_strings)
++
++            # Process nose optparse options
++            for option in options:
++                # Skip any options also in Django options
++                opt_long = option.get_opt_string()
++                if opt_long in django_options:
++                    continue
++                if option._short_opts:
++                    opt_short = option._short_opts[0]
++                    if opt_short in django_options:
++                        continue
++                else:
++                    opt_short = None
++
++                # Rename nose's --verbosity to --nose-verbosity
++                if opt_long == '--verbosity':
++                    opt_long = '--nose-verbosity'
++
++                # Convert optparse attributes to argparse attributes
++                option_attrs = {}
++                for attr in option.ATTRS:
++                    value = getattr(option, attr)
++
++                    # Rename options for nose's --verbosity
++                    if opt_long == '--nose-verbosity':
++                        if attr == 'dest':
++                            value = 'nose_verbosity'
++                        elif attr == 'metavar':
++                            value = 'NOSE_VERBOSITY'
++
++                    # Omit arguments that are None, use default
++                    if attr in cls._argparse_omit_if_none and value is None:
++                        continue
++
++                    # Translating callbacks is not supported
++                    if attr in cls._argparse_fail_if_not_none:
++                        assert value is None, (
++                            'argparse option %s=%s is not supported' %
++                            (attr, value))
++                        continue
++
++                    # Convert type from optparse string to argparse type
++                    if attr == 'type':
++                        value = cls._argparse_type[value]
++
++                    # Pass converted attribute to optparse option
++                    option_attrs[attr] = value
++
++                # Add the optparse argument
++                if opt_short:
++                    parser.add_argument(opt_short, opt_long, **option_attrs)
++                else:
++                    parser.add_argument(opt_long, **option_attrs)
++else:
++    # Django 1.7 and earlier use optparse
++    class BaseRunner(DiscoverRunner):
++        # Replace the builtin options with the merged django/nose options:
++        options = _get_options()
++
++        # Not add following options to nosetests
++        django_opts = ['--noinput', '--liveserver', '-p', '--pattern',
++            '--testrunner']
++
++
++class BasicNoseRunner(BaseRunner):
+     """Facade that implements a nose runner in the guise of a Django runner
+ 
+     You shouldn't have to use this directly unless the additions made by
+@@ -153,13 +278,6 @@ class BasicNoseRunner(DiscoverRunner):
+     """
+     __test__ = False
+ 
+-    # Replace the builtin command options with the merged django/nose options:
+-    options = _get_options()
+-
+-    # Not add following options to nosetests
+-    django_opts = ['--noinput', '--liveserver', '-p', '--pattern',
+-        '--testrunner']
+-
+     def run_suite(self, nose_argv):
+         result_plugin = ResultPlugin()
+         plugins_to_add = [DjangoSetUpPlugin(self),
diff --git a/python-django-nose.spec b/python-django-nose.spec
index f7a62d5..6c70d03 100644
--- a/python-django-nose.spec
+++ b/python-django-nose.spec
@@ -2,7 +2,7 @@
 
 Name:           python-django-nose
 Version:        1.3
-Release:        1%{?dist}
+Release:        2%{?dist}
 Summary:        Django test runner that uses nose
 
 License:        BSD
@@ -13,6 +13,12 @@ Source0:        http://pypi.python.org/packages/source/d/%{pkgname}/%{pkgname}-%
 # https://github.com/django-nose/django-nose/commit/08bc8e5efc0e89bbce4ca2a3bf5a5bcdb49ae43c
 Patch0:         python-django-nose-django18-compat.patch
 
+# upstream commit set runner by option
+# as dependency for patch2.
+Patch1:         10568067acde9a5bcb83be609de6bdeb3c07ae01.patch
+# Convert nose optparse options to argparse
+# https://github.com/jwhitlock/django-nose/commit/5c936915b3964e7f71c568219693e43f319b50ca
+Patch2:         convert-nose-optparse-options.patch
 BuildArch:      noarch
 BuildRequires:  python2-devel python-setuptools
 Requires:       python-nose
@@ -30,7 +36,8 @@ Django test runner that uses nose.
 rm -rf django_nose.egg-info
 
 %patch0 -p1
-
+%patch1 -p1
+%patch2 -p1
 
 %build
 %{__python} setup.py build
@@ -48,6 +55,9 @@ rm -rf django_nose.egg-info
 
 
 %changelog
+* Tue Apr 14 2015 Matthias Runge <mrunge at redhat.com> - 1.3-2
+- Convert nose optparse options to argparse
+
 * Fri Feb 27 2015 Matthias Runge <mrunge at redhat.com> - 1.3-1
 - update to 1.3
 - add patch for Django-1.8 compatibility
-- 
cgit v0.10.2


	http://pkgs.fedoraproject.org/cgit/python-django-nose.git/commit/?h=f22&id=08cb9e8c47a033091e3b9e63cc6e4c340714e90b


More information about the scm-commits mailing list