Esempio n. 1
0
    def test_expr_from_tokens(self):
        self.assertEqual(
            expr_from_tokens(['(', '1', '2', '3', ')']),
            [1, 2, 3]
        )

        with self.assertRaises(SyntaxError) as cm:
            eval_string('(')
        with self.assertRaises(SyntaxError):
            expr_from_tokens([')'])
        self.assertEqual(str(cm.exception), 'Unexpected ")"')
Esempio n. 2
0
    def test_expr_from_tokens_raises(self):
        with self.assertRaises(SyntaxError) as cm:
            expr_from_tokens([])
        self.assertEqual(str(cm.exception), 'Unexpected EOF at start of expression')

        with self.assertRaises(SyntaxError) as cm:
            expr_from_tokens(['('])
        self.assertEqual(str(cm.exception), 'Unexpected EOF mid expression')

        with self.assertRaises(SyntaxError) as cm:
            expr_from_tokens([')'])
        self.assertEqual(str(cm.exception), 'Unexpected ")"')
Esempio n. 3
0
 def test_expr_from_tokens_returns_first_expression_only(self):
     tokens = ['(', '1', '2', ')', '(', '3', ')']
     self.assertEqual(expr_from_tokens(tokens), [1, 2])
     self.assertEqual(tokens, ['(', '3', ')'])
Esempio n. 4
0
 def test_expr_from_tokens(self):
     self.assertEqual(
         expr_from_tokens(['(', '1', '2', '3', ')']),
         [1, 2, 3]
     )