Esempio n. 1
0
def _multiruntest(suite):
    stream = StringIO()
    with contextlib.closing(stream):
        runner = unittest.TextTestRunner(descriptions=False, verbosity=3,
                                         buffer=True, stream=stream)
        result = runner.run(suite)
        return result.wasSuccessful(), stream.getvalue()
Esempio n. 2
0
 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()))
Esempio n. 3
0
 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())
     )
Esempio n. 4
0
def captured_logs(l):
    try:
        buffer = StringIO()
        handler = logging.StreamHandler(buffer)
        l.addHandler(handler)
        yield buffer
    finally:
        l.removeHandler(handler)
Esempio n. 5
0
    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])
Esempio n. 6
0
    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)
Esempio n. 7
0
    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)
Esempio n. 8
0
    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])
Esempio n. 9
0
 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())
Esempio n. 10
0
class CapturedTrace:
    """Capture the trace temporarily for validation."""

    def __init__(self):
        self.buffer = StringIO()
        self.handler = logging.StreamHandler(self.buffer)
    def __enter__(self):
        self._handlers = logger.handlers
        self.buffer = StringIO()
        logger.handlers = [logging.StreamHandler(self.buffer)]
    def __exit__(self, type, value, traceback):
        logger.handlers = self._handlers
    def getvalue(self):

        # Depending on how the tests are run, object names may be
        # qualified by their containing module.
        # Remove that to make the trace output independent from the testing mode.
        log = self.buffer.getvalue()
        log = log.replace(__name__ + '.','')
        return log
Esempio n. 11
0
 def __enter__(self):
     self._handlers = logger.handlers
     self.buffer = StringIO()
     logger.handlers = [logging.StreamHandler(self.buffer)]
Esempio n. 12
0
 def __init__(self):
     self.buffer = StringIO()
     self.handler = logging.StreamHandler(self.buffer)