Skip to content

Commit

Permalink
add unit test for enable cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Rfank2021 committed Apr 6, 2021
1 parent 1a6a535 commit 71c5cc7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions test_simpleeval.py
Expand Up @@ -26,15 +26,26 @@ class DRYTest(unittest.TestCase):
def setUp(self):
""" initialize a SimpleEval """
self.s = SimpleEval()
self.s_cached = SimpleEval(enable_cache=True)

def t(self, expr, shouldbe): # pylint: disable=invalid-name
def t(self, expr, shouldbe, s=None): # pylint: disable=invalid-name
""" test an evaluation of an expression against an expected answer """
return self.assertEqual(self.s.eval(expr), shouldbe)
s = (s or self.s)
return self.assertEqual(s.eval(expr), shouldbe)


class TestBasic(DRYTest):
""" Simple expressions. """

def test_enable_cache(self):
""" test enable parsed expression cache. """
self.t("21 + 21", 42, s=self.s_cached)
self.t("21 + 21", 42, s=self.s_cached)
self.t("'a' if 1 == 1 else 'b'", 'a', s=self.s_cached)
self.t('110 == 100 + 10 and True', True, s=self.s_cached)
self.t('110 == 100 + 10 and True', True, s=self.s_cached)
self.t("'a' if 1 == 1 else 'b'", 'a', s=self.s_cached)

def test_maths_with_ints(self):
""" simple maths expressions """

Expand Down

0 comments on commit 71c5cc7

Please sign in to comment.