def parse_ordinal_identifier(ordinal_identifier, lineno=None): """Checks if the string `ordinal_identifier` is a number followed by one of the suffixes st, nd, rd or th. Raises chef.validators.OrdinalIdentifierError if it does not. Else, return the appertaining number as an integer. """ m = re.match(ORDINAL_IDENTIFIER_PATTERN, ordinal_identifier) if m is None: raise syntax_errors.OrdinalIdentifierError(ordinal_identifier, lineno) num_str, suffix = m.groups() validate_ordinal_id_suffix(num_str, suffix, lineno) return int(num_str)
def test_th(self, number): with pytest.raises(syntax_errors.NonMatchingSuffixError) as e: validate_ordinal_id_suffix(number, 'th') # muahaha, side effects! assert e.value.number == self.th_numbers.pop() assert e.value.suffix == 'th'