示例#1
0
def make_test_funcs(steps, feature_id):

    filename = 'test_{}.py'.format(feature_id)
    with open(os.path.join(settings.PROJECT_ROOT, 'stephen_demo_repo', filename), 'w') as f:
        for step in steps:
            test_fun = make_undefined_step_snippet(step)
            f.write(test_fun)
    return filename
示例#2
0
def step_status_details(result):
    if result.exception:
        return StatusDetails(message=format_exception(type(result.exception), result.exception),
                             trace=format_traceback(result.exc_traceback))
    elif result.status == 'undefined':
        message = '\nYou can implement step definitions for undefined steps with these snippets:\n\n'
        message += make_undefined_step_snippet(result)
        return StatusDetails(message=message)
示例#3
0
def step_status_details(result):
    if result.exception:
        message = u','.join(map(lambda s: u'%s' % s, result.exception.args))
        message = u'{name}: {message}'.format(name=result.exception.__class__.__name__, message=message)
        trace = '\n'.join(traceback.format_tb(result.exc_traceback)).decode('utf-8') if result.exc_traceback else None
        return StatusDetails(message=message, trace=trace)
    elif result.status == 'undefined':
        message = u'\nYou can implement step definitions for undefined steps with these snippets:\n\n'
        message += make_undefined_step_snippet(result)
        return StatusDetails(message=message)
示例#4
0
def step_status_details(result):
    if result.exception:
        # workaround for https://github.com/behave/behave/pull/616
        trace = "\n".join(result.exc_traceback) if type(result.exc_traceback) == list else format_traceback(
            result.exc_traceback)
        return StatusDetails(message=format_exception(type(result.exception), result.exception), trace=trace)

    elif result.status == 'undefined':
        message = '\nYou can implement step definitions for undefined steps with these snippets:\n\n'
        message += make_undefined_step_snippet(result)
        return StatusDetails(message=message)
def step_undefined_step_snippet_should_not_exist_for(context, step):
    """
    Checks if an undefined-step snippet is provided for a step
    in behave command output (last command).
    """
    undefined_step_snippet  = make_undefined_step_snippet(step)
    context.execute_steps(u'''\
Then the command output should not contain:
    """
    {undefined_step_snippet}
    """
    '''.format(undefined_step_snippet=text_indent(undefined_step_snippet, 4)))
示例#6
0
def step_undefined_step_snippet_should_not_exist_for(context, step):
    """
    Checks if an undefined-step snippet is provided for a step
    in behave command output (last command).
    """
    undefined_step_snippet = make_undefined_step_snippet(step)
    context.execute_steps(u'''\
Then the command output should not contain:
    """
    {undefined_step_snippet}
    """
    '''.format(undefined_step_snippet=text_indent(undefined_step_snippet, 4)))
示例#7
0
	def run(self):
		#each browsers
		
		for browser in self.browsers:
			#pathes
			bro_dirname = browser['id'] if browser else 'none'
			json_path = os.path.join(self.report_dir,bro_dirname,str(random.random())+'.json')
			screenshots_dir = os.path.join(self.report_dir,bro_dirname)
			approved_dir = os.path.join(os.path.dirname(os.path.dirname(self.report_dir)), 'approved', bro_dirname)
			runner = copy.copy(self.runner)
			#reload
			runner.prepare_launch()
			# set worker to context
			runner.set_worker(self)
			runner.context.set_browser_config(browser)
			self.screenshots_dir = screenshots_dir
			self.approved_dir = approved_dir
			#set screenshot dirs to steps
			features = runner.get_features()
			if not features:
				self.log('Runner is empty. Nothing to run.', level='ERROR')
				return
			#set screenshots dir for capture_screens() hook
			#[[ self.set_screenshot_dir_to_steps(screenshots_dir,scenario) for scenario in feature.scenarios ] for feature in features ]
			# add hooks
			runner.add_hooks(self.hooks())
			#try make dir for json
			try:
				os.makedirs(os.path.dirname(json_path))
				os.makedirs(approved_dir)
			except:
				pass
			plain_stream = StringIO.StringIO()
			#outputs
			streams = [StreamOpener(json_path),StreamOpener(stream=plain_stream)]
			runner.run(streams)
			if browser:
				name = 'configured with browser %s'%browser['id']
			else:
				name = ''
			plain_stream.seek(0)
			output = '\nRunner %s finished and say: \n %s'%(name, plain_stream.read())
			self.log(output)
			#collect undefined steps
			if self.runner.undefined_steps:
				for step in self.runner.undefined_steps:
					snippet = make_undefined_step_snippet(step)
					if snippet not in self.und_steps_queue:
						self.und_steps_queue.put(snippet)
		_stopped = True
		return
示例#8
0
def step_status_details(result):
    if result.exception:
        # workaround for https://github.com/behave/behave/pull/616
        trace = result.exc_traceback if type(
            result.exc_traceback) == list else format_traceback(
                result.exc_traceback)
        return StatusDetails(message=format_exception(type(result.exception),
                                                      result.exception),
                             trace=trace)

    elif result.status == 'undefined':
        message = '\nYou can implement step definitions for undefined steps with these snippets:\n\n'
        message += make_undefined_step_snippet(result)
        return StatusDetails(message=message)
示例#9
0
def step_status_details(result):
    if result.exception:
        message = u','.join(map(str, result.exception.args))
        message = u'{name}: {message}'.format(
            name=result.exception.__class__.__name__, message=message)
        trace = u'\n'.join(traceback.format_tb(
            result.exc_traceback)) if result.exc_traceback else None
        message += '\n\nRerun with:\n    python manage.py behave -D ipdb \'%s\'' % str(
            result.location)
        return StatusDetails(message=message, trace=trace)
    elif result.status == 'undefined':
        message = u'\nYou can implement step definitions for undefined steps with these snippets:\n\n'
        message += make_undefined_step_snippet(result)
        return StatusDetails(message=message)
示例#10
0
        sys.exit("ConfigError: %s" % e)
    except FileNotFoundError, e:
        sys.exit("FileNotFoundError: %s" % e)
    except InvalidFileLocationError, e:
        sys.exit("InvalidFileLocationError: %s" % e)
    except InvalidFilenameError, e:
        sys.exit("InvalidFilenameError: %s" % e)


    if config.show_snippets and runner.undefined:
        msg = u"\nYou can implement step definitions for undefined steps with "
        msg += u"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)

if __name__ == '__main__':
    main()
示例#11
0
文件: __main__.py 项目: vhumpa/behave
        sys.exit("ConfigError: %s" % e)
    except FileNotFoundError, e:
        sys.exit("FileNotFoundError: %s" % e)
    except InvalidFileLocationError, e:
        sys.exit("InvalidFileLocationError: %s" % e)
    except InvalidFilenameError, e:
        sys.exit("InvalidFilenameError: %s" % e)

    if config.show_snippets and runner.undefined:
        msg = u"\nYou can implement step definitions for undefined steps with "
        msg += u"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)


if __name__ == "__main__":
    main()
示例#12
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)