Beispiel #1
0
    def test_sphinx_doc(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.split(__file__)[0]
        file = os.path.join(
            path,
            "..",
            "..",
            "src",
            "pyquickhelper",
            "helpgen",
            "utils_sphinx_doc.py")
        assert os.path.exists(file)

        with open(file, "r", encoding="utf8") as f:
            content = f.read()
        stats, newc = utils_sphinx_doc.migrating_doxygen_doc(content, file)
        snewc = newc[:len(newc) // 2]
        assert "pass" in newc
        assert ":param" in newc
        if "@param" in snewc:
            raise Exception(snewc)
        assert "docrows" in stats
Beispiel #2
0
 def test_guess_type(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     l = [
         '0002',
         '0003',
         '0001',
         '0',
         '0',
         '0',
         '0',
         '0',
         '',
         '0002',
         '0003',
         '0001',
         '0002',
         '0003',
         '0001',
         '0002',
         '0003',
         '0001',
         '0002',
         '0001',
         '0002',
         '0001']
     res = guess_type_list(l)
     fLOG(res)
     if res != (str  # unicode#
                , 8):
         raise Exception("different: {0}".format(res))
Beispiel #3
0
    def test_rst2html_png_bug(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        if is_travis_or_appveyor():
            # it requires latex
            return

        if sys.version_info[:2] <= (2, 7):
            # i don't want to fix it for Python 2.7
            return

        temp = get_temp_folder(__file__, "temp_rst2html_png_latex")
        rst = os.path.join(os.path.abspath(
            os.path.dirname(__file__)), "data", "puzzle_girafe.rst")
        with open(rst, "r", encoding="utf-8") as f:
            content = f.read()
        text = rst2html(content, fLOG=fLOG, outdir=temp,
                        imgmath_latex_preamble="""
                    \\newcommand{\\acc}[1]{\\left\\{#1\\right\\}}
                    \\newcommand{\\cro}[1]{\\left[#1\\right]}
                    \\newcommand{\\pa}[1]{\\left(#1\\right)}
                    \\newcommand{\\girafedec}[3]{ \\begin{array}{ccccc} #1 &=& #2 &+& #3 \\\\ a' &=& a &-& o  \\end{array}}
                    \\newcommand{\\vecteur}[2]{\\pa{#1,\\dots,#2}}
                    \\newcommand{\\R}[0]{\\mathbb{R}}
                    \\newcommand{\\N}[0]{\\mathbb{N}}
                    """)
        # fLOG(text)
        ji = os.path.join(temp, "out.html")
        with open(ji, "w", encoding="utf-8") as f:
            f.write(text)
Beispiel #4
0
    def test_post_parse_sn(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        directives.register_directive("sharenet", ShareNetDirective)
Beispiel #5
0
 def test_split_cmp_command(self) :
     fLOG (__file__, self._testMethodName, OutputPrint = __name__ == "__main__")
     assert split_cmp_command("ab cd ef") == ["ab", "cd", "ef"]
     assert split_cmp_command('ab "cd ef"') == ["ab", 'cd ef']
     assert split_cmp_command('"ab cd" ef') == ["ab cd", "ef"]
     assert split_cmp_command('"ab" cd ef') == ["ab", "cd", "ef"]
     assert split_cmp_command('"ab cd ef"') == ["ab cd ef"]
 def test_NbImage(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     r = NbImage("completion.png")
     assert isinstance(r, Image)
Beispiel #7
0
 def test_cmd_communicate2(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     out, err = run_cmd("dir *.py", shell=True, wait=True, communicate=True)
     assert len(out) > 0
Beispiel #8
0
    def test_post_parse_sn(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        register_canonical_role("bigger", bigger_role)
Beispiel #9
0
 def test_cmd_noshell(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     out, err = run_cmd("dir", wait=True)
     assert len(out) > 0
 def test_doctring2html_pandas(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     html = docstring2html(pandas.read_csv, "rawhtml", fLOG=fLOG)
     assert len(html) > 0
Beispiel #11
0
 def test_synchronize (self) :
     fLOG (__file__, self._testMethodName, OutputPrint = __name__ == "__main__")
     thispath = os.path.abspath(os.path.split(__file__) [0])
     cache = os.path.join (thispath, "temp_synchro" )
     if not os.path.exists (cache) : os.mkdir (cache)
     
     remone = os.path.join (cache, "test_log.py")
     fLOG("existing file",remone)
     if os.path.exists (remone) : 
         os.remove (remone)
         
     try :
         import pysvn
     except ImportError :
         return
         
     all = []
     action = foldermod.synchronize_folder (os.path.join(thispath,"..","ut_loghelper"), cache, hash_size = 0, repo1 = True, 
             operations = lambda a,b,c : all.append (a))
     assert len(all)>0
         
     action = foldermod.synchronize_folder (os.path.join(thispath,"..","ut_loghelper"), cache, hash_size = 0, repo1 = True)
     assert os.path.exists (cache)
     assert len(os.listdir(cache)) > 0
     assert os.path.exists (os.path.join(cache,"data"))
     assert len(os.listdir(os.path.join(cache,"data"))) > 0
     assert len(action) > 0
Beispiel #12
0
    def test_bug_accent(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        data = os.path.abspath(os.path.dirname(__file__))
        fold = os.path.join(data, "data", "bug")
        assert os.path.exists(fold)

        to = os.path.join(data, "temp_bug")
        if os.path.exists(to):
            remove_folder(to)
        os.mkdir(to)
        assert os.path.exists(to)

        synchronize_folder(fold, to, hash_size=0, repo1=False, repo2=False,
                           size_different=True, no_deletion=False, filter=None,
                           filter_copy=None, avoid_copy=False, operations=None,
                           file_date=None, log1=False)

        if sys.version_info[0] == 2:
            return

        assert os.path.exists(
            os.path.join(
                to,
                "bugged",
                "Présentation.pdf.txt"))
    def test_var(self):
        fLOG (__file__, self._testMethodName, OutputPrint = __name__ == "__main__")
        
        docstring = """
            This class opens a text file as if it were a binary file. It can deal with null characters which are missed by open function.

            @var    filename        file name
            @var    utf8            decode in utf8
            @var    errors          decoding in utf8 can raise some errors, @see cl str to understand the meaning of this parameter
            @var    fLOG            logging function (@see fn fLOG)
            @var    _buffer_size    read a text file _buffer_size bytes each time
            @var    _filter         function filter, None or return True or False whether a line should considered or not
            
            Example:
            @code
            f = TextFile (filename)
            f.open ()
            for line in f :
                print line
            f.close ()
            @endcode
            """    
        values = process_var_tag(docstring)
        assert len(values) == 6
        
        rst = process_var_tag(docstring, True)
        fLOG(rst)
        assert len(rst)  > 0
Beispiel #14
0
    def test_jsdifflib(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        try:
            import pymyinstall
        except ImportError:
            path = os.path.normpath(
                os.path.abspath(
                    os.path.join(
                        os.path.split(__file__)[0],
                        "..",
                        "..",
                        "..",
                        "pymyinstall",
                        "src")))
            if path not in sys.path:
                sys.path.append(path)
            try:
                import pymyinstall
            except ImportError:
                # we skip
                warnings.warn("unable to test TestJsDiffLib.test_jsdifflib")
                return

        tt = os.path.split(
            src.pyquickhelper.filehelper.visual_sync.__file__)[0]
        ma = tt
        p = create_visual_diff_through_html("a", "b")
        assert len(p) > 0
        assert os.path.exists(os.path.join(ma, "difflib.js"))
Beispiel #15
0
    def test_parse_readme_cb(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        fold = os.path.dirname(os.path.abspath(__file__))
        readme = os.path.join(fold, "data", "README.rst")
        fLOG(readme)
        assert os.path.exists(readme)
        with open(readme, "r", encoding="utf8") as f:
            content = f.read()
        r = parse_markdown(content)
        if sys.version_info[0] == 2:
            return
        if "<p>.. _l-README:</p>" not in str(r):
            m = [ord(c) for c in content]
            m = ",".join(str(_) for _ in m[:20])
            raise Exception("IN\n{0}\nOUT:{1}".format(m, str(r)))

        ht = rst2html(content)
        # fLOG(ht)
        assert len(ht) > 0

        spl = content.split("\n")
        r = list(yield_sphinx_only_markup_for_pipy(spl))
        assert len(r) == len(spl)
Beispiel #16
0
 def test_fail(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     # change that value to test the build stops going through a failure
     assert True
Beispiel #17
0
    def test_ie(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        if is_travis_or_appveyor() == "travis" or "anaconda" in sys.executable.lower() or sys.version_info[0] == 2 \
           or "yquickhelper_condavir" in sys.executable:
            if sys.version_info[0] == 2:
                warnings.warn(
                    "skipping on travis and with anaconda or python 2.7: " + sys.executable)
            else:
                warnings.warn(
                    "skipping on travis and with anaconda: " + sys.executable)
            return

        if not ie_layout_html():
            fLOG("updating layout.html")
            r = fix_ie_layout_html()
            assert r

        try:
            assert ie_layout_html()
        except AttributeError:
            return
Beispiel #18
0
 def test_conf_sphinx(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     ff = os.path.abspath(os.path.dirname(__file__))
     ff = os.path.join(
         ff,
         "..",
         "..",
         "_doc",
         "sphinxdoc",
         "source",
         "conf.py")
     if sys.version_info[0] == 2:
         return
     assert os.path.exists(ff)
     import solar_theme
     d = {}
     set_sphinx_variables(
         ff,
         "thisname",
         "XD",
         2014,
         "solar_theme",
         solar_theme.theme_path,
         d)
     for k, v in d.items():
         fLOG(k, "\t=", v)
Beispiel #19
0
    def test_newdirective_with_rst2html(self):
        """
        this test also test the extension runpython
        """
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        if sys.version_info[0] == 2:
            warnings.warn(
                "test_newdirective_with_rst2html not run on Python 2.7")
            return

        from docutils import nodes

        class runpythonthis_node(nodes.Structural, nodes.Element):
            pass

        class RunPythonThisDirective (RunPythonDirective):
            runpython_class = runpythonthis_node

        def visit_rp_node(self, node):
            self.body.append("<p><b>visit_rp_node</b></p>")

        def depart_rp_node(self, node):
            self.body.append("<p><b>depart_rp_node</b></p>")

        content = """
                    test a directive
                    ================

                    .. runpythonthis::

                        print(u"this code shoud appear" + u"___")
                    """.replace("                    ", "")
        if sys.version_info[0] >= 3:
            content = content.replace('u"', '"')

        tives = [("runpythonthis", RunPythonThisDirective, runpythonthis_node,
                  visit_rp_node, depart_rp_node)]

        html = rst2html(content, fLOG=fLOG,
                        writer="custom", keep_warnings=True,
                        directives=tives)

        ta = "<p><b>visit_rp_node</b></p>"
        if ta not in html:
            raise Exception(html)
        tb = "<p><b>depart_rp_node</b></p>"
        if tb not in html:
            raise Exception(html)
        t1 = "this code shoud appear___".split()
        for t in t1:
            if t not in html:
                temp = get_temp_folder(
                    __file__, "temp_newdirective_with_rst2html")
                with open(os.path.join(temp, "bug.html"), "w", encoding="utf8") as f:
                    f.write(html)
                raise Exception(html)
Beispiel #20
0
    def test_post_parse(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        directives.register_directive("runpython", RunPythonDirective)
Beispiel #21
0
    def test_bigger(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        if sys.version_info[0] == 2:
            warnings.warn(
                "test_biffer not run on Python 2.7")
            return

        from docutils import nodes as skip_

        content = """
                    test a directive
                    ================

                    before

                    :bigger:`facebook`

                    after

                    this code shoud appear
                    """.replace("                    ", "")
        if sys.version_info[0] >= 3:
            content = content.replace('u"', '"')

        html = rst2html(content, fLOG=fLOG,
                        writer="custom", keep_warnings=True,
                        directives=None)

        t1 = "this code shoud not appear"
        if t1 in html:
            raise Exception(html)

        t1 = "this code shoud appear"
        if t1 not in html:
            raise Exception(html)

        t1 = "facebook"
        if t1 not in html:
            raise Exception(html)

        t1 = "linkedin"
        if t1 in html:
            raise Exception(html)

        t1 = '{1}'
        if t1 in html:
            raise Exception(html)

        t1 = "visit_sharenet_node"
        if t1 in html:
            raise Exception(html)

        temp = get_temp_folder(__file__, "temp_bigger")
        with open(os.path.join(temp, "out_bigger.html"), "w", encoding="utf8") as f:
            f.write(html)
Beispiel #22
0
    def test_post_parse_blocref(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        directives.register_directive("blocref", BlocRef)
        directives.register_directive("blocreflist", BlocRefList)
Beispiel #23
0
 def test_load_content_file_with_encoding(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     file = __file__.replace(".pyc", ".py")
     cont, enc = load_content_file_with_encoding(file)
     assert len(file) > 0
    def test_nb_image(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        r = NbImage("completion.png")
        assert r is not None
Beispiel #25
0
    def test_get_default_value_type(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        assert get_default_value_type(None) is None
        assert get_default_value_type(int) == 0
Beispiel #26
0
 def test_remove_character_under32(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     s = "a\na\r"
     s2 = remove_character_under32(s)
     self.assertEqual(s2, 'a a ')
Beispiel #27
0
 def test_open_window_params(self):
     fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__")
     if __name__ == "__main__":
         par = {"user": os.environ["USERNAME"], "password": ""}
         res = open_window_params(
             par, help_string="unit test", title="try the password *", top_level_window=None, key_save="unique"
         )
         fLOG(res)
Beispiel #28
0
 def test_logfile(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     r = GetLogFile()
     assert not isinstance(r, str  # unicode#
                           )
    def test_file_binary (self) :
        fLOG (__file__, self._testMethodName, OutputPrint = __name__ == "__main__")

        if __name__ == "__main__" :
            functions = {   "test_regular_expression":test_regular_expression,
                            "test_edit_distance":file_grep,
                            "file_head":file_head }
            main_loop_functions ( functions, title = "title: TestMakeWindow2")
Beispiel #30
0
    def test_post_parse_sn_todoext(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        directives.register_directive("todoext", TodoExt)
        directives.register_directive("todoextlist", TodoExtList)