示例#1
0
def main():
    config = Configuration()

    if config.version:
        print "behave " + __version__
        sys.exit(0)

    if config.tags_help:
        print TAG_HELP
        sys.exit(0)

    if config.lang_list:
        iso_codes = languages.keys()
        iso_codes.sort()
        print "Languages available:"
        for iso_code in iso_codes:
            native = languages[iso_code]['native'][0]
            name = languages[iso_code]['name'][0]
            print u'%s: %s / %s' % (iso_code, native, name)
        sys.exit(0)

    if config.lang_help:
        if config.lang_help not in languages:
            sys.exit('%s is not a recognised language: try --lang-list' %
                     config.lang_help)
        trans = languages[config.lang_help]
        print u"Translations for %s / %s" % (trans['name'][0],
              trans['native'][0])
        for kw in trans:
            if kw in 'name native'.split():
                continue
            print u'%16s: %s' % (kw.title().replace('_', ' '),
                  u', '.join(w for w in trans[kw] if w != '*'))
        sys.exit(0)

    if not config.format:
        default_format = config.defaults["default_format"]
        config.format = [ default_format ]
    elif config.format and "format" in config.defaults:
        # -- CASE: Formatter are specified in behave configuration file.
        #    Check if formatter are provided on command-line, too.
        if len(config.format) == len(config.defaults["format"]):
            # -- NO FORMATTER on command-line: Add default formatter.
            default_format = config.defaults["default_format"]
            config.format.append(default_format)
    if 'help' in config.format:
        print "Available formatters:"
        formatters.list_formatters(sys.stdout)
        sys.exit(0)

    if len(config.outputs) > len(config.format):
        print 'CONFIG-ERROR: More outfiles (%d) than formatters (%d).' % \
              (len(config.outputs), len(config.format))
        sys.exit(1)

    runner = Runner(config)
    try:
        failed = runner.run()
    except ParserError, e:
        sys.exit("ParseError: %s" % e)
示例#2
0
文件: main.py 项目: hangtwenty/behave
def main():
    # pylint: disable=R0912,R0915
    #   R0912   Too many branches (17/12)
    #   R0915   Too many statements (57/50)
    config = Configuration()

    if config.version:
        print "behave " + __version__
        sys.exit(0)

    if config.tags_help:
        print TAG_HELP
        sys.exit(0)

    if config.lang_list:
        iso_codes = languages.keys()
        iso_codes.sort()
        print "Languages available:"
        for iso_code in iso_codes:
            native = languages[iso_code]["native"][0]
            name = languages[iso_code]["name"][0]
            print u"%s: %s / %s" % (iso_code, native, name)
        sys.exit(0)

    if config.lang_help:
        if config.lang_help not in languages:
            sys.exit("%s is not a recognised language: try --lang-list" % config.lang_help)
        trans = languages[config.lang_help]
        print u"Translations for %s / %s" % (trans["name"][0], trans["native"][0])
        for kw in trans:
            if kw in "name native".split():
                continue
            print u"%16s: %s" % (kw.title().replace("_", " "), u", ".join(w for w in trans[kw] if w != "*"))
        sys.exit(0)

    if not config.format:
        format0 = config.defaults["format0"]
        config.format = [format0]
    elif "help" in config.format:
        print "Available formatters:"
        formatters.list_formatters(sys.stdout)
        sys.exit(0)
    # -- SANITY: Use at most one formatter, more cause various problems.
    # PROBLEM DESCRIPTION:
    #   1. APPEND MODE: configfile.format + --format
    #   2. Daisy chaining of formatters does not work
    #     => behave.formatter.formatters.get_formatter()
    #     => Stream methods, stream.write(), stream.flush are missing
    #        in Formatter interface
    config.format = config.format[-1:]

    stream = config.output
    runner = Runner(config)
    try:
        failed = runner.run()
    except ParserError, e:
        sys.exit(str(e))
