Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _exp_measures_to_dict(measures):
def convertvalue(value):
return None if value == "None" else float(value)
res = {}
if isinstance(measures, model.Table):
res = {row["metric"]: convertvalue(row["value"]) for row in measures}
elif isinstance(measures, list):
assert len(measures) == len(TEST_METRICS_ORDER)
res = {}
for i in range(len(measures) - 1):
res[TEST_METRICS_ORDER[i]] = convertvalue(measures[i])
return res
def _toSimpleDict(measures):
if isinstance(measures, model.Table):
return {row["metric"]: None if row["value"] == "None" else float(row["value"])
for row in measures}
else:
return {measure["key"]: measure["val"] for measure in measures}
def test_parse_tags_with_tags_and_comment(self):
tags = parse_tags('@one @two.three-four @xxx # @fake-tag-in-comment xxx')
assert len(tags) == 3
assert tags == [
model.Tag(name, 1)
for name in (u'one', u'two.three-four', u'xxx')
]
self.examples = None
else:
step = self.statement.steps[-1]
step.table = self.table
if step.name.endswith(":"):
step.name = step.name[:-1]
self.table = None
self.state = "steps"
return self.action_steps(line)
# -- SUPPORT: Escaped-pipe(s) in Gherkin cell values.
# Search for pipe(s) that are not preceeded with an escape char.
cells = [cell.replace("\\|", "|").strip()
for cell in re.split(r"(?
'keyword': scenario.keyword,
'name': scenario.name,
'tags': scenario.tags,
'location': scenario.location,
'steps': [],
})
"""
keyword = json_element.get("keyword", u"")
name = json_element.get("name", u"")
description = json_element.get("description", [])
tags = json_element.get("tags", [])
location = json_element.get("location", u"")
json_steps = json_element.get("steps", [])
steps = self.parse_steps(json_steps)
filename, line = location.split(":")
scenario = model.Scenario(filename, line, keyword, name, tags, steps)
scenario.description = description
return scenario
def parse_feature(self, json_feature):
name = json_feature.get("name", u"")
keyword = json_feature.get("keyword", None)
tags = json_feature.get("tags", [])
description = json_feature.get("description", [])
location = json_feature.get("location", u"")
filename, line = location.split(":")
feature = model.Feature(filename, line, keyword, name, tags, description)
json_elements = json_feature.get("elements", [])
for json_element in json_elements:
self.add_feature_element(feature, json_element)
return feature
def _build_scenario_statement(self, keyword, line):
name = line[len(keyword) + 1:].strip()
scenario = model.Scenario(self.filename, self.line, keyword, name,
tags=self.tags)
self.statement = scenario
self.scenario_container.add_scenario(scenario)
# OLD: self.feature.add_scenario(self.statement)
# -- RESET STATE:
self.tags = []
# -- CASE: Line does not start w/ a step-keyword.
continue
# -- HINT: Trailing SPACE is used for most keywords.
# BUT: Keywords in some languages (like Chinese, Japanese, ...)
# do not need a whitespace as word separator.
step_text_after_keyword = line[len(kw):].strip()
if step_type in ("and", "but"):
if not self.last_step:
raise ParserError(u"No previous step",
self.line, self.filename)
step_type = self.last_step
else:
self.last_step = step_type
keyword = kw.rstrip() # HINT: Strip optional trailing SPACE.
step = model.Step(self.filename, self.line,
keyword, step_type, step_text_after_keyword)
return step
return None
def _build_background_statement(self, keyword, line):
if self.tags:
msg = u"Background supports no tags: @%s" % (u" @".join(self.tags))
raise ParserError(msg, self.line, self.filename, line)
elif self.scenario_container and self.scenario_container.background:
if self.scenario_container.background.steps:
# -- HINT: Rule may have default background w/o steps.
msg = u"Second Background (can have only one)"
raise ParserError(msg, self.line, self.filename, line)
name = line[len(keyword) + 1:].strip()
background = model.Background(self.filename, self.line, keyword, name)
self.scenario_container.add_background(background)
self.statement = background