def test_invalid(self): the_ir = get_func_ir(lift_invalid) with self.assertRaises(errors.CompilerError) as raises: with_lifting( the_ir, self.typingctx, self.targetctx, self.flags, locals={}, ) self.assertIn( "Unsupported context manager in use", str(raises.exception), )
def test_undefined_global(self): the_ir = get_func_ir(lift_undefiend) with self.assertRaises(errors.CompilerError) as raises: with_lifting( the_ir, self.typingctx, self.targetctx, self.flags, locals={}, ) self.assertIn( "Undefined variable used as context manager", str(raises.exception), )
def check_extracted_with(self, func, expect_count, expected_stdout): the_ir = get_func_ir(func) new_ir, extracted = with_lifting( the_ir, self.typingctx, self.targetctx, self.flags, locals={}, ) self.assertEqual(len(extracted), expect_count) cres = self.compile_ir(new_ir) with captured_stdout() as out: cres.entry_point() self.assertEqual(out.getvalue(), expected_stdout)
def stage_frontend_withlift(self): """ Extract with-contexts """ main, withs = transforms.with_lifting( func_ir=self.func_ir, typingctx=self.typingctx, targetctx=self.targetctx, flags=self.flags, locals=self.locals, ) if withs: cres = compile_ir(self.typingctx, self.targetctx, main, self.args, self.return_type, self.flags, self.locals, lifted=tuple(withs), lifted_from=None, pipeline_class=type(self)) raise _EarlyPipelineCompletion(cres)
def stage_frontend_withlift(self): """ Extract with-contexts """ main, withs = transforms.with_lifting( func_ir=self.func_ir, typingctx=self.typingctx, targetctx=self.targetctx, flags=self.flags, locals=self.locals, ) if withs: cres = compile_ir(self.typingctx, self.targetctx, main, self.args, self.return_type, self.flags, self.locals, lifted=tuple(withs), lifted_from=None, pipeline_class=type(self)) raise _EarlyPipelineCompletion(cres)