def test_multi_exception(self): ctx = {} b = Block(block2) try: b.execute(ctx, continue_on_errors=True) assert False #We should have thrown except Exception, e: assert isinstance(e, CompositeException) assert len(e.exceptions) == 2
def test_single_exception(self): ctx = dict(raises_valuerror=raises_valuerror) b = Block(block) try: b.execute(ctx, continue_on_errors=True) assert False #We should have thrown except Exception, e: assert isinstance(e, ValueError) assert ctx.has_key('d')
def test_function_kwargs_args(self): code = "a = 1.0\n" \ "def test_func(c, d):\n" \ " e = c + 4\n" \ " f = d + 4\n" \ " return e*f\n" \ "m = test_func(d=a, c=b)" def test_raises(code): block = Block(code) try: import nose except: assert (False) raise nose.SkipTest( "inputs do not get mapped correctly, but we need keyword support for decorators" ) self.assertRaises(ValueError, test_raises, code) # keywords might be supported in the future, just not yet if (True): block = Block(code) self.assertEqual(len(block.sub_blocks), 3) self.assertEqual(block.inputs, set(['b', 'test_func'])) self.assertEqual(block.all_outputs, set(['a', 'm'])) self.assertEqual(block.conditional_outputs, set([])) self.assertEqual(block.outputs, set(['a', 'm']))
def test_function_default_args(self): code = "a = 1.0\n" \ "def test_func(c, d=1):\n" \ " e = c + 4\n" \ " f = d + 4\n" \ " return e*f\n" \ "m = test_func(b)" block = Block(code) self.assertEqual(len(block.sub_blocks), 3) self.assertEqual(block.inputs, set(['b'])) self.assertEqual(block.all_outputs, set(['a', 'm', 'test_func'])) self.assertEqual(block.conditional_outputs, set([])) self.assertEqual(block.outputs, set(['a', 'm', 'test_func']))
def test_raises(code): block = Block(code)
def _code_changed(self, new): self._block = Block(new)