예제 #1
0
    def test_htmlhelp(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        mg = MagicFile()
        mg.add_context({
            "file_tail": file_tail,
            "Database": Database,
            "text": 3
        })
        cmd = "-np -f rawhtml file_tail"
        res = mg.hhelp(cmd)
        assert "<p>extracts the first nbline of a file " in res
        res = mg.hhelp("-np -f rst file_tail")
        assert ":param      threshold:" in res
        res = mg.hhelp("-np -f rawhtml Database")
        assert "SQL file which can be empty or not," in res
        doc = docstring2html(Database.__init__, format="rawhtml")
        assert "it can also contain several files separated by" in doc
        fLOG("----------")
        res = mg.hhelp("-np -f rst Database.__init__")
        assert "it can also contain several files separated by" in res
        res = mg.hhelp("Database.__init__")
        assert res is not None
        res = mg.hhelp("-np -f text Database.__init__")
        assert "it can also contain several files separated by" in res
        assert "@param" in res
예제 #2
0
    def test_htmlhelp(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        mg = MagicFile()
        mg.add_context(
            {"file_tail": file_tail, "Database": Database, "text": 3})
        cmd = "-np -f rawhtml file_tail"
        res = mg.hhelp(cmd)
        assert "<p>extracts the first nbline of a file " in res
        res = mg.hhelp("-np -f rst file_tail")
        assert ":param      threshold:" in res
        res = mg.hhelp("-np -f rawhtml Database")
        assert "SQL file which can be empty or not," in res
        doc = docstring2html(Database.__init__, format="rawhtml")
        assert "it can also contain several files separated by" in doc
        fLOG("----------")
        res = mg.hhelp("-np -f rst Database.__init__")
        assert "it can also contain several files separated by" in res
        res = mg.hhelp("Database.__init__")
        assert res is not None
        res = mg.hhelp("-np -f text Database.__init__")
        assert "it can also contain several files separated by" in res
        assert "@param" in res
예제 #3
0
 def test_grep(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     fp = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data",
                       "Exportutf8.txt")
     mg = MagicFile()
     fLOG("--", fp)
     res = mg.grep("{0} .*6.* -n 3 -r".format(fp))
     fLOG("*****", res)
     self.assertEqual(res.strip("\n"), "1.2	3.4	5.6".strip("\n"))
예제 #4
0
    def test_textdiff(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        from IPython.core.display import Javascript
        mg = MagicFile()
        mg.add_context(
            {"f1": "STRING1\nSTRING2", "f2": "STRING1\nSTRING3"})
        cmd = "f1 f2"
        res = mg.textdiff(cmd)
        assert isinstance(res, Javascript)
예제 #5
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
예제 #6
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
예제 #7
0
 def test_grep(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     fp = os.path.join(
         os.path.dirname(
             os.path.abspath(__file__)),
         "data",
         "Exportutf8.txt")
     mg = MagicFile()
     fLOG("--", fp)
     res = mg.grep("{0} .*6.* -n 3 -r".format(fp))
     fLOG("*****", res)
     self.assertEqual(res.strip("\n"), "1.2	3.4	5.6".strip("\n"))
예제 #8
0
 def test_files(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     path = os.path.abspath(os.path.dirname(__file__))
     mg = MagicFile()
     cmd = path + " -f .*[.]py"
     fLOG("**", cmd)
     res = mg.lsr(cmd)
     fLOG(res)
     if len(res) == 0:
         raise FileNotFoundError("cmd: " + cmd)
     res = mg.lsr("")
     fLOG(res)
     assert len(res) > 0
예제 #9
0
 def test_files(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     path = os.path.abspath(os.path.dirname(__file__))
     mg = MagicFile()
     cmd = path + " -f .*[.]py"
     fLOG("**", cmd)
     res = mg.lsr(cmd)
     fLOG(res)
     if len(res) == 0:
         raise FileNotFoundError("cmd: " + cmd)
     res = mg.lsr("")
     fLOG(res)
     assert len(res) > 0
예제 #10
0
 def test_tail(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     fp = os.path.abspath(__file__)
     mg = MagicFile()
     fLOG("--", fp)
     res = mg.tail("{0} -n 3".format(fp))
     fLOG("*****", res)
     assert "unittest.main" in res.data
     res = mg.tail("{0} --n 3 -e ascii".format(fp))
     res = mg.tail("{0} --n 3 -e utf8".format(fp))
     res = file_tail(fp, threshold=300, nbline=3)
     res = [_ for _ in res if len(_) > 0]
     fLOG("#####", res)
     if "unittest.main" not in res[-2]:
         raise Exception("unittest.main not in " + str(res[-2]))
예제 #11
0
    def test_files_compress(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        this = os.path.abspath(__file__)
        temp = get_temp_folder(__file__, "temp_compress")
        dest = os.path.join(temp, "temp_this.zip")

        mg = MagicFile()
        cmd = "dest [this]"
        fLOG("**", cmd)
        assert not os.path.exists(dest)
        mg.add_context({"this": this, "dest": dest})
        res = mg.compress(cmd)
        fLOG(res)
        assert os.path.exists(dest)
        assert res == 1
예제 #12
0
 def test_tail(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     fp = os.path.abspath(__file__)
     mg = MagicFile()
     fLOG("--", fp)
     res = mg.tail("{0} -n 3".format(fp))
     fLOG("*****", res)
     assert "unittest.main" in res.data
     res = mg.tail("{0} --n 3 -e ascii".format(fp))
     res = mg.tail("{0} --n 3 -e utf8".format(fp))
     res = file_tail(fp, threshold=300, nbline=3)
     res = [_ for _ in res if len(_) > 0]
     fLOG("#####", res)
     if "unittest.main" not in res[-1]:
         raise Exception("unittest.main not in " + str(res[-1]))
예제 #13
0
 def test_head(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     fp = os.path.abspath(__file__)
     mg = MagicFile()
     fLOG("--", fp)
     res = mg.head("{0} -n 3".format(fp))
     fLOG("*****", res)
     assert "test log" in res.data
     res = mg.head("{0} --n 3 -e ascii".format(fp))
     resr = mg.head("{0} --n 3 -e utf8 --raw".format(fp))
     fLOG(resr)
     assert resr != res
     assert "<" not in resr
     assert "@brief" in resr
     assert "usage" not in resr
     assert not isinstance(res, str)
예제 #14
0
 def test_head(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     fp = os.path.abspath(__file__)
     mg = MagicFile()
     fLOG("--", fp)
     res = mg.head("{0} -n 3".format(fp))
     fLOG("*****", res)
     assert "test log" in res.data
     res = mg.head("{0} --n 3 -e ascii".format(fp))
     resr = mg.head("{0} --n 3 -e utf8 --raw".format(fp))
     fLOG(resr)
     assert resr != res
     assert "<" not in resr
     assert "@brief" in resr
     assert "usage" not in resr
     assert not isinstance(res, str)
예제 #15
0
    def test_head2(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        fp = os.path.join(
            os.path.dirname(
                os.path.abspath(__file__)),
            "data",
            "Exportutf8.txt")
        mg = MagicFile()
        fLOG("--", fp)
        res = mg.head("{0} -n 3".format(fp))
        fLOG("*****", res)
        res = mg.head("{0} -n=3".format(fp))
        fLOG("*****", res)
        res = mg.head("{0}".format(fp))
        fLOG("*****", res)
        assert "9.0" in res.data
        res = mg.head("{0} --n 3 -e utf8".format(fp))

        try:
            res = mg.head("Exportutf8.txt")
        except FileNotFoundError:
            pass
예제 #16
0
    def test_head2(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")
        fp = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data",
                          "Exportutf8.txt")
        mg = MagicFile()
        fLOG("--", fp)
        res = mg.head("{0} -n 3".format(fp))
        fLOG("*****", res)
        res = mg.head("{0} -n=3".format(fp))
        fLOG("*****", res)
        res = mg.head("{0}".format(fp))
        fLOG("*****", res)
        assert "9.0" in res.data
        res = mg.head("{0} --n 3 -e utf8".format(fp))

        try:
            res = mg.head("Exportutf8.txt")
        except FileNotFoundError:
            pass