Back to index

enigmail  1.4.3
unit-Expression.py
Go to the documentation of this file.
00001 import unittest
00002 
00003 import sys
00004 import os.path
00005 sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
00006 
00007 from Expression import Expression, Context
00008 
00009 class TestContext(unittest.TestCase):
00010   """
00011   Unit tests for the Context class
00012   """
00013 
00014   def setUp(self):
00015     self.c = Context()
00016     self.c['FAIL'] = 'PASS'
00017 
00018   def test_string_literal(self):
00019     """test string literal, fall-through for undefined var in a Context"""
00020     self.assertEqual(self.c['PASS'], 'PASS')
00021 
00022   def test_variable(self):
00023     """test value for defined var in the Context class"""
00024     self.assertEqual(self.c['FAIL'], 'PASS')
00025 
00026   def test_in(self):
00027     """test 'var in context' to not fall for fallback"""
00028     self.assert_('FAIL' in self.c)
00029     self.assert_('PASS' not in self.c)
00030 
00031 class TestExpression(unittest.TestCase):
00032   """
00033   Unit tests for the Expression class
00034   evaluate() is called with a context {FAIL: 'PASS'}
00035   """
00036 
00037   def setUp(self):
00038     self.c = Context()
00039     self.c['FAIL'] = 'PASS'
00040 
00041   def test_string_literal(self):
00042     """Test for a string literal in an Expression"""
00043     self.assertEqual(Expression('PASS').evaluate(self.c), 'PASS')
00044 
00045   def test_variable(self):
00046     """Test for variable value in an Expression"""
00047     self.assertEqual(Expression('FAIL').evaluate(self.c), 'PASS')
00048 
00049   def test_not(self):
00050     """Test for the ! operator"""
00051     self.assert_(Expression('!0').evaluate(self.c))
00052     self.assert_(not Expression('!1').evaluate(self.c))
00053 
00054   def test_equals(self):
00055     """ Test for the == operator"""
00056     self.assert_(Expression('FAIL == PASS').evaluate(self.c))
00057 
00058   def test_notequals(self):
00059     """ Test for the != operator"""
00060     self.assert_(Expression('FAIL != 1').evaluate(self.c))
00061 
00062 if __name__ == '__main__':
00063   unittest.main()