示例#3
0
文件: __main__.py 项目: jgr21/behave
def main():
    config = Configuration()

    if config.version:
        print "behave " + __version__
        sys.exit(0)

    if config.tags_help:
        print TAG_HELP
        sys.exit(0)

    if config.lang_list:
        iso_codes = languages.keys()
        iso_codes.sort()
        print "Languages available:"
        for iso_code in iso_codes:
            native = languages[iso_code]['native'][0]
            name = languages[iso_code]['name'][0]
            print u'%s: %s / %s' % (iso_code, native, name)
        sys.exit(0)

    if config.lang_help:
        if config.lang_help not in languages:
            sys.exit('%s is not a recognised language: try --lang-list' %
                     config.lang_help)
        trans = languages[config.lang_help]
        print u"Translations for %s / %s" % (trans['name'][0],
              trans['native'][0])
        for kw in trans:
            if kw in 'name native'.split():
                continue
            print u'%16s: %s' % (kw.title().replace('_', ' '),
                  u', '.join(w for w in trans[kw] if w != '*'))
        sys.exit(0)

    if not config.format:
        format0 = config.defaults["format0"]
        config.format = [ format0 ]
    elif 'help' in config.format:
        print "Available formatters:"
        formatters.list_formatters(sys.stdout)
        sys.exit(0)
    # -- SANITY: Use at most one formatter, more cause various problems.
    # PROBLEM DESCRIPTION:
    #   1. APPEND MODE: configfile.format + --format
    #   2. Daisy chaining of formatter does not work
    #     => behave.formatter.formatters.get_formatter()
    #     => Stream methods, stream.write(), stream.flush are missing
    #        in Formatter interface
    if DISABLE_MULTI_FORMATTERS:
        config.format = config.format[-1:]

    runner = Runner(config)
    try:
        failed = runner.run()
    except ParserError, e:
        sys.exit(str(e))
示例#4
0
文件: __main__.py 项目: vhumpa/behave
def main():
    config = Configuration()

    if config.version:
        print "behave " + __version__
        sys.exit(0)

    if config.tags_help:
        print TAG_HELP
        sys.exit(0)

    if config.lang_list:
        iso_codes = languages.keys()
        iso_codes.sort()
        print "Languages available:"
        for iso_code in iso_codes:
            native = languages[iso_code]["native"][0]
            name = languages[iso_code]["name"][0]
            print u"%s: %s / %s" % (iso_code, native, name)
        sys.exit(0)

    if config.lang_help:
        if config.lang_help not in languages:
            sys.exit("%s is not a recognised language: try --lang-list" % config.lang_help)
        trans = languages[config.lang_help]
        print u"Translations for %s / %s" % (trans["name"][0], trans["native"][0])
        for kw in trans:
            if kw in "name native".split():
                continue
            print u"%16s: %s" % (kw.title().replace("_", " "), u", ".join(w for w in trans[kw] if w != "*"))
        sys.exit(0)

    if not config.format:
        default_format = config.defaults["default_format"]
        config.format = [default_format]
    elif config.format and "format" in config.defaults:
        # -- CASE: Formatter are specified in behave configuration file.
        #    Check if formatter are provided on command-line, too.
        if len(config.format) == len(config.defaults["format"]):
            # -- NO FORMATTER on command-line: Add default formatter.
            default_format = config.defaults["default_format"]
            config.format.append(default_format)
    if "help" in config.format:
        print "Available formatters:"
        formatters.list_formatters(sys.stdout)
        sys.exit(0)

    if len(config.outputs) > len(config.format):
        print "CONFIG-ERROR: More outfiles (%d) than formatters (%d)." % (len(config.outputs), len(config.format))
        sys.exit(1)

    runner = Runner(config)
    try:
        failed = runner.run()
    except ParserError, e:
        sys.exit("ParseError: %s" % e)
示例#5
0
文件: __main__.py 项目: eykd/behave
def main():
    config = Configuration()

    if config.version:
        print "behave " + __version__
        sys.exit(0)

    if config.tags_help:
        print TAG_HELP
        sys.exit(0)

    if config.lang_list:
        iso_codes = languages.keys()
        iso_codes.sort()
        print "Languages available:"
        for iso_code in iso_codes:
            native = languages[iso_code]['native'][0]
            name = languages[iso_code]['name'][0]
            print u'%s: %s / %s' % (iso_code, native, name)
        sys.exit(0)

    if config.lang_help:
        if config.lang_help not in languages:
            sys.exit('%s is not a recognised language: try --lang-list' %
                config.lang_help)
        trans = languages[config.lang_help]
        print u"Translations for %s / %s" % (trans['name'][0],
            trans['native'][0])
        for kw in trans:
            if kw in 'name native'.split():
                continue
            print u'%16s: %s' % (kw.title().replace('_', ' '),
                u', '.join(w for w in trans[kw] if w != '*'))
        sys.exit(0)

    if not config.format:
        config.format = ['pretty']
    elif 'help' in config.format:
        print "Available formatters:"
        formatters.list_formatters(sys.stdout)
        sys.exit(0)

    stream = config.output

    runner = Runner(config)
    try:
        failed = runner.run()
    except ParserError, e:
        sys.exit(str(e))
