Skip to content

Commit

Permalink
Merge pull request #483 from michelts/fix-480-optparse
Browse files Browse the repository at this point in the history
Fix the verbosity option conflict in Django 1.8
  • Loading branch information
gabrielfalcao committed Jul 22, 2015
2 parents 19e6f8c + ce0157a commit 54b7d32
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 82 deletions.
17 changes: 13 additions & 4 deletions lettuce/__init__.py
Expand Up @@ -22,6 +22,7 @@
import os
import sys
import traceback
import warnings
try:
from imp import reload
except ImportError:
Expand Down Expand Up @@ -88,7 +89,8 @@ class Runner(object):
Takes a base path as parameter (string), so that it can look for
features and step definitions on there.
"""
def __init__(self, base_path, scenarios=None, verbosity=0, random=False,
def __init__(self, base_path, scenarios=None,
verbosity=0, no_color=False, random=False,
enable_xunit=False, xunit_filename=None,
enable_subunit=False, subunit_filename=None,
tags=None, failfast=False, auto_pdb=False,
Expand Down Expand Up @@ -121,10 +123,17 @@ def __init__(self, base_path, scenarios=None, verbosity=0, random=False,
from lettuce.plugins import dots as output
elif verbosity is 2:
from lettuce.plugins import scenario_names as output
elif verbosity is 3:
from lettuce.plugins import shell_output as output
else:
from lettuce.plugins import colored_shell_output as output
if verbosity is 4:
from lettuce.plugins import colored_shell_output as output
msg = ('Deprecated in lettuce 2.2.21. Use verbosity 3 without '
'--no-color flag instead of verbosity 4')
warnings.warn(msg, DeprecationWarning)
elif verbosity is 3:
if no_color:
from lettuce.plugins import shell_output as output
else:
from lettuce.plugins import colored_shell_output as output

self.random = random

Expand Down
8 changes: 7 additions & 1 deletion lettuce/bin.py
Expand Up @@ -30,9 +30,15 @@ def main(args=sys.argv[1:]):

parser.add_option("-v", "--verbosity",
dest="verbosity",
default=4,
default=3,
help='The verbosity level')

parser.add_option("--no-color",
action="store_true",
dest="no_color",
default=False,
help="Don't colorize the command output.")

parser.add_option("-s", "--scenarios",
dest="scenarios",
default=None,
Expand Down
39 changes: 31 additions & 8 deletions lettuce/django/management/commands/harvest.py
Expand Up @@ -16,6 +16,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import django
from distutils.version import StrictVersion
from optparse import make_option
from django.conf import settings
from django.core.management import call_command
Expand All @@ -36,11 +38,7 @@ class Command(BaseCommand):
args = '[PATH to feature file or folder]'
requires_model_validation = False

option_list = BaseCommand.option_list[1:] + (
make_option('-v', '--verbosity', action='store', dest='verbosity', default='4',
type='choice', choices=map(str, range(5)),
help='Verbosity level; 0=no output, 1=only dots, 2=only scenario names, 3=colorless output, 4=normal output (colorful)'),

option_list = BaseCommand.option_list + (
make_option('-a', '--apps', action='store', dest='apps', default='',
help='Run ONLY the django apps that are listed here. Comma separated'),

Expand All @@ -49,7 +47,7 @@ class Command(BaseCommand):

make_option('-S', '--no-server', action='store_true', dest='no_server', default=False,
help="will not run django's builtin HTTP server"),

make_option('--nothreading', action='store_false', dest='use_threading', default=True,
help='Tells Django to NOT use threading.'),

Expand Down Expand Up @@ -105,6 +103,29 @@ class Command(BaseCommand):

)

def create_parser(self, prog_name, subcommand):
parser = super(Command, self).create_parser(prog_name, subcommand)
parser.remove_option('-v')
help_text = ('Verbosity level; 0=no output, 1=only dots, 2=only '
'scenario names, 3=normal output, 4=normal output '
'(colorful, deprecated)')
parser.add_option('-v', '--verbosity',
action='store',
dest='verbosity',
default='3',
type='choice',
choices=map(str, range(5)),
help=help_text)
if StrictVersion(django.get_version()) < StrictVersion('1.7'):
# Django 1.7 introduces the --no-color flag. We must add the flag
# to be compatible with older django versions
parser.add_option('--no-color',
action='store_true',
dest='no_color',
default=False,
help="Don't colorize the command output.")
return parser

def stopserver(self, failed=False):
raise SystemExit(int(failed))

Expand All @@ -124,7 +145,8 @@ def get_paths(self, args, apps_to_run, apps_to_avoid):
def handle(self, *args, **options):
setup_test_environment()

verbosity = int(options.get('verbosity', 4))
verbosity = int(options.get('verbosity', 3))
no_color = int(options.get('no_color', False))
apps_to_run = tuple(options.get('apps', '').split(","))
apps_to_avoid = tuple(options.get('avoid_apps', '').split(","))
run_server = not options.get('no_server', False)
Expand Down Expand Up @@ -181,7 +203,8 @@ def handle(self, *args, **options):
if app_module is not None:
registry.call_hook('before_each', 'app', app_module)

runner = Runner(path, options.get('scenarios'), verbosity,
runner = Runner(path, options.get('scenarios'),
verbosity, no_color,
enable_xunit=options.get('enable_xunit'),
enable_subunit=options.get('enable_subunit'),
xunit_filename=options.get('xunit_file'),
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/language_specific_features/test_fr.py
Expand Up @@ -28,7 +28,7 @@
def test_output_with_success_colorless():
"Language: fr -> sucess colorless"

runner = Runner(join_path('fr', 'success', 'dumb.feature'), verbosity=3)
runner = Runner(join_path('fr', 'success', 'dumb.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand All @@ -49,7 +49,7 @@ def test_output_with_success_colorless():
def test_output_of_table_with_success_colorless():
"Language: fr -> sucess table colorless"

runner = Runner(join_path('fr', 'success', 'table.feature'), verbosity=3)
runner = Runner(join_path('fr', 'success', 'table.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand All @@ -75,7 +75,7 @@ def test_output_of_table_with_success_colorless():
def test_output_outlines_success_colorless():
"Language: fr -> sucess outlines colorless"

runner = Runner(join_path('fr', 'success', 'outlines.feature'), verbosity=3)
runner = Runner(join_path('fr', 'success', 'outlines.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_output_outlines_success_colorless():
def test_output_outlines_success_colorful():
"Language: fr -> sucess outlines colorful"

runner = Runner(join_path('fr', 'success', 'outlines.feature'), verbosity=4)
runner = Runner(join_path('fr', 'success', 'outlines.feature'), verbosity=3, no_color=False)
runner.run()

assert_stdout_lines(
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_output_outlines_success_colorful():
def test_output_outlines2_success_colorful():
"Language: fr -> sucess outlines colorful, alternate name"

runner = Runner(join_path('fr', 'success', 'outlines2.feature'), verbosity=4)
runner = Runner(join_path('fr', 'success', 'outlines2.feature'), verbosity=3, no_color=False)
runner.run()

assert_stdout_lines(
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/language_specific_features/test_ja.py
Expand Up @@ -28,7 +28,7 @@
def test_output_with_success_colorless():
"Language: ja -> sucess colorless"

runner = Runner(join_path('ja', 'success', 'dumb.feature'), verbosity=3)
runner = Runner(join_path('ja', 'success', 'dumb.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand All @@ -48,7 +48,7 @@ def test_output_with_success_colorless():
def test_output_of_table_with_success_colorless():
"Language: ja -> sucess table colorless"

runner = Runner(join_path('ja', 'success', 'table.feature'), verbosity=3)
runner = Runner(join_path('ja', 'success', 'table.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand All @@ -71,7 +71,7 @@ def test_output_of_table_with_success_colorless():
def test_output_outlines_success_colorless():
"Language: ja -> sucess outlines colorless"

runner = Runner(join_path('ja', 'success', 'outlines.feature'), verbosity=3)
runner = Runner(join_path('ja', 'success', 'outlines.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_output_outlines_success_colorless():
def test_output_outlines_success_colorful():
"Language: ja -> sucess outlines colorful"

runner = Runner(join_path('ja', 'success', 'outlines.feature'), verbosity=4)
runner = Runner(join_path('ja', 'success', 'outlines.feature'), verbosity=3, no_color=False)
runner.run()

assert_stdout_lines(
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/language_specific_features/test_ptbr.py
Expand Up @@ -28,7 +28,7 @@
def test_output_with_success_colorless():
"Language: pt-br -> sucess colorless"

runner = Runner(join_path('pt-br', 'success', 'dumb.feature'), verbosity=3)
runner = Runner(join_path('pt-br', 'success', 'dumb.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand All @@ -50,7 +50,7 @@ def test_output_with_success_colorless():
def test_output_of_table_with_success_colorless():
"Language: pt-br -> sucess table colorless"

runner = Runner(join_path('pt-br', 'success', 'table.feature'), verbosity=3)
runner = Runner(join_path('pt-br', 'success', 'table.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand All @@ -75,7 +75,7 @@ def test_output_of_table_with_success_colorless():
def test_output_outlines_success_colorless():
"Language: pt-br -> sucess outlines colorless"

runner = Runner(join_path('pt-br', 'success', 'outlines.feature'), verbosity=3)
runner = Runner(join_path('pt-br', 'success', 'outlines.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_output_outlines_success_colorless():
def test_output_outlines_success_colorful():
"Language: pt-br -> sucess outlines colorful"

runner = Runner(join_path('pt-br', 'success', 'outlines.feature'), verbosity=4)
runner = Runner(join_path('pt-br', 'success', 'outlines.feature'), verbosity=3, no_color=False)
runner.run()

assert_stdout_lines(
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/language_specific_features/test_ru.py
Expand Up @@ -28,7 +28,7 @@
def test_output_with_success_colorless():
"Language: ru -> sucess colorless"

runner = Runner(join_path('ru', 'success', 'dumb.feature'), verbosity=3)
runner = Runner(join_path('ru', 'success', 'dumb.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand All @@ -51,7 +51,7 @@ def test_output_with_success_colorless():
def test_output_of_table_with_success_colorless():
"Language: ru -> sucess table colorless"

runner = Runner(join_path('ru', 'success', 'table.feature'), verbosity=3)
runner = Runner(join_path('ru', 'success', 'table.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand All @@ -76,7 +76,7 @@ def test_output_of_table_with_success_colorless():
def test_output_outlines_success_colorless():
"Language: ru -> sucess outlines colorless"

runner = Runner(join_path('ru', 'success', 'outlines.feature'), verbosity=3)
runner = Runner(join_path('ru', 'success', 'outlines.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_output_outlines_success_colorless():
def test_output_outlines_success_colorful():
"Language: ru -> sucess outlines colorful"

runner = Runner(join_path('ru', 'success', 'outlines.feature'), verbosity=4)
runner = Runner(join_path('ru', 'success', 'outlines.feature'), verbosity=3, no_color=False)
runner.run()

assert_stdout_lines(
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/language_specific_features/test_zh-CN.py
Expand Up @@ -28,7 +28,7 @@
def test_output_with_success_colorless():
"Language: zh-CN -> sucess colorless"

runner = Runner(join_path('zh-CN', 'success', 'dumb.feature'), verbosity=3)
runner = Runner(join_path('zh-CN', 'success', 'dumb.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand All @@ -48,7 +48,7 @@ def test_output_with_success_colorless():
def test_output_of_table_with_success_colorless():
"Language: zh-CN -> sucess table colorless"

runner = Runner(join_path('zh-CN', 'success', 'table.feature'), verbosity=3)
runner = Runner(join_path('zh-CN', 'success', 'table.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand All @@ -71,7 +71,7 @@ def test_output_of_table_with_success_colorless():
def test_output_outlines_success_colorless():
"Language: zh-CN -> sucess outlines colorless"

runner = Runner(join_path('zh-CN', 'success', 'outlines.feature'), verbosity=3)
runner = Runner(join_path('zh-CN', 'success', 'outlines.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_output_outlines_success_colorless():
def test_output_outlines_success_colorful():
"Language: zh-CN -> sucess outlines colorful"

runner = Runner(join_path('zh-CN', 'success', 'outlines.feature'), verbosity=4)
runner = Runner(join_path('zh-CN', 'success', 'outlines.feature'), verbosity=3, no_color=False)
runner.run()

assert_stdout_lines(
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/language_specific_features/test_zh-TW.py
Expand Up @@ -28,7 +28,7 @@
def test_output_with_success_colorless():
"Language: zh-TW -> sucess colorless"

runner = Runner(join_path('zh-TW', 'success', 'dumb.feature'), verbosity=3)
runner = Runner(join_path('zh-TW', 'success', 'dumb.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand All @@ -48,7 +48,7 @@ def test_output_with_success_colorless():
def test_output_of_table_with_success_colorless():
"Language: zh-TW -> sucess table colorless"

runner = Runner(join_path('zh-TW', 'success', 'table.feature'), verbosity=3)
runner = Runner(join_path('zh-TW', 'success', 'table.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand All @@ -71,7 +71,7 @@ def test_output_of_table_with_success_colorless():
def test_output_outlines_success_colorless():
"Language: zh-TW -> sucess outlines colorless"

runner = Runner(join_path('zh-TW', 'success', 'outlines.feature'), verbosity=3)
runner = Runner(join_path('zh-TW', 'success', 'outlines.feature'), verbosity=3, no_color=True)
runner.run()

assert_stdout_lines(
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_output_outlines_success_colorless():
def test_output_outlines_success_colorful():
"Language: zh-TW -> sucess outlines colorful"

runner = Runner(join_path('zh-TW', 'success', 'outlines.feature'), verbosity=4)
runner = Runner(join_path('zh-TW', 'success', 'outlines.feature'), verbosity=3, no_color=False)
runner.run()

assert_stdout_lines(
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/test_behave_as_handling.py
Expand Up @@ -37,7 +37,7 @@ def path_to_feature(name):
@with_setup(prepare_stdout)
def test_simple_behave_as_feature():
"Basic step.behave_as behaviour is working"
Runner(path_to_feature('1st_normal_steps'), verbosity=3).run()
Runner(path_to_feature('1st_normal_steps'), verbosity=3, no_color=True).run()
assert_stdout_lines(
"\n"
"Feature: Multiplication # tests/functional/behave_as_features/1st_normal_steps/1st_normal_steps.feature:2\n"
Expand All @@ -62,7 +62,7 @@ def test_simple_behave_as_feature():
@with_setup(prepare_stdout)
def test_simple_tables_behave_as_feature():
"Basic step.behave_as behaviour is working"
Runner(path_to_feature('2nd_table_steps'), verbosity=3).run()
Runner(path_to_feature('2nd_table_steps'), verbosity=3, no_color=True).run()
assert_stdout_lines(
"\n"
"Feature: Multiplication # tests/functional/behave_as_features/2nd_table_steps/2nd_table_steps.feature:2\n"
Expand All @@ -88,7 +88,7 @@ def test_simple_tables_behave_as_feature():
@with_setup(prepare_stdout)
def test_failing_tables_behave_as_feature():
"Basic step.behave_as behaviour is working"
Runner(path_to_feature('3rd_failing_steps'), verbosity=3).run()
Runner(path_to_feature('3rd_failing_steps'), verbosity=3, no_color=True).run()
assert_stdout_lines_with_traceback(
'\n'
'Feature: Multiplication # tests/functional/behave_as_features/3rd_failing_steps/3rd_failing_steps.feature:2\n'
Expand Down

0 comments on commit 54b7d32

Please sign in to comment.