- if self.result is not None:
- self.result = [r['geocoding'] for r in self.result]
-
- def assert_field(self, idx, field, value):
- """ Check that result row `idx` has a field `field` with value `value`.
- Float numbers are matched approximately. When the expected value
- starts with a carat, regular expression matching is used.
- """
- assert field in self.result[idx], \
- "Result row {} has no field '{}'.\nFull row: {}"\
- .format(idx, field, json.dumps(self.result[idx], indent=4))
-
- if isinstance(value, float):
- assert Almost(value) == float(self.result[idx][field]), \
- BadRowValueAssert(self, idx, field, value)
- elif value.startswith("^"):
- assert re.fullmatch(value, self.result[idx][field]), \
- BadRowValueAssert(self, idx, field, value)
- elif isinstance(self.result[idx][field], dict):
- assert self.result[idx][field] == eval('{' + value + '}'), \
- BadRowValueAssert(self, idx, field, value)
- else:
- assert str(self.result[idx][field]) == str(value), \
- BadRowValueAssert(self, idx, field, value)
-
-
- def assert_subfield(self, idx, path, value):
- assert path
-
- field = self.result[idx]
- for p in path:
- assert isinstance(field, dict)
- assert p in field
- field = field[p]
-
- if isinstance(value, float):
- assert Almost(value) == float(field)
- elif value.startswith("^"):
- assert re.fullmatch(value, field)
- elif isinstance(field, dict):
- assert field, eval('{' + value + '}')
- else:
- assert str(field) == str(value)