Beispiel #1
0
    def test_pycc_pymodule(self):
        unset_macosx_deployment_target()

        modulename = os.path.join(base_path, 'compile_with_pycc')
        tmpdir = tempfile.gettempdir()
        print('tmpdir: %s' % tmpdir)
        out_modulename = (os.path.join(tmpdir, 'compiled_with_pycc')
                          + find_shared_ending())
        main(args=['--python', '-o', out_modulename, modulename + '.py'])

        sys.path.append(tmpdir)
        try:
            import compiled_with_pycc as lib
            try:
                res = lib.mult(123, 321)
                print('lib.mult(123, 321) = %f' % res)
                assert res == 123 * 321

                res = lib.multf(987, 321)
                print('lib.multf(987, 321) = %f' % res)
                assert res == 987 * 321
            finally:
                del lib
        finally:
            if os.path.exists(out_modulename):
                os.unlink(out_modulename)
Beispiel #2
0
    def test_pycc_pymodule(self):
        """
        Test creating a CPython extension module using pycc.
        """
        unset_macosx_deployment_target()

        modulename = os.path.join(base_path, 'compile_with_pycc')
        tmpdir = tempfile.gettempdir()
        out_modulename = (os.path.join(tmpdir, 'compiled_with_pycc')
                          + find_shared_ending())

        def _cleanup():
            if os.path.exists(out_modulename):
                os.unlink(out_modulename)
        _cleanup()
        self.addCleanup(_cleanup)

        main(args=['--python', '-o', out_modulename, modulename + '.py'])

        sys.path.append(tmpdir)
        try:
            import compiled_with_pycc as lib
            try:
                res = lib.mult(123, 321)
                assert res == 123 * 321

                res = lib.multf(987, 321)
                assert res == 987 * 321
            finally:
                del lib
        finally:
            sys.path.remove(tmpdir)
Beispiel #3
0
    def test_pycc_pymodule(self):
        unset_macosx_deployment_target()

        modulename = os.path.join(base_path, 'compile_with_pycc')
        tmpdir = tempfile.gettempdir()
        print('tmpdir: %s' % tmpdir)
        out_modulename = (os.path.join(tmpdir, 'compiled_with_pycc') +
                          find_shared_ending())
        main(args=['--python', '-o', out_modulename, modulename + '.py'])

        sys.path.append(tmpdir)
        try:
            import compiled_with_pycc as lib
            try:
                res = lib.mult(123, 321)
                print('lib.mult(123, 321) = %f' % res)
                assert res == 123 * 321

                res = lib.multf(987, 321)
                print('lib.multf(987, 321) = %f' % res)
                assert res == 987 * 321
            finally:
                del lib
        finally:
            if os.path.exists(out_modulename):
                os.unlink(out_modulename)
Beispiel #4
0
def test_pycc():
    modulename = os.path.join(base_path, "compile_with_pycc")
    cdll_modulename = modulename + find_shared_ending()
    if os.path.exists(cdll_modulename):
        os.unlink(cdll_modulename)

    main(args=[modulename + ".py"])
    lib = CDLL(cdll_modulename)

    try:
        lib.mult.argtypes = [c_double, c_double]
        lib.mult.restype = c_double

        lib.multf.argtypes = [c_float, c_float]
        lib.multf.restype = c_float

        res = lib.mult(123, 321)
        print("lib.mult(123, 321) = %f", res)
        assert res == 123 * 321

        res = lib.multf(987, 321)
        print("lib.multf(987, 321) = %f" % res)
        assert res == 987 * 321
    finally:
        del lib
        if os.path.exists(cdll_modulename):
            os.unlink(cdll_modulename)

    tmpdir = tempfile.gettempdir()
    print("tmpdir: %s" % tmpdir)
    out_modulename = os.path.join(tmpdir, "compiled_with_pycc") + find_shared_ending()
    main(args=["--python", "-o", out_modulename, modulename + ".py"])

    sys.path.append(tmpdir)
    try:
        import compiled_with_pycc as lib

        try:
            res = lib.mult(123, 321)
            print("lib.mult(123, 321) = %f" % res)
            assert res == 123 * 321

            res = lib.multf(987, 321)
            print("lib.multf(987, 321) = %f" % res)
            assert res == 987 * 321
        finally:
            del lib
    finally:
        if os.path.exists(out_modulename):
            os.unlink(out_modulename)
