Пример #1
0
    def test_write_compiled_module(self):
        space = self.space
        pathname = _testfilesource()
        os.chmod(pathname, 0777)
        stream = streamio.open_file_as_stream(pathname, "r")
        try:
            w_ret = importing.parse_source_module(space,
                                                  pathname,
                                                  stream.readall())
        finally:
            stream.close()
        pycode = w_ret
        assert type(pycode) is pypy.interpreter.pycode.PyCode

        cpathname = str(udir.join('cpathname.pyc'))
        mode = 0777
        mtime = 12345
        importing.write_compiled_module(space,
                                        pycode,
                                        cpathname,
                                        mode,
                                        mtime)

        # check
        ret = importing.check_compiled_module(space,
                                              cpathname,
                                              mtime)
        assert ret is not None
        ret.close()

        # Check that the executable bit was removed
        assert os.stat(cpathname).st_mode & 0111 == 0

        # read compiled module
        stream = streamio.open_file_as_stream(cpathname, "rb")
        try:
            stream.seek(8, 0)
            w_code = importing.read_compiled_module(space, cpathname,
                                                    stream.readall())
            pycode = w_code
        finally:
            stream.close()

        # check value of load
        w_dic = space.newdict()
        pycode.exec_code(space, w_dic, w_dic)
        w_ret = space.getitem(w_dic, space.wrap('x'))
        ret = space.int_w(w_ret)
        assert ret == 42
Пример #2
0
    def test_write_compiled_module(self):
        space = self.space
        pathname = _testfilesource()
        os.chmod(pathname, 0777)
        stream = streamio.open_file_as_stream(pathname, "r")
        try:
            w_ret = importing.parse_source_module(space,
                                                  pathname,
                                                  stream.readall())
        finally:
            stream.close()
        pycode = w_ret
        assert type(pycode) is pypy.interpreter.pycode.PyCode

        cpathname = str(udir.join('cpathname.pyc'))
        mode = 0777
        mtime = 12345
        importing.write_compiled_module(space,
                                        pycode,
                                        cpathname,
                                        mode,
                                        mtime)

        # check
        ret = importing.check_compiled_module(space,
                                              cpathname,
                                              mtime)
        assert ret is not None
        ret.close()

        # Check that the executable bit was removed
        assert os.stat(cpathname).st_mode & 0111 == 0

        # read compiled module
        stream = streamio.open_file_as_stream(cpathname, "rb")
        try:
            stream.seek(8, 0)
            w_code = importing.read_compiled_module(space, cpathname,
                                                    stream.readall())
            pycode = w_code
        finally:
            stream.close()

        # check value of load
        w_dic = space.newdict()
        pycode.exec_code(space, w_dic, w_dic)
        w_ret = space.getitem(w_dic, space.wrap('x'))
        ret = space.int_w(w_ret)
        assert ret == 42
Пример #3
0
 def test_parse_source_module(self):
     space = self.space
     pathname = _testfilesource()
     stream = streamio.open_file_as_stream(pathname, "r")
     try:
         w_ret = importing.parse_source_module(space, pathname, stream.readall())
     finally:
         stream.close()
     pycode = w_ret
     assert type(pycode) is pypy.interpreter.pycode.PyCode
     w_dic = space.newdict()
     pycode.exec_code(space, w_dic, w_dic)
     w_ret = space.getitem(w_dic, space.wrap("x"))
     ret = space.int_w(w_ret)
     assert ret == 42
Пример #4
0
 def test_parse_source_module(self):
     space = self.space
     pathname = _testfilesource()
     stream = streamio.open_file_as_stream(pathname, "r")
     try:
         w_ret = importing.parse_source_module(space, pathname,
                                               stream.readall())
     finally:
         stream.close()
     pycode = w_ret
     assert type(pycode) is pypy.interpreter.pycode.PyCode
     w_dic = space.newdict()
     pycode.exec_code(space, w_dic, w_dic)
     w_ret = space.getitem(w_dic, space.wrap('x'))
     ret = space.int_w(w_ret)
     assert ret == 42
Пример #5
0
 def test_read_compiled_module(self):
     space = self.space
     mtime = 12345
     co = compile("x = 42", "?", "exec")
     cpathname = _testfile(importing.get_pyc_magic(space), mtime, co)
     stream = streamio.open_file_as_stream(cpathname, "rb")
     try:
         stream.seek(8, 0)
         w_code = importing.read_compiled_module(space, cpathname, stream.readall())
         pycode = w_code
     finally:
         stream.close()
     assert type(pycode) is pypy.interpreter.pycode.PyCode
     w_dic = space.newdict()
     pycode.exec_code(space, w_dic, w_dic)
     w_ret = space.getitem(w_dic, space.wrap("x"))
     ret = space.int_w(w_ret)
     assert ret == 42