示例#6
0
def main():
    config = Configuration()

    if config.version:
        print "behave " + __version__
        sys.exit(0)

    if config.tags_help:
        print TAG_HELP
        sys.exit(0)

    if config.lang_list:
        iso_codes = languages.keys()
        iso_codes.sort()
        print "Languages available:"
        for iso_code in iso_codes:
            native = languages[iso_code]['native'][0]
            name = languages[iso_code]['name'][0]
            print u'%s: %s / %s' % (iso_code, native, name)
        sys.exit(0)

    if config.lang_help:
        if config.lang_help not in languages:
            sys.exit('%s is not a recognised language: try --lang-list' %
                config.lang_help)
        trans = languages[config.lang_help]
        print u"Translations for %s / %s" % (trans['name'][0],
            trans['native'][0])
        for kw in trans:
            if kw in 'name native'.split():
                continue
            print u'%16s: %s' % (kw.title().replace('_', ' '),
                u', '.join(w for w in trans[kw] if w != '*'))
        sys.exit(0)

    if not config.format:
        config.format = ['pretty']
    elif 'help' in config.format:
        print "Available formatters:"
        formatters.list_formatters(sys.stdout)
        sys.exit(0)

    stream = config.output

    runner = Runner(config)
    try:
        failed = runner.run()
    except ParserError, e:
        sys.exit(str(e))
示例#7
0
文件: main.py 项目: biznixcn/behave
def main():
    # pylint: disable=R0912,R0915
    #   R0912   Too many branches (17/12)
    #   R0915   Too many statements (57/50)
    config = Configuration()

    if config.version:
        print "behave " + __version__
        sys.exit(0)

    if config.tags_help:
        print TAG_HELP
        sys.exit(0)

    if config.lang_list:
        iso_codes = languages.keys()
        iso_codes.sort()
        print "Languages available:"
        for iso_code in iso_codes:
            native = languages[iso_code]['native'][0]
            name = languages[iso_code]['name'][0]
            print u'%s: %s / %s' % (iso_code, native, name)
        sys.exit(0)

    if config.lang_help:
        if config.lang_help not in languages:
            sys.exit('%s is not a recognised language: try --lang-list' %
                     config.lang_help)
        trans = languages[config.lang_help]
        print u"Translations for %s / %s" % (trans['name'][0],
              trans['native'][0])
        for kw in trans:
            if kw in 'name native'.split():
                continue
            print u'%16s: %s' % (kw.title().replace('_', ' '),
                  u', '.join(w for w in trans[kw] if w != '*'))
        sys.exit(0)

    if not config.format:
        default_format = config.defaults["default_format"]
        config.format = [ default_format ]
    elif config.format and "format" in config.defaults:
        # -- CASE: Formatter are specified in behave configuration file.
        #    Check if formatter are provided on command-line, too.
        if len(config.format) == len(config.defaults["format"]):
            # -- NO FORMATTER on command-line: Add default formatter.
            default_format = config.defaults["default_format"]
            config.format.append(default_format)
    elif 'help' in config.format:
        print "Available formatters:"
        formatters.list_formatters(sys.stdout)
        sys.exit(0)

    if len(config.outputs) > len(config.format):
        print 'CONFIG-ERROR: More outfiles (%d) than formatters (%d).' % \
              (len(config.outputs), len(config.format))
        sys.exit(1)

    runner = Runner(config)
    try:
        failed = runner.run()
    except ParserError, e:
        sys.exit(str(e))
