def test_forked_args(self):
     """If argument node gives forked return, only used indexed argument."""
     mock_arg = MockCallback()
     mock_arg.body.eval.return_value = TwoInts(x=5, y=6)
     mock_arg.index = 'x'
     node_body = PyConstBody(self.mock_callback, mock_arg)
     node_body.eval()
     self.mock_callback.assert_called_with(5)
 def test_evaluated_once(self):
     """Callback should be called only once, even if evaluated multiple
     times.
     """
     node_body = PyConstBody(self.mock_callback)
     node_body.eval()
     node_body.eval()
     self.mock_callback.assert_called_once()
 def test_receive_none_kwarg_nonoptional(self):
     """None should not be received for kwargs."""
     mock_kwarg = MockCallback()
     mock_kwarg.body.eval.return_value = None
     mock_kwarg.index = None
     node_body = PyConstBody(self.mock_callback, a=mock_kwarg)
     with self.assertRaises(ValueError):
         node_body.eval()
 def test_kwargs_evaluated_once(self):
     """Keyword arguments should be evaluated and used only once."""
     mock_kwarg = MockCallback()
     mock_kwarg.body.eval.return_value = 5
     mock_kwarg.index = None
     node_body = PyConstBody(self.mock_callback, a=mock_kwarg)
     node_body.eval()
     node_body.eval()
     mock_kwarg.body.eval.assert_called_once()
 def test_args_eval(self):
     """Arguments should be evaluated and used."""
     mock_arg = MockCallback()
     mock_arg.body.eval.return_value = 5
     mock_arg.index = None
     node_body = PyConstBody(self.mock_callback, mock_arg)
     node_body.eval()
     mock_arg.body.eval.assert_called()
     self.mock_callback.assert_called_with(5)
 def test_receive_none_forked_arg_nonoptional(self):
     """None should not be received for args."""
     mock_arg = MockCallback()
     mock_arg.body.eval.return_value = TwoInts(None, 3)
     mock_arg.index = 'x'
     mock_arg.outputs = TwoIntsT
     node_body = PyConstBody(self.mock_callback, mock_arg)
     with self.assertRaises(ValueError):
         node_body.eval()
 def test_forked_args(self):
     """If argument node gives forked return, only used indexed argument."""
     mock_arg = MockCallback()
     mock_arg.body.eval.return_value = 5, 6
     mock_arg.index = 'x'
     mock_arg.outputs = OrderedDict([('x', int), ('y', int)])
     node_body = PyConstBody(self.mock_callback, mock_arg)
     node_body.eval()
     self.mock_callback.assert_called_with(5)
 def test_receive_none_forked_kwarg_nonoptional(self):
     """None should not be received for kwargs."""
     mock_kwarg = MockCallback()
     mock_kwarg.body.eval.return_value = None, 3
     mock_kwarg.index = 'x'
     mock_kwarg.outputs = OrderedDict([('x', int), ('y', int)])
     node_body = PyConstBody(self.mock_callback, a=mock_kwarg)
     with self.assertRaises(ValueError):
         node_body.eval()
 def test_args_evaluated_once(self):
     """Arguments should be evaluated and used only once."""
     mock_arg = MockCallback()
     mock_arg.body.eval.return_value = 5
     mock_arg.index = None
     mock_arg.outputs = OrderedDict([('x', int)])
     node_body = PyConstBody(self.mock_callback, mock_arg)
     node_body.eval()
     node_body.eval()
     mock_arg.body.eval.assert_called_once()
 def test_kwargs_eval(self):
     """Keyword arguments should be evaluated and used."""
     mock_kwarg = MockCallback()
     mock_kwarg.body.eval.return_value = 5
     mock_kwarg.index = None
     mock_kwarg.outputs = OrderedDict([('x', int)])
     node_body = PyConstBody(self.mock_callback, a=mock_kwarg)
     node_body.eval()
     mock_kwarg.body.eval.assert_called()
     self.mock_callback.assert_called_with(a=5)
    def test_globals(self):
        """Setting up globals in the environment."""
        a = 3

        def add_2():
            return a+2
        node_body = PyConstBody(add_2)
        self.assertEqual(5, node_body.eval())
 def test_return_value(self):
     """Evaluated value should be returned."""
     self.mock_callback.return_value = 3
     node_body = PyConstBody(self.mock_callback)
     self.assertEqual(3, node_body.eval())
 def test_callback(self):
     """Callback should be called."""
     node_body = PyConstBody(self.mock_callback)
     node_body.eval()
     self.mock_callback.assert_called()