def step_impl(context, timestamp): parsed = et.fromstring(str(context.response.text)) creationTime = parsed.find(get_UwsName("creationTime")).text check(creationTime).is_not_none().or_raise(Exception, "Error with creationTime: {msg}. Job link is %s. The http response was: %r" % (context.joblink, context.response)) # convert creationTime to UTC, in case it has a timezone attached: date = dateutil.parser.parse(creationTime) if date.utcoffset() is not None: utz = pytz.timezone('UTC') date = date.astimezone(utz).replace(tzinfo=None) date = date.isoformat() context.job = uws.Job() context.job.creationTime = date # also convert timestamp to a useful format for comparison (not helping with format like 2015-W01 though) timestamp = dateutil.parser.parse(timestamp).isoformat() ensure(date).is_less_than_or_equal_to(timestamp)
def __init__(self, tooth: str, calculus: str, eh: str, cavities: str, abcess: str): check(tooth).is_in(VALID_TEETH).or_raise(ValueError) check(calculus).is_in(VALID_CALCULUS).or_raise(ValueError) check(eh).is_in(VALID_EH).or_raise(ValueError) check(cavities).is_in(VALID_CAVITIES).or_raise(ValueError) check(abcess).is_in(VALID_ABCESS).or_raise(ValueError) # If there is no tooth then there can be no calculus, eh or cavities. # Note there can be abcess if tooth == 'NA': check(calculus).equals('NA').or_raise(ValueError) check(eh).equals('NA').or_raise(ValueError) check(cavities).equals('NA').or_raise(ValueError) self._tooth: str = tooth self._calculus: str = calculus self._eh: str = eh self._cavities: str = cavities self._abcess: str = abcess
def test_error_formatting(self): with self.assertRaisesRegexp(Exception, "Major fail detected"): check(False).is_true().or_raise(KeyError, "{} {error} detected", "Major", error="fail")