def test_eq_with_args_and_kwargs(self):
        const_value = 1
        b1_1 = PyConstBody(lambda: const_value, value=const_value)
        b2_1 = PyConstBody(lambda: const_value, value=const_value)
        b3_1 = self.make_b3(b1_1, b2_1)

        b1_2 = PyConstBody(lambda: const_value, value=const_value)
        b2_2 = PyConstBody(lambda: const_value, value=const_value)
        b3_2 = self.make_b3(a=b1_2, b=b2_2)

        self.assertEqual(b3_1, b3_2)
    def test_neq_func_body_diff(self):
        const_value = 1
        b1_1 = PyConstBody(lambda: const_value, value=const_value)
        b2_1 = PyConstBody(lambda: const_value, value=const_value)
        b3 = self.make_b3(b1_1, b2_1)

        b1_2 = PyConstBody(lambda: const_value, value=const_value)
        b2_2 = PyConstBody(lambda: const_value, value=const_value)
        b4 = self.make_b4(b1_2, b2_2)

        self.assertNotEqual(b3, b4)
 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_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_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_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_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_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_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_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_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_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_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 make_b4(self, *args, **kwargs):
        def b_callback(a, b):
            return a + b + 0

        return PyConstBody(b_callback, value=None, *args, **kwargs)
 def test_eq_const_value(self):
     const_value = 7
     b1 = PyConstBody(lambda: const_value, value=const_value)
     b2 = PyConstBody(lambda: const_value, value=const_value)
     self.assertEqual(b1, b2)
 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()
 def test_neq_const_value_diff(self):
     const_value = 7
     const_value_2 = 8
     b1 = PyConstBody(lambda: const_value, value=const_value)
     b2 = PyConstBody(lambda: const_value_2, value=const_value_2)
     self.assertNotEqual(b1, b2)