示例#8
0
def main(args=None):
    config = Configuration(args)
    if config.version:
        print "behave " + __version__
        return 0

    if config.tags_help:
        print TAG_HELP
        return 0

    if config.lang_list:
        from behave.i18n import languages
        iso_codes = languages.keys()
        iso_codes.sort()
        print "Languages available:"
        for iso_code in iso_codes:
            native = languages[iso_code]['native'][0]
            name = languages[iso_code]['name'][0]
            print u'%s: %s / %s' % (iso_code, native, name)
        return 0

    if config.lang_help:
        from behave.i18n import languages
        if config.lang_help not in languages:
            print '%s is not a recognised language: try --lang-list' % \
                    config.lang_help
            return 1
        trans = languages[config.lang_help]
        print u"Translations for %s / %s" % (trans['name'][0],
              trans['native'][0])
        for kw in trans:
            if kw in 'name native'.split():
                continue
            print u'%16s: %s' % (kw.title().replace('_', ' '),
                  u', '.join(w for w in trans[kw] if w != '*'))
        return 0

    if not config.format:
        default_format = config.defaults["default_format"]
        config.format = [ default_format ]
    elif config.format and "format" in config.defaults:
        # -- CASE: Formatter are specified in behave configuration file.
        #    Check if formatter are provided on command-line, too.
        if len(config.format) == len(config.defaults["format"]):
            # -- NO FORMATTER on command-line: Add default formatter.
            default_format = config.defaults["default_format"]
            config.format.append(default_format)
    if 'help' in config.format:
        from behave.formatter import formatters
        print "Available formatters:"
        formatters.list_formatters(sys.stdout)
        return 0

    if len(config.outputs) > len(config.format):
        print 'CONFIG-ERROR: More outfiles (%d) than formatters (%d).' % \
              (len(config.outputs), len(config.format))
        return 1

    failed = True
    runner = Runner(config)
    try:
        failed = runner.run()
    except ParserError, e:
        print "ParseError: %s" % e
示例#9
0
文件: __main__.py 项目: hwkns/behave
def main(args=None):
    config = Configuration(args)
    if config.version:
        print("behave " + __version__)
        return 0

    if config.tags_help:
        print(TAG_HELP)
        return 0

    if config.lang_list:
        from behave.i18n import languages
        iso_codes = languages.keys()
        iso_codes.sort()
        print("Languages available:")
        for iso_code in iso_codes:
            native = languages[iso_code]['native'][0]
            name = languages[iso_code]['name'][0]
            print(u'%s: %s / %s' % (iso_code, native, name))
        return 0

    if config.lang_help:
        from behave.i18n import languages
        if config.lang_help not in languages:
            print('%s is not a recognised language: try --lang-list' %
                  config.lang_help)
            return 1
        trans = languages[config.lang_help]
        print("Translations for %s / %s" % (trans['name'][0],
              trans['native'][0]))
        for kw in trans:
            if kw in 'name native'.split():
                continue
            print(u'%16s: %s' % (kw.title().replace('_', ' '),
                  u', '.join(w for w in trans[kw] if w != '*')))
        return 0

    if not config.format:
        config.format = [ config.default_format ]
    elif config.format and "format" in config.defaults:
        # -- CASE: Formatter are specified in behave configuration file.
        #    Check if formatter are provided on command-line, too.
        if len(config.format) == len(config.defaults["format"]):
            # -- NO FORMATTER on command-line: Add default formatter.
            config.format.append(config.default_format)
    if 'help' in config.format:
        from behave.formatter import formatters
        print("Available formatters:")
        formatters.list_formatters(sys.stdout)
        return 0

    if len(config.outputs) > len(config.format):
        print('CONFIG-ERROR: More outfiles (%d) than formatters (%d).' %
              (len(config.outputs), len(config.format)))
        return 1

    failed = True
    runner = Runner(config)
    try:
        failed = runner.run()
    except ParserError as e:
        print("ParseError: %s" % e)
    except ConfigError as e:
        print("ConfigError: %s" % e)
    except FileNotFoundError as e:
        print("FileNotFoundError: %s" % e)
    except InvalidFileLocationError as e:
        print("InvalidFileLocationError: %s" % e)
    except InvalidFilenameError as e:
        print("InvalidFilenameError: %s" % e)

    if config.show_snippets and runner.undefined_steps:
        print_undefined_step_snippets(runner.undefined_steps,
                                      colored=config.color)

    return_code = 0
    if failed:
        return_code = 1
    return return_code
