Exemple #1
0
    def run_in_byterun(self, code):
        real_stdout = sys.stdout

        # Run the code through our VM.

        vm_stdout = six.StringIO()
        if CAPTURE_STDOUT:              # pragma: no branch
            sys.stdout = vm_stdout
        vm = VirtualMachine()

        vm_value = vm_exc = None
        try:
            vm_value = vm.run_code(code)
        except VirtualMachineError:         # pragma: no cover
            # If the VM code raises an error, show it.
            raise
        except AssertionError:              # pragma: no cover
            # If test code fails an assert, show it.
            raise
        except Exception as e:
            # Otherwise, keep the exception for comparison later.
            if not CAPTURE_EXCEPTION:       # pragma: no cover
                raise
            vm_exc = e
        finally:
            sys.stdout = real_stdout
            real_stdout.write("-- stdout ----------\n")
            real_stdout.write(vm_stdout.getvalue())

        return vm_value, vm_exc, vm_stdout
Exemple #2
0
    def run_in_byterun(self, code):
        real_stdout = sys.stdout

        # Run the code through our VM.

        vm_stdout = six.StringIO()
        if CAPTURE_STDOUT:  # pragma: no branch
            sys.stdout = vm_stdout
        vm = VirtualMachine()

        vm_value = vm_exc = None
        try:
            vm_value = vm.run_code(code)
        except VirtualMachineError:  # pragma: no cover
            # If the VM code raises an error, show it.
            raise
        except AssertionError:  # pragma: no cover
            # If test code fails an assert, show it.
            raise
        except Exception as e:
            # Otherwise, keep the exception for comparison later.
            if not CAPTURE_EXCEPTION:  # pragma: no cover
                raise
            vm_exc = e
        finally:
            sys.stdout = real_stdout
            real_stdout.write("-- stdout ----------\n")
            real_stdout.write(vm_stdout.getvalue())

        return vm_value, vm_exc, vm_stdout
Exemple #3
0
    def assert_ok(self, code, raises=None):
        """Run `code` in our VM and in real Python: they behave the same."""

        code = textwrap.dedent(code)
        code = compile(code, "<%s>" % self.id(), "exec", 0, 1)

        # Print the disassembly so we'll see it if the test fails.
        # dis_code(code)

        real_stdout = sys.stdout

        # Run the code through our VM.

        vm_stdout = six.StringIO()
        if CAPTURE_STDOUT:  # pragma: no branch
            sys.stdout = vm_stdout
        vm = VirtualMachine()

        vm_value = vm_exc = None
        try:
            vm_value = vm.run_code(code)
        except VirtualMachineError:  # pragma: no cover
            # If the VM code raises an error, show it.
            raise
        except AssertionError:  # pragma: no cover
            # If test code fails an assert, show it.
            raise
        except Exception as e:
            # Otherwise, keep the exception for comparison later.
            if not CAPTURE_EXCEPTION:  # pragma: no cover
                raise
            vm_exc = e
        finally:
            vm_stdout.flush()
            real_stdout.write("-- stdout ----------\n")
            real_stdout.write(vm_stdout.getvalue())

        # Run the code through the real Python interpreter, for comparison.

        py_stdout = six.StringIO()
        sys.stdout = py_stdout

        py_value = py_exc = None
        globs = {}
        try:
            py_value = eval(code, globs, globs)
        except AssertionError:  # pragma: no cover
            raise
        except Exception as e:
            py_exc = e

        sys.stdout = real_stdout

        # self.assert_same_exception(vm_exc, py_exc) #TODO: redo
        self.assertEqual(vm_stdout.getvalue(), py_stdout.getvalue())
        self.assertEqual(vm_value, py_value)
        if raises:
            self.assertIsInstance(vm_exc, raises)
        else:
            self.assertIsNone(vm_exc)
