def from_sexp(cls, sexp): if isinstance(sexp, Symbol): return cls(checker=sexp.value(), maximum_level=None) else: level, checker = parse_cons_cell(sexp) if not isinstance(checker, Symbol): raise ValueError('Invalid checker: ' + repr(checker)) if not isinstance(level, Symbol): raise ValueError('Invalid level: ' + repr(level)) return cls(checker=checker.value(), maximum_level=level.value())
def from_sexp(cls, sexp): if isinstance(sexp, Symbol): return cls(checker=sexp.value(), warnings_only=False, no_errors=False) else: predicate, checker = parse_cons_cell(sexp) if not isinstance(checker, Symbol): raise ValueError('Invalid checker: ' + repr(checker)) if not isinstance(predicate, Symbol): raise ValueError('Invalid predicate: ' + repr(predicate)) predicate = predicate.value() if predicate not in {'no-errors', 'warnings-only'}: raise ValueError('Invalid predicate: ' + repr(predicate)) return cls(checker=checker.value(), warnings_only=predicate == 'warnings-only', no_errors=predicate == 'no-errors')
def test_parse_cons_cell(sexp, car, cdr): assert lisp_util.parse_cons_cell(sexp) == (car, cdr)
def test_parse_cons_cell_no_cons_cell(sexp): with pytest.raises(ValueError) as excinfo: lisp_util.parse_cons_cell(sexp) assert str(excinfo.value) == 'Not a cons cell: {0!r}'.format(sexp)