5 sys
.path
.append(os
.path
.join(os
.path
.dirname(__file__
), '..'))
7 from Expression
import Expression
, Context
9 class TestContext(unittest
.TestCase
):
11 Unit tests for the Context class
16 self
.c
['FAIL'] = 'PASS'
18 def test_string_literal(self
):
19 """test string literal, fall-through for undefined var in a Context"""
20 self
.assertEqual(self
.c
['PASS'], 'PASS')
22 def test_variable(self
):
23 """test value for defined var in the Context class"""
24 self
.assertEqual(self
.c
['FAIL'], 'PASS')
27 """test 'var in context' to not fall for fallback"""
28 self
.assert_('FAIL' in self
.c
)
29 self
.assert_('PASS' not in self
.c
)
31 class TestExpression(unittest
.TestCase
):
33 Unit tests for the Expression class
34 evaluate() is called with a context {FAIL: 'PASS'}
39 self
.c
['FAIL'] = 'PASS'
41 def test_string_literal(self
):
42 """Test for a string literal in an Expression"""
43 self
.assertEqual(Expression('PASS').evaluate(self
.c
), 'PASS')
45 def test_variable(self
):
46 """Test for variable value in an Expression"""
47 self
.assertEqual(Expression('FAIL').evaluate(self
.c
), 'PASS')
50 """Test for the ! operator"""
51 self
.assert_(Expression('!0').evaluate(self
.c
))
52 self
.assert_(not Expression('!1').evaluate(self
.c
))
54 def test_equals(self
):
55 """ Test for the == operator"""
56 self
.assert_(Expression('FAIL == PASS').evaluate(self
.c
))
58 def test_notequals(self
):
59 """ Test for the != operator"""
60 self
.assert_(Expression('FAIL != 1').evaluate(self
.c
))
62 if __name__
== '__main__':