Esempio n. 1
0
class TestAtomNotification(unittest.TestCase):

    def setUp(self):
        expressions = {
            'a': Expr('2'),
            'b': Expr('a*10'),
        }
        self.ant = ANT()
        self.ns = ExpressionNamespace(expressions)
        self.ns.observe('_locals', self.ant.mark_observed)

    def test_get_value_notification(self):
        for v in ('a', 'b'):
            self.ant.observed = False
            self.ns.get_value(v)
            self.assertTrue(self.ant.observed)

    def test_set_value_notification(self):
        self.ant.observed = False
        self.ns.set_value('c', 5)
        self.assertTrue(self.ant.observed)

    def test_get_value_notification_no_change(self):
        self.ant.observed = False
        self.ns.get_value('b')
        self.assertTrue(self.ant.observed)

        # Should not trigger notification because 'a' was already computed when
        # getting 'b', so there was no change in value.
        self.ant.observed = False
        self.ns.get_value('a')
        self.assertFalse(self.ant.observed)
Esempio n. 2
0
 def test_extra_context(self):
     random = np.random.RandomState(seed=1)
     ns = ExpressionNamespace(self.EXPRESSIONS, {'random': random})
     ns.set_values({'data.channel.bar': 3.1})
     ns.set_value('z', 32)
     values = ns.get_values()
     self.assertTrue('z' in values)
     self.assertTrue('data.channel.bar' in values)
     self.assertEqual(values['z'], 32)
     self.assertEqual(values['f'], 31)