Beispiel #5
0
def test_pycc():
    modulename = os.path.join(base_path, 'compile_with_pycc')
    cdll_modulename = modulename + find_shared_ending()
    if os.path.exists(cdll_modulename):
        os.unlink(cdll_modulename)

    main(args=[modulename + '.py'])
    lib = CDLL(cdll_modulename)

    try:
        lib.mult.argtypes = [c_double, c_double]
        lib.mult.restype = c_double

        lib.multf.argtypes = [c_float, c_float]
        lib.multf.restype = c_float

        res = lib.mult(123, 321)
        print('lib.mult(123, 321) = %f', res)
        assert res == 123 * 321

        res = lib.multf(987, 321)
        print('lib.multf(987, 321) = %f' % res)
        assert res == 987 * 321
    finally:
        del lib
        if os.path.exists(cdll_modulename):
            os.unlink(cdll_modulename)

    tmpdir = tempfile.gettempdir()
    print('tmpdir: %s' % tmpdir)
    out_modulename = (os.path.join(tmpdir, 'compiled_with_pycc')
                      + find_shared_ending())
    main(args=['--python', '-o', out_modulename, modulename + '.py'])

    sys.path.append(tmpdir)
    try:
        import compiled_with_pycc as lib
        try:
            res = lib.mult(123, 321)
            print('lib.mult(123, 321) = %f' % res)
            assert res == 123 * 321

            res = lib.multf(987, 321)
            print('lib.multf(987, 321) = %f' % res)
            assert res == 987 * 321
        finally:
            del lib
    finally:
        if os.path.exists(out_modulename):
            os.unlink(out_modulename)
Beispiel #6
0
    def test_pycc_pymodule(self):
        modulename = os.path.join(base_path, "compile_with_pycc")
        tmpdir = tempfile.gettempdir()
        print("tmpdir: %s" % tmpdir)
        out_modulename = os.path.join(tmpdir, "compiled_with_pycc") + find_shared_ending()
        main(args=["--python", "-o", out_modulename, modulename + ".py"])

        sys.path.append(tmpdir)
        try:
            import compiled_with_pycc as lib

            try:
                res = lib.mult(123, 321)
                print("lib.mult(123, 321) = %f" % res)
                assert res == 123 * 321

                res = lib.multf(987, 321)
                print("lib.multf(987, 321) = %f" % res)
                assert res == 987 * 321
            finally:
                del lib
        finally:
            if os.path.exists(out_modulename):
                os.unlink(out_modulename)
Beispiel #7
0
    del lib
    if os.path.exists(cdll_modulename):
        os.unlink(cdll_modulename)

modulename = os.path.join(base_path, 'compile_with_pycc')
tmpdir = tempfile.gettempdir()
print('tmpdir: %s' % tmpdir)
out_modulename = (os.path.join(tmpdir, 'compiled_with_pycc') +
                  find_shared_ending())

# Compile python module to python extension
main(args=['--python', '-o', out_modulename, modulename + '.py'])

# Load compiled extension and call mult function
sys.path.append(tmpdir)
try:
    import compiled_with_pycc as lib
    try:
        res = lib.mult(123, 321)
        print('lib.mult(123, 321) = %f' % res)
        assert res == 123 * 321

        res = lib.multf(987, 321)
        print('lib.multf(987, 321) = %f' % res)
        assert res == 987 * 321
    finally:
        del lib
finally:
    if os.path.exists(out_modulename):
        os.unlink(out_modulename)
Beispiel #8
0
        os.unlink(cdll_modulename)


modulename = os.path.join(base_path, 'compile_with_pycc')
tmpdir = tempfile.gettempdir()
print('tmpdir: %s' % tmpdir)
out_modulename = (os.path.join(tmpdir, 'compiled_with_pycc')
                  + find_shared_ending())

# Compile python module to python extension
main(args=['--python', '-o', out_modulename, modulename + '.py'])

# Load compiled extension and call mult function
sys.path.append(tmpdir)
try:
    import compiled_with_pycc as lib
    try:
        res = lib.mult(123, 321)
        print('lib.mult(123, 321) = %f' % res)
        assert res == 123 * 321

        res = lib.multf(987, 321)
        print('lib.multf(987, 321) = %f' % res)
        assert res == 987 * 321
    finally:
        del lib
finally:
    if os.path.exists(out_modulename):
        os.unlink(out_modulename)