Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_make_step_for_row__without_placeholders_remains_unchanged(self):
step_text = u'Given a step without placeholders'
expected_text = text(step_text)
params = dict(firstname="Alice", lastname="Beauville")
self.assert_make_step_for_row(step_text, expected_text, params)
def test__problem_exists_with_problematic_encoding(self):
"""Test ensures that problem exists with encoding=unicode-escape"""
# -- NOTE: Explicit use of problematic encoding
problematic_encoding = "unicode-escape"
text2 = text(self.traceback_bytes, problematic_encoding)
print("TEXT: "+ text2)
assert isinstance(self.traceback_bytes, bytes)
assert isinstance(text2, six.text_type)
# -- VERIFY BAD-OUTCOME: With problematic encoding
file_line_text = self.traceback_file_line_texts[0]
assert file_line_text not in text2
def test_text__with_object_convertable_to_unicode(self, text_value):
obj = ConvertableToUnicode(text_value)
actual_text = text(obj)
assert actual_text == text_value
assert isinstance(actual_text, six.text_type)
def make_row(*data, **kwargs):
line = kwargs.pop("line", None)
data2 = dict(data, **kwargs)
headings = list(data2.keys())
cells = [text(value) for value in data2.values()]
return Row(headings, cells, line=line)
self._process_scenario_outline(scenario_outline, report)
else:
self._process_scenario(scenario, report)
# -- ADD TESTCASES to testsuite:
for testcase in report.testcases:
suite.append(testcase)
suite.set(u'tests', _text(report.counts_tests))
suite.set(u'errors', _text(report.counts_errors))
suite.set(u'failures', _text(report.counts_failed))
suite.set(u'skipped', _text(report.counts_skipped)) # WAS: skips
suite.set(u'time', _text(round(feature.duration, 6)))
# -- SINCE: behave-1.2.6.dev0
if self.show_timestamp:
suite.set(u'timestamp', _text(now.isoformat()))
if self.show_hostname:
suite.set(u'hostname', _text(gethostname()))
if not os.path.exists(self.config.junit_directory):
# -- ENSURE: Create multiple directory levels at once.
os.makedirs(self.config.junit_directory)
tree = ElementTreeWithCDATA(suite)
report_dirname = self.config.junit_directory
report_basename = u'TESTS-%s.xml' % feature_filename
report_filename = os.path.join(report_dirname, report_basename)
tree.write(codecs.open(report_filename, "wb"), "UTF-8")
scenarios = []
for example_index, example in enumerate(scenario_outline.examples):
example.index = example_index+1
params["examples.name"] = example.name
params["examples.index"] = _text(example.index)
if not example.table:
# -- SYNDROME: Examples keyword without table
print("ERROR: ScenarioOutline.Examples: Has NO-TABLE syndrome ({0})"\
.format(example.location))
continue
for row_index, row in enumerate(example.table):
row.index = row_index+1
row.id = "%d.%d" % (example.index, row.index)
params["row.id"] = row.id
params["row.index"] = _text(row.index)
scenario_name = self.make_scenario_name(scenario_outline.name,
example, row, params)
row_tags = self.make_row_tags(scenario_outline.tags, row, params)
row_tags.extend(example.tags)
new_steps = []
for outline_step in scenario_outline.steps:
new_step = self.make_step_for_row(outline_step, row, params)
new_steps.append(new_step)
# -- STEP: Make Scenario name for this row.
# scenario_line = example.line + 2 + row_index
scenario_line = row.line
scenario = Scenario(scenario_outline.filename, scenario_line,
scenario_outline.keyword,
scenario_name, row_tags, new_steps)
scenario.feature = scenario_outline.feature
assert isinstance(scenario, Scenario)
assert not isinstance(scenario, ScenarioOutline)
if scenario.status != Status.skipped or self.show_skipped:
# -- NOTE: Count only if not-skipped or skipped should be shown.
report.counts_tests += 1
classname = report.classname
feature = report.feature
feature_name = feature.name
if not feature_name:
feature_name = self.make_feature_filename(feature)
case = ElementTree.Element('testcase')
case.set(u"classname", u"%s.%s" % (classname, feature_name))
case.set(u"name", scenario.name or "")
case.set(u"status", scenario.status.name)
case.set(u"time", _text(round(scenario.duration, 6)))
step = None
failing_step = None
if scenario.status == Status.failed:
for status in (Status.failed, Status.undefined):
step = self.select_step_with_status(status, scenario)
if step:
break
# -- NOTE: Scenario may fail now due to hook-errors.
element_name = "failure"
if step and isinstance(step.exception, (AssertionError, type(None))):
# -- FAILURE: AssertionError
assert step.status in (Status.failed, Status.undefined)
report.counts_failed += 1
else:
# -- UNEXPECTED RUNTIME-ERROR:
def captured(self):
"""Provides access of the captured output data.
:return: Object that stores the captured output parts (as Captured).
"""
stdout = None
stderr = None
log_out = None
if self.config.stdout_capture and self.stdout_capture:
stdout = _text(self.stdout_capture.getvalue())
if self.config.stderr_capture and self.stderr_capture:
stderr = _text(self.stderr_capture.getvalue())
if self.config.log_capture and self.log_capture:
log_out = _text(self.log_capture.getvalue())
return Captured(stdout, stderr, log_out)
def doc_string(self, doc_string):
#self.stream.write(' """' + doc_string.content_type + '\n')
doc_string = _text(doc_string)
prefix = u" "
self.stream.write(u'%s"""\n' % prefix)
doc_string = escape_triple_quotes(indent(doc_string, prefix))
self.stream.write(doc_string)
self.stream.write(u'\n%s"""\n' % prefix)
self.stream.flush()
assert step.status in (Status.failed, Status.undefined)
report.counts_failed += 1
else:
# -- UNEXPECTED RUNTIME-ERROR:
report.counts_errors += 1
element_name = "error"
# -- COMMON-PART:
failure = ElementTree.Element(element_name)
if step:
step_text = self.describe_step(step).rstrip()
text = u"\nFailing step: %s\nLocation: %s\n" % \
(step_text, step.location)
message = _text(step.exception)
failure.set(u'type', step.exception.__class__.__name__)
failure.set(u'message', message)
text += _text(step.error_message)
else:
# -- MAYBE: Hook failure before any step is executed.
failure_type = "UnknownError"
if scenario.exception:
failure_type = scenario.exception.__class__.__name__
failure.set(u'type', failure_type)
failure.set(u'message', scenario.error_message or "")
traceback_lines = traceback.format_tb(scenario.exc_traceback)
traceback_lines.insert(0, u"Traceback:\n")
text = _text(u"".join(traceback_lines))
failure.append(CDATA(text))
case.append(failure)
elif (scenario.status in (Status.skipped, Status.untested)
and self.show_skipped):
report.counts_skipped += 1
step = self.select_step_with_status(Status.undefined, scenario)