Exemple #4
0
    def assert_ok(self, code, raises=None):
        """Run `code` in the VM, and in the real Python, and see that they behave the same."""

        code = textwrap.dedent(code)
        code = compile(code, "<%s>" % self.id(), "exec")

        # Print the disassembly so we'll see it if the test fails.
        dis_code(code)

        real_stdout = sys.stdout

        # Run the code through our VM.

        vm_stdout = six.StringIO()
        if CAPTURE_STDOUT:              # pragma: no branch
            sys.stdout = vm_stdout
        vm = VirtualMachine()

        vm_value = vm_exc = None
        try:
            vm_value = vm.run_code(code)
        except VirtualMachineError:         # pragma: no cover
            # If the VM code raises an error, show it.
            raise
        except AssertionError:              # pragma: no cover
            # If test code fails an assert, show it.
            raise
        except Exception as e:
            # Otherwise, keep the exception for comparison later.
            if not CAPTURE_EXCEPTION:       # pragma: no cover
                raise
            vm_exc = e
        finally:
            real_stdout.write("-- stdout ----------\n")
            real_stdout.write(vm_stdout.getvalue())

        # Run the code through the real Python interpreter, for comparison.

        py_stdout = six.StringIO()
        sys.stdout = py_stdout

        py_value = py_exc = None
        globs = {}
        try:
            py_value = eval(code, globs, globs)
        except AssertionError:              # pragma: no cover
            raise
        except Exception as e:
            py_exc = e

        sys.stdout = real_stdout

        self.assert_same_exception(vm_exc, py_exc)
        self.assertEqual(vm_stdout.getvalue(), py_stdout.getvalue())
        self.assertEqual(vm_value, py_value)
        if raises:
            self.assertIsInstance(vm_exc, raises)
        else:
            self.assertIsNone(vm_exc)
Exemple #5
0
    def Analisis(self):
        lab = []
        Unidades = []
        f = open(self.pasa.frames[VentanaIndividual].nombre, 'r')
        mensaje = f.read()

        code = mensaje
        f.close()

        code = textwrap.dedent(code)
        code = compile(code, "<%s>" % id(code), "exec", 0, 1)
        dis_code(code)
        vm_stdout = six.StringIO()
        vm = VirtualMachine()
        vm_value = self.vm_exc = None
        vm_value = vm.run_code(code)

        for i in vm.opera.keys():
            lab.append(i[0] + "_" + str(i[1])[7:10] + "_" + str(i[2])[7:10])

        labels = lab
        self.Operaciones = lab
        self.OperacionesF = lab
        self.Valores = vm.opera.values()
        self.ValoresF = vm.opera.values()
        values = vm.opera.values()
        self.xList = [1, 2, 3, 4, 5]
        self.yList = values
        for archivo in Procesadores.Archivos_csv:
            Unidades = self.SacarCiclosDeReloj(archivo, vm.opera.keys())
            aux = []
            cont = 0
            for a in self.ValoresF:
                aux.append(a * int(Unidades[cont]))
                cont += 1

            self.CiclosDeReloj[archivo] = aux

        "Recorre los tipos de operaciones y seleccionas los que luego deseas"
        app.frames[VentanaOperaciones2].Muestra_Operaciones()

        if self.Muestrafichero == 0:
            self.Muestrafichero = 1
            self.canvas.show()
            self.canvas.get_tk_widget().pack(side=Tkinter.BOTTOM,
                                             fill=Tkinter.BOTH,
                                             expand=True)

            toolbar = NavigationToolbar2Tk(self.canvas, self)
            toolbar.update()
            self.canvas._tkcanvas.pack(side=Tkinter.TOP,
                                       fill=Tkinter.BOTH,
                                       expand=True)