Пример #6
0
    def test_write_compiled_module(self):
        space = self.space
        pathname = _testfilesource()
        stream = streamio.open_file_as_stream(pathname, "r")
        try:
            w_ret = importing.parse_source_module(space,
                                                  pathname,
                                                  stream.readall())
        finally:
            stream.close()
        pycode = space.interpclass_w(w_ret)
        assert type(pycode) is pypy.interpreter.pycode.PyCode

        cpathname = str(udir.join('cpathname.pyc'))
        mtime = 12345
        importing.write_compiled_module(space,
                                        pycode,
                                        cpathname,
                                        mtime)

        # check
        pathname = str(udir.join('cpathname.py'))
        ret = importing.check_compiled_module(space,
                                              pathname,
                                              mtime,
                                              cpathname)
        assert ret == 1

        # read compile module
        stream = streamio.open_file_as_stream(cpathname, "r")
        try:
            stream.seek(8, 0)
            w_code = importing.read_compiled_module(space, cpathname,
                                                    stream.readall())
            pycode = space.interpclass_w(w_code)
        finally:
            stream.close()

        # check value of load
        w_dic = space.newdict()
        pycode.exec_code(space, w_dic, w_dic)
        w_ret = space.getitem(w_dic, space.wrap('x'))
        ret = space.int_w(w_ret)
        assert ret == 42
Пример #7
0
 def test_read_compiled_module(self):
     space = self.space
     mtime = 12345
     co = compile('x = 42', '?', 'exec')
     cpathname = _testfile(importing.get_pyc_magic(space), mtime, co)
     stream = streamio.open_file_as_stream(cpathname, "rb")
     try:
         stream.seek(8, 0)
         w_code = importing.read_compiled_module(
                 space, cpathname, stream.readall())
         pycode = space.interpclass_w(w_code)
     finally:
         stream.close()
     assert type(pycode) is pypy.interpreter.pycode.PyCode
     w_dic = space.newdict()
     pycode.exec_code(space, w_dic, w_dic)
     w_ret = space.getitem(w_dic, space.wrap('x'))
     ret = space.int_w(w_ret)
     assert ret == 42
Пример #8
0
    def test_write_compiled_module(self):
        space = self.space
        pathname = _testfilesource()
        stream = streamio.open_file_as_stream(pathname, "r")
        try:
            w_ret = importing.parse_source_module(space,
                                                  pathname,
                                                  stream.readall())
        finally:
            stream.close()
        pycode = space.interpclass_w(w_ret)
        assert type(pycode) is pypy.interpreter.pycode.PyCode

        cpathname = str(udir.join('cpathname.pyc'))
        mtime = 12345
        importing.write_compiled_module(space,
                                        pycode,
                                        cpathname,
                                        mtime)

        # check
        ret = importing.check_compiled_module(space,
                                              cpathname,
                                              mtime)
        assert ret is True

        # read compiled module
        stream = streamio.open_file_as_stream(cpathname, "rb")
        try:
            stream.seek(8, 0)
            w_code = importing.read_compiled_module(space, cpathname,
                                                    stream.readall())
            pycode = space.interpclass_w(w_code)
        finally:
            stream.close()

        # check value of load
        w_dic = space.newdict()
        pycode.exec_code(space, w_dic, w_dic)
        w_ret = space.getitem(w_dic, space.wrap('x'))
        ret = space.int_w(w_ret)
        assert ret == 42
Пример #9
0
 def test_read_compiled_module(self):
     space = self.space
     pathname = "whatever"
     mtime = 12345
     co = compile('x = 42', '?', 'exec')
     cpathname = _testfile(importing.get_pyc_magic(space), mtime, co)
     stream = streamio.open_file_as_stream(cpathname, "r")
     try:
         stream.seek(8, 0)
         w_code = importing.read_compiled_module(
                 space, cpathname, stream)
         pycode = space.interpclass_w(w_code)
     finally:
         stream.close()
     assert type(pycode) is pypy.interpreter.pycode.PyCode
     w_dic = space.newdict()
     pycode.exec_code(space, w_dic, w_dic)
     w_ret = space.getitem(w_dic, space.wrap('x'))
     ret = space.int_w(w_ret)
     assert ret == 42