def captured_logs(l): try: buffer = StringIO() handler = logging.StreamHandler(buffer) l.addHandler(handler) yield buffer finally: l.removeHandler(handler)
def check_ir_dump(self, pyfunc): interp = self.get_ir(pyfunc) out = StringIO() interp.dump(file=out) expected = textwrap.dedent(pyfunc.__doc__).strip().splitlines() got = out.getvalue().strip().splitlines() self.assertEqual(got, expected, "dump might need to be refreshed; here is the " "actual dump:\n%s\n" % (out.getvalue()))
def __call__(self, test): # Executed in child process kwargs = self.runner_args # Force recording of output in a buffer (it will be printed out # by the parent). kwargs['stream'] = StringIO() runner = self.runner_cls(**kwargs) result = runner._makeResult() # Avoid child tracebacks when Ctrl-C is pressed. signals.installHandler() signals.registerResult(result) result.failfast = runner.failfast result.buffer = runner.buffer with self.cleanup_object(test): test(result) # HACK as cStringIO.StringIO isn't picklable in 2.x result.stream = _FakeStringIO(result.stream.getvalue()) return _MinimalResult(result, test.id())
def test_polytyped(self): @cuda.jit def foo(x, y): pass foo(1, 1) foo(1.2, 2.4) file = StringIO() foo.inspect_types(file=file) typeanno = file.getvalue() file.close() # Signature in annotation self.assertIn("({0}, {0})".format(intp), typeanno) self.assertIn("(float64, float64)", typeanno) # Signature in LLVM dict llvmirs = foo.inspect_llvm() self.assertEqual( 2, len(llvmirs), ) self.assertIn((intp, intp), llvmirs) self.assertIn((float64, float64), llvmirs) # Function name in LLVM self.assertIn("foo", llvmirs[intp, intp]) self.assertIn("foo", llvmirs[float64, float64]) asmdict = foo.inspect_asm() # Signature in LLVM dict self.assertEqual( 2, len(asmdict), ) self.assertIn((intp, intp), asmdict) self.assertIn((float64, float64), asmdict) # NNVM inserted in PTX self.assertIn("foo", asmdict[intp, intp]) self.assertIn("foo", asmdict[float64, float64])
def test_monotyped(self): @cuda.jit("(float32, int32)") def foo(x, y): pass file = StringIO() foo.inspect_types(file=file) typeanno = file.getvalue() # Function name in annotation self.assertIn("foo", typeanno) # Signature in annotation self.assertIn("(float32, int32)", typeanno) file.close() # Function name in LLVM self.assertIn("foo", foo.inspect_llvm()) asm = foo.inspect_asm() # Function name in PTX self.assertIn("foo", asm) # NVVM inserted comments in PTX self.assertIn("Generated by NVIDIA NVVM Compiler", asm)
def __enter__(self): self._handlers = logger.handlers self.buffer = StringIO() logger.handlers = [logging.StreamHandler(self.buffer)]
def __init__(self): self.buffer = StringIO() self.handler = logging.StreamHandler(self.buffer)