Beispiel #1
0
    def test_magic_command_jython(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        if "travis" in sys.executable:
            return

        temp = get_temp_folder(__file__, "temp_magic_command_jython")

        download_java_standalone()
        assert is_java_installed()

        script = """
                    import random

                    @schemaFunction("rsSchema")
                    def rsSchema(input):
                        return input

                    @outputSchemaFunction("rsSchema")
                    def reservoir_sampling(ensemble):
                        ensemble = eval(ensemble)
                        k = 10
                        N = len(ensemble)
                        echantillon = []
                        for i, e in enumerate(ensemble):
                            if len(echantillon) < k:
                                echantillon.append(e)
                            else:
                                j = random.randint(0, i)
                                if j < k:
                                    echantillon[j] = e
                        return echantillon
                    """.replace("                    ", "")

        dest = os.path.join(temp, "script.py")
        mg = MagicFile()
        cmd = dest
        fLOG("**", cmd)
        res = mg.PYTHON(cmd, cell=script)
        fLOG(res)
        assert os.path.exists(dest)

        mg = MagicAzure()
        cmd = dest + " reservoir_sampling"
        cell = '{(100001,"AAAAAA"),(99999,"D99999"),(99998,"C99998")}\n'
        res = mg.jython(cmd, cell=cell)
        fLOG(res)
        assert res
    def test_magic_command_jython(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        if "travis" in sys.executable:
            return

        temp = get_temp_folder(__file__, "temp_magic_command_jython")

        download_java_standalone()
        assert is_java_installed()

        script = """
                    import random

                    @schemaFunction("rsSchema")
                    def rsSchema(input):
                        return input

                    @outputSchemaFunction("rsSchema")
                    def reservoir_sampling(ensemble):
                        ensemble = eval(ensemble)
                        k = 10
                        N = len(ensemble)
                        echantillon = []
                        for i, e in enumerate(ensemble):
                            if len(echantillon) < k:
                                echantillon.append(e)
                            else:
                                j = random.randint(0, i)
                                if j < k:
                                    echantillon[j] = e
                        return echantillon
                    """.replace("                    ", "")

        dest = os.path.join(temp, "script.py")
        mg = MagicFile()
        cmd = dest
        fLOG("**", cmd)
        res = mg.PYTHON(cmd, cell=script)
        fLOG(res)
        assert os.path.exists(dest)

        mg = MagicAzure()
        cmd = dest + " reservoir_sampling"
        cell = '{(100001,"AAAAAA"),(99999,"D99999"),(99998,"C99998")}\n'
        res = mg.jython(cmd, cell=cell)
        fLOG(res)
        assert res