def test_invalid_formulas(self, inputs): with self.assertRaises(FormulaError): Parser().ast(inputs)
def test_invalid_compile(self, case): formula, inputs = case with self.assertRaises(sh.DispatcherError): Parser().ast(formula)[1].compile()(*inputs)
def test_valid_formula(self, case): inputs, result = case tokens, ast = Parser().ast(inputs) output = ''.join(t.name for t in tokens) self.assertEqual(result, output, '%s != %s' % (result, output))
def test_compile(self, case): references, formula, inputs, result = case func = Parser().ast(formula)[1].compile(references) output = str(func(*inputs)) self.assertEqual(result, output, '{} != {}'.format(result, output))