Exemple #6
0
    def V_analisis(self):
        "Parametro=0"
        self.nombres = []
        self.Value = {}
        self.Operaciones = {}
        self.CiclosDeReloj = {}
        self.OperacionesTotales = []
        Cuidado = 0
        Barrera = 0
        self.AnalisisP = 0
        self.NombreP = []
        ArchivosCorrectos = 0
        self.nombres = tkFileDialog.askopenfilenames(
            initialdir="/",
            title="Select file",
            filetypes=(("jpeg files", "*.jpg"), ("all files", "*.*")))
        for comprobacion in self.nombres:
            "Barrabaja=0"

            cerrado = 0
            parametro = 0
            for c in range(comprobacion.__len__()):
                if comprobacion[comprobacion.__len__() - c -
                                1] == "_" and Cuidado < 2 and cerrado < 1:
                    Cuidado = Cuidado + 1
                if comprobacion[comprobacion.__len__() - c - 1] == "/":
                    cerrado = 1
                if Cuidado == 1 and comprobacion[comprobacion.__len__() - c -
                                                 1] == "P":
                    parametro = 1

            self.NombreP.append(comprobacion[comprobacion.__len__() - 1])

            if parametro != 1 or Cuidado != 2:
                Barrera = 1

            if comprobacion[len(comprobacion) - 1] != "y" or comprobacion[
                    len(comprobacion) - 2] != "p" and self.comprobacion[
                        len(comprobacion) - 3] != ".":
                ArchivosCorrectos = 1

        if ArchivosCorrectos == 1:
            tkMessageBox.showerror(
                "Error", "El fichero seleccionado no es de tipo .py")
        elif self.nombres.__len__() == 1:
            tkMessageBox.showerror("Error", "Solo has seleccionado 1 fichero")
        elif self.nombres.__len__() == 0:
            tkMessageBox.showwarning()("Error",
                                       "No se ha seleccionado ningun fichero")
        else:
            if self.nombres.__len__() <= 10:
                if self.Boton1 == 0:
                    if self.Boton2 == 1:
                        self.btn3.pack_forget()
                    self.btn3 = Tkinter.Button(self,
                                               text="Comparison of files",
                                               command=lambda: self.pasa.
                                               show_frame(VentanaComparacion))

                    self.btn3.pack()
                    self.Boton1 = 1
                    self.Boton2 = 0
            else:
                if self.Boton2 == 0:
                    if self.Boton1 == 1:
                        self.btn3.pack_forget()
                    self.btn3 = Tkinter.Button(self,
                                               text="Comparison of files",
                                               command=lambda: self.pasa.
                                               show_frame(VentanaComparacion2))

                    self.btn3.pack()
                    self.Boton1 = 0
                    self.Boton2 = 1

                if Barrera == 0:
                    self.AnalisisP = 1

            Checkbutto = []
            Unidades = []
            posi = 190
            enumera = 1

            for ficherin in self.nombres:
                lab = []
                CiclosDeReloj_dentro = {}
                f = open(ficherin, 'r')
                mensaje = f.read()

                CAPTURE_EXCEPTION = 1

                code = mensaje
                f.close()

                code = textwrap.dedent(code)
                code = compile(code, "<%s>" % id(code), "exec", 0, 1)
                dis_code(code)
                vm_stdout = six.StringIO()
                vm = VirtualMachine()
                vm_value = self.vm_exc = None
                vm_value = vm.run_code(code)

                for i in vm.opera.keys():
                    lab.append(i[0] + "_" + str(i[1])[7:10] + "_" +
                               str(i[2])[7:10])

                labels = lab
                self.Operaciones[enumera] = lab
                "self.OperacionesF=lab"
                self.Value[enumera] = vm.opera.values()
                "self.ValoresF=vm.opera.values()"
                for oper in lab:
                    if oper not in self.OperacionesTotales:
                        self.OperacionesTotales.append(oper)

                for archivo in Procesadores.Archivos_csv:
                    Unidades = self.SacarCiclosDeReloj(archivo,
                                                       vm.opera.keys())
                    aux = []
                    cont = 0
                    for a in self.Value[enumera]:
                        aux.append(a * int(Unidades[cont]))
                        cont += 1

                    CiclosDeReloj_dentro[archivo] = aux
                self.CiclosDeReloj[enumera] = CiclosDeReloj_dentro
                enumera = enumera + 1
            app.frames[VentanaComparacion].Comba[
                "values"] = self.OperacionesTotales
            app.frames[VentanaComparacion2].Comba[
                "values"] = self.OperacionesTotales

            tkMessageBox.showinfo("Exito", "El analisis ya ha sido realizado")
            "app.frames[VentanaComparacion].Comba.pack()"
            app.frames[VentanaComparacion].btn2.pack()
            "app.frames[VentanaComparacion2].Comba.pack()"
            app.frames[VentanaComparacion2].btn2.pack()
            "app.frames[VentanaComparacion].Muestra_Botones()"
            "app.frames[VentanaComparacion2].Muestra_Botones()"
            app.frames[VentanaOperaciones].Muestra_Operaciones()
            app.frames[VentanaOperaciones3].Muestra_Operaciones()

            for marcar in range(
                    0, app.frames[VentanaOperaciones].VBoton.__len__()):
                "app.frames[VentanaComparacion].Checkbutto[marcar].invoke()"
                "app.frames[VentanaComparacion2].Checkbutto[marcar].invoke()"
                app.frames[VentanaOperaciones].Checkbutto[marcar].invoke()
                app.frames[VentanaOperaciones3].Checkbutto[marcar].invoke()