def output_failure(step_func, errors): """ Write the given errors to stdout. """ sys.stdout.write(u(colorful.bold_red(u'✘'))) if step_func is not None: sys.stdout.write( u(colorful.red(' (at {0})'.format(get_func_location(step_func))))) sys.stdout.write('\n') for error in errors: print(u(colorful.red(' - {0}'.format(error))))
def output_failure(step_func, errors): """ Write the given errors to stdout. """ sys.stdout.write(u(colorful.bold_red("✘"))) if step_func is not None: sys.stdout.write( u(colorful.red(" (at {0})".format(get_func_location(step_func))))) sys.stdout.write("\n") for error in errors: print(u(colorful.red(" - {0}".format(error))))
def output_failure(step_func, errors): """ Write the given errors to stdout. """ sys.stdout.write(u(colorful.bold_red("✘"))) if step_func is not None: sys.stdout.write( u(colorful.red(" (at {0})".format(get_func_location(step_func)))) ) sys.stdout.write("\n") for error in errors: print(u(colorful.red(" - {0}".format(error))))
def test_step_match(sentence, expected_step, expected_arguments, steps): sys.stdout.write('{0} STEP "{1}" SHOULD MATCH {2} '.format( colorful.yellow('>>'), colorful.cyan(sentence), colorful.cyan(expected_step))) result = match_step(sentence, steps) if not result: output_failure( None, ['Expected sentence didn\'t match any step implementation']) return False if expected_step != result.func.__name__: output_failure(result.func, [ 'Expected sentence matched {0} instead of {1}'.format( result.func.__name__, expected_step) ]) return False if expected_arguments: arguments = merge_step_args(result) expected_arguments = { k: v for expected_arguments in expected_arguments for k, v in expected_arguments.items() } argument_errors = check_step_arguments(expected_arguments, arguments) if argument_errors: output_failure(result.func, argument_errors) return False print(u(colorful.bold_green(u'✔'))) return True
def dot_formatter_failure_summary(self, features, marker): """Output summary for failed Scenarios.""" if not self._failed_steps: return output = "\n" + cf.bold_red("Failures:") + "\n" for step in self._failed_steps: output += "{}: {}\n {}\n".format( step.path, step.parent.sentence, cf.red(step.sentence) ) if world.config.with_traceback: output += " {}\n".format( "\n ".join( [ str(cf.red(l)) for l in step.failure.traceback.split("\n")[:-2] ] ) ) output += " {}: {}\n\n".format( cf.bold_red(step.failure.name), cf.red(step.failure.reason) ) sys.stdout.write(u(output + "\n"))
def test_step_not_match(sentence, expected_not_matching_step, steps): step_to_print = ( colorful.cyan(expected_not_matching_step) if expected_not_matching_step else "ANY" ) sys.stdout.write( '{0} STEP "{1}" SHOULD NOT MATCH {2} '.format( colorful.yellow(">>"), colorful.cyan(sentence), step_to_print ) ) result = match_step(sentence, steps) if result: if ( not expected_not_matching_step or result.func.__name__ == expected_not_matching_step ): output_failure( None, [ "Expected sentence did match {0} but it shouldn't".format( expected_not_matching_step ) ], ) return False print(u(colorful.bold_green("✔"))) return True
def dot_formatter_before_each_feature(self, feature): """ Writes feature header to the console :param Feature feature: the feature to write to the console """ output = cf.bold_black(feature.path) + ": " sys.stdout.write(u(output))
def dot_formatter_after_each_scenario(self, scenario): """ If the scenario is a ExampleScenario it will write the Examples header :param Scenario scenario: the scenario which was ran. """ if isinstance(scenario, (ScenarioOutline, ScenarioLoop)): return sys.stdout.write(u(self.STATE_SYMBOLS[scenario.state]))
def test_step_matches(match_config, steps): """ Test if the given match config matches the actual matched step implementations. """ failed = 0 passed = 0 for item in match_config: validate_config_item(item) sentence = item['sentence'] expected_step = item['should_match'] sys.stdout.write('{0} STEP "{1}" SHOULD MATCH {2} '.format( colorful.yellow('>>'), colorful.cyan(sentence), colorful.cyan(expected_step))) result = match_step(item['sentence'], steps) if not result: output_failure( None, ['Expected sentence didn\'t match any step implementation']) failed += 1 continue if expected_step != result.func.__name__: output_failure(result.func, [ 'Expected sentence matched {0} instead of {1}'.format( result.func.__name__, expected_step) ]) failed += 1 continue expected_arguments = item.get('with_arguments') if expected_arguments: arguments = merge_step_args(result) expected_arguments = { k: v for expected_arguments in expected_arguments for k, v in expected_arguments.items() } argument_errors = check_step_arguments(expected_arguments, arguments) if argument_errors: output_failure(result.func, argument_errors) failed += 1 continue # check if arguments match print(u(colorful.bold_green(u'✔'))) passed += 1 return failed, passed
def test_step_not_match(sentence, expected_not_matching_step, steps): step_to_print = colorful.cyan( expected_not_matching_step) if expected_not_matching_step else 'ANY' sys.stdout.write('{0} STEP "{1}" SHOULD NOT MATCH {2} '.format( colorful.yellow('>>'), colorful.cyan(sentence), step_to_print)) result = match_step(sentence, steps) if result: if not expected_not_matching_step or result.func.__name__ == expected_not_matching_step: output_failure(None, [ 'Expected sentence did match {0} but it shouldn\'t'.format( expected_not_matching_step) ]) return False print(u(colorful.bold_green(u'✔'))) return True
def test_step_not_match(sentence, expected_not_matching_step, steps): step_to_print = (colorful.cyan(expected_not_matching_step) if expected_not_matching_step else "ANY") sys.stdout.write('{0} STEP "{1}" SHOULD NOT MATCH {2} '.format( colorful.yellow(">>"), colorful.cyan(sentence), step_to_print)) result = match_step(sentence, steps) if result: if (not expected_not_matching_step or result.func.__name__ == expected_not_matching_step): output_failure( None, [ "Expected sentence did match {0} but it shouldn't".format( expected_not_matching_step) ], ) return False print(u(colorful.bold_green("✔"))) return True
def test_step_match(sentence, expected_step, expected_arguments, steps): sys.stdout.write( '{0} STEP "{1}" SHOULD MATCH {2} '.format( colorful.yellow(">>"), colorful.cyan(sentence), colorful.cyan(expected_step) ) ) result = match_step(sentence, steps) if not result: output_failure(None, ["Expected sentence didn't match any step implementation"]) return False if expected_step != result.func.__name__: output_failure( result.func, [ "Expected sentence matched {0} instead of {1}".format( result.func.__name__, expected_step ) ], ) return False if expected_arguments: arguments = merge_step_args(result) expected_arguments = { k: v for expected_arguments in expected_arguments for k, v in expected_arguments.items() } argument_errors = check_step_arguments(expected_arguments, arguments) if argument_errors: output_failure(result.func, argument_errors) return False print(u(colorful.bold_green("✔"))) return True