示例#10
0
def main(args=None):
    config = Configuration(args)
    if config.version:
        print("behave " + __version__)
        return 0

    if config.tags_help:
        print(TAG_HELP)
        return 0

    if config.lang_list:
        from behave.i18n import languages
        iso_codes = languages.keys()
        iso_codes.sort()
        print("Languages available:")
        for iso_code in iso_codes:
            native = languages[iso_code]['native'][0]
            name = languages[iso_code]['name'][0]
            print(u'%s: %s / %s' % (iso_code, native, name))
        return 0

    if config.lang_help:
        from behave.i18n import languages
        if config.lang_help not in languages:
            print('%s is not a recognised language: try --lang-list' % \
                    config.lang_help)
            return 1
        trans = languages[config.lang_help]
        print(u"Translations for %s / %s" % (trans['name'][0],
                                             trans['native'][0]))
        for kw in trans:
            if kw in 'name native'.split():
                continue
            print(u'%16s: %s' % (kw.title().replace('_', ' '),
                  u', '.join(w for w in trans[kw] if w != '*')))
        return 0

    if not config.format:
        config.format = [ config.default_format ]
    elif config.format and "format" in config.defaults:
        # -- CASE: Formatter are specified in behave configuration file.
        #    Check if formatter are provided on command-line, too.
        if len(config.format) == len(config.defaults["format"]):
            # -- NO FORMATTER on command-line: Add default formatter.
            config.format.append(config.default_format)
    if 'help' in config.format:
        from behave.formatter import formatters
        print("Available formatters:")
        formatters.list_formatters(sys.stdout)
        return 0

    if len(config.outputs) > len(config.format):
        print('CONFIG-ERROR: More outfiles (%d) than formatters (%d).' % \
              (len(config.outputs), len(config.format)))
        return 1

    failed = True
    runner = Runner(config)
    try:
        failed = runner.run()
    except ParserError as e:
        print("ParseError: %s" % e)
    except ConfigError as e:
        print("ConfigError: %s" % e)
    except FileNotFoundError as e:
        print("FileNotFoundError: %s" % e)
    except InvalidFileLocationError as e:
        print("InvalidFileLocationError: %s" % e)
    except InvalidFilenameError as e:
        print("InvalidFilenameError: %s" % e)

    if config.show_snippets and runner.undefined_steps:
        print_undefined_step_snippets(runner.undefined_steps,
                                      colored=config.color)

    return_code = 0
    if failed:
        return_code = 1
    return return_code
示例#11
0
def main():
    config = Configuration()

    if config.version:
        print("behave " + __version__)
        sys.exit(0)

    if config.tags_help:
        print(TAG_HELP)
        sys.exit(0)

    if config.lang_list:
        iso_codes = list(languages.keys())
        iso_codes.sort()
        print("Languages available:")
        for iso_code in iso_codes:
            native = languages[iso_code]['native'][0]
            name = languages[iso_code]['name'][0]
            print('%s: %s / %s' % (iso_code, native, name))
        sys.exit(0)

    if config.lang_help:
        if config.lang_help not in languages:
            sys.exit('%s is not a recognised language: try --lang-list' %
                     config.lang_help)
        trans = languages[config.lang_help]
        print("Translations for %s / %s" % (trans['name'][0],
              trans['native'][0]))
        for kw in trans:
            if kw in 'name native'.split():
                continue
            print('%16s: %s' % (kw.title().replace('_', ' '),
                  ', '.join(w for w in trans[kw] if w != '*')))
        sys.exit(0)

    if not config.format:
        default_format = config.defaults["default_format"]
        config.format = [ default_format ]
    elif config.format and "format" in config.defaults:
        # -- CASE: Formatter are specified in behave configuration file.
        #    Check if formatter are provided on command-line, too.
        if len(config.format) == len(config.defaults["format"]):
            # -- NO FORMATTER on command-line: Add default formatter.
            default_format = config.defaults["default_format"]
            config.format.append(default_format)
    if 'help' in config.format:
        print("Available formatters:")
        formatters.list_formatters(sys.stdout)
        sys.exit(0)

    if len(config.outputs) > len(config.format):
        print('CONFIG-ERROR: More outfiles (%d) than formatters (%d).' % \
              (len(config.outputs), len(config.format)))
        sys.exit(1)

    runner = Runner(config)
    try:
        failed = runner.run()
    except ParserError as e:
        sys.exit("ParseError: %s" % e)
    except ConfigError as e:
        sys.exit("ConfigError: %s" % e)
    except FileNotFoundError as e:
        sys.exit("FileNotFoundError: %s" % e)
    except InvalidFileLocationError as e:
        sys.exit("InvalidFileLocationError: %s" % e)
    except InvalidFilenameError as e:
        sys.exit("InvalidFilenameError: %s" % e)


    if config.show_snippets and runner.undefined:
        msg = "\nYou can implement step definitions for undefined steps with "
        msg += "these snippets:\n\n"
        printed = set()
        for step in runner.undefined:
            if step in printed:
                continue
            printed.add(step)
            msg += make_undefined_step_snippet(step)

        # -- OOPS: Unclear if stream supports ANSI coloring.
        sys.stderr.write(escapes['undefined'] + msg + escapes['reset'])
        sys.stderr.flush()

    if failed:
        sys.exit(1)
    # -- OTHERWISE: Successful run.
    sys.exit(0)