def test_main(self): st = BufferedPrint() main(args=[], fLOG=st.fprint) res = str(st) self.assertIn("python -m pyquickhelper <command>", res) self.assertIn("Synchronizes a folder", res)
def test_main_epkg(self): st = BufferedPrint() main(args=["clean_files", "--help"], fLOG=st.fprint) res = str(st) self.assertNotIn("<<", res) self.assertNotIn("``", res) self.assertIn("`'\\n'`", res)
def test_cli_ftp_comma(self): st = BufferedPrint() try: main(args=['ftp_upload', '-f', 'a,b', '-d', 'www/', '-ho', 'ftp.xavierdupre.fr', '-u', 'user', '--pwd', '***', '-ft', '1'], fLOG=st.fprint) except socket.gaierror: # expected return
def test_process_notebook(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") temp = get_temp_folder(__file__, "temp_process_notebook") source = os.path.join(temp, "..", "data", "td1a_unit_test_ci.ipynb") st = BufferedPrint() main(args=["process_notebooks", "-n", source, "-o", temp, "-b", temp, '-f', 'rst'], fLOG=st.fprint) res = str(st) self.assertIn("convert into rst", res)
def test_sphinx_rst(self): "sphinx rst" st = BufferedPrint() temp = get_temp_folder(__file__, "temp_sphinx_rst") name = os.path.join(temp, "..", "data", "glossary.rst") out = os.path.join(temp, "out") res = main(args=['sphinx_rst', '-i', name, '-o', out], fLOG=st.fprint) out += ".html" self.assertExists(out)
def test_zoom_img_do(self): temp = get_temp_folder(__file__, 'temp_img_zoom') dest = os.path.join(temp, '{}') data = os.path.join(temp, '..', 'data', '*.png') st = BufferedPrint() win = main(args=['zoom_img', '-f', '0.5', '--img', data, '-o', dest], fLOG=st.fprint) res = str(st) self.assertNotIn("usage: zoom_img", res) self.assertIn("Writing '", res)
def test_main(self): from tkinter import TclError st = BufferedPrint() try: win = main(args=['--GUITEST'], fLOG=st.fprint) except TclError as e: # probably run from a remote machine warnings.warn(str(e)) return res = str(st) self.assertNotIn("python -m pyquickhelper <command> --help", res) self.assertNotEmpty(win)
def test_sphinx_rst_notoctree(self): "sphinx rst toctree" st = BufferedPrint() temp = get_temp_folder(__file__, "temp_sphinx_rst_notoctree") name = os.path.join(temp, "..", "data", "piecewise_notoc.rst") out = os.path.join(temp, "out") res = main(args=['sphinx_rst', '-i', name, '-o', out], fLOG=st.fprint) out += ".html" self.assertExists(out) with open(out, "r", encoding="utf-8") as f: content = f.read() self.assertIn("pour finalement illustrer", content)
def test_cli_file_helper(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") this = os.path.abspath(os.path.dirname(__file__)) st = BufferedPrint() main(args=["ls", "-f", this, "-p", ".*[.]py", "-r", "f"], fLOG=st.fprint) res = str(st) self.assertIn(".py", res) this = os.path.abspath(os.path.dirname(__file__)) st = BufferedPrint() main(args=[ "ls", "-f", this, "-p", ".*[.]py", "-r", "f", '-n', 'pycache', '-fu', '1' ], fLOG=st.fprint) res = str(st) self.assertIn(".py", res) self.assertNotIn("pycache", res) this = os.path.abspath(os.path.dirname(__file__)) st = BufferedPrint() main(args=[ "ls", "-f", this, "-p", ".*[.]py", "-r", "f", '-n', 'pycache', '-fu', '1', '-s', "test_(.*)", '-su', 'unit_\\1' ], fLOG=st.fprint) res = str(st) self.assertIn(".py", res) self.assertNotIn("pycache", res) self.assertNotIn("test_parser", res) self.assertIn("unit_parser", res)
def test_convert_notebook2(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") temp = get_temp_folder(__file__, "temp_convert_notebook2") source = os.path.join(temp, "..", "data", "onnx_tree_ensemble_parallel.ipynb") with self.subTest(cmd="convert_notebook"): st = BufferedPrint() main(args=["convert_notebook", "-f", source, "-o", temp, "-b", temp, '-fo', 'rst,html'], fLOG=st.fprint) res = str(st) self.assertIn("convert into 'rst'", res) with self.subTest(cmd="run_notebook"): outname = os.path.join(temp, "out_nb.ipynb") st = BufferedPrint() main(args=['run_notebook', '-f', source, '-o', outname], fLOG=st.fprint) res = str(st) self.assertExists(outname) source = outname temp2 = get_temp_folder(__file__, "temp_convert_notebook2_next") st = BufferedPrint() main(args=["convert_notebook", "-f", source, "-o", temp2, "-b", temp2, '-fo', 'rst,html'], fLOG=st.fprint) res = str(st) self.assertIn("convert into 'rst'", res) self.assertExists(os.path.join(temp2, "out_nb2html.html"))
def test_cli_file_helper(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") this = os.path.abspath(os.path.dirname(__file__)) st = BufferedPrint() main(args=["ls", "-f", this, "-p", ".*[.]py", "-r", "f"], fLOG=st.fprint) res = str(st) self.assertIn(".py", res) this = os.path.abspath(os.path.dirname(__file__)) st = BufferedPrint() main(args=["ls", "-f", this, "-p", ".*[.]py", "-r", "f", '-n', 'pycache', '-fu', '1'], fLOG=st.fprint) res = str(st) self.assertIn(".py", res) self.assertNotIn("pycache", res) this = os.path.abspath(os.path.dirname(__file__)) st = BufferedPrint() main(args=["ls", "-f", this, "-p", ".*[.]py", "-r", "f", '-n', 'pycache', '-fu', '1', '-s', "test_(.*)", '-su', 'unit_\\1'], fLOG=st.fprint) res = str(st) self.assertIn(".py", res) self.assertNotIn("pycache", res) self.assertNotIn("test_parser", res) self.assertIn("unit_parser", res)
def test_convert_notebook(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") temp = get_temp_folder(__file__, "temp_convert_notebook") source = os.path.join(temp, "..", "data", "td1a_unit_test_ci.ipynb") fold = 'static' if not os.path.exists(fold): os.mkdir(fold) for tpl in ['rst', 'display_priority', 'null']: sty = os.path.join(fold, '%s.tpl' % tpl) sr = os.path.join(temp, '..', 'data', '%s.tpl' % tpl) if not os.path.exists(sr): raise FileNotFoundError(sr) if not os.path.exists(sty): shutil.copy(sr, fold) if not os.path.exists('%s.tpl' % tpl): shutil.copy(sr, '.') with self.subTest(cmd="convert_notebook"): st = BufferedPrint() main(args=[ "convert_notebook", "-f", source, "-o", temp, "-b", temp, '-fo', 'rst,html' ], fLOG=st.fprint) res = str(st) self.assertIn("convert into 'rst'", res) with self.subTest(cmd="run_notebook"): outname = os.path.join(temp, "out_nb.ipynb") st = BufferedPrint() main(args=['run_notebook', '-f', source, '-o', outname], fLOG=st.fprint) res = str(st) self.assertExists(outname) source = outname temp2 = get_temp_folder(__file__, "temp_convert_notebook_next") st = BufferedPrint() main(args=[ "convert_notebook", "-f", source, "-o", temp2, "-b", temp2, '-fo', 'rst,html' ], fLOG=st.fprint) res = str(st) self.assertIn("convert into 'rst'", res) self.assertExists(os.path.join(temp2, "out_nb2html.html"))
def test_encrypt_files(self): st = BufferedPrint() main(args=["encrypt_file", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: encrypt_file", res)
def test_clean_files(self): st = BufferedPrint() main(args=["clean_files", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: clean_files", res)
def test_run_notebook_help(self): st = BufferedPrint() main(args=['run_notebook', '--help'], fLOG=st.fprint) res = str(st) self.assertIn("run_notebook [-h]", res)
def test_srst(self): st = BufferedPrint() main(args=["sphinx_rst", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: sphinx_rst", res)
def test_ls(self): st = BufferedPrint() main(args=["ls", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: ls", res)
def test_cvtnb(self): st = BufferedPrint() main(args=["convert_notebook", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: convert_notebook", res)
def test_profile_stat_gr(self): def f0(t): time.sleep(t) def f1(t): time.sleep(t) def f2(): f1(0.1) f1(0.01) def f3(): f0(0.2) f1(0.5) def f4(): f2() f3() ps = profile(f4)[0] # pylint: disable=W0632 ps.dump_stats("temp_gr_stat.prof") with self.subTest(calls=False, output=None): st = BufferedPrint() main(args=[ 'profile_stat', '-f', "temp_gr_stat.prof", '--calls', '1' ], fLOG=st.fprint) self.assertIn('+++', str(st)) with self.subTest(calls=False, output="txt"): st = BufferedPrint() main(args=[ 'profile_stat', '-f', "temp_gr_stat.prof", '--calls', '1', '-o', 'temp_gr_output.txt' ], fLOG=st.fprint) with open("temp_gr_output.txt", "r", encoding='utf-8') as f: content = f.read() self.assertIn('+++', str(st)) self.assertIn('+++', content) with self.subTest(calls=False, output='csv'): st = BufferedPrint() main(args=[ 'profile_stat', '-f', "temp_gr_stat.prof", '--calls', '1', '-o', 'temp_gr_output.csv' ], fLOG=st.fprint) with open("temp_gr_output.csv", "r", encoding='utf-8') as f: content = f.read() self.assertIn('+++', str(st)) self.assertIn(',+', content) with self.subTest(calls=False, output='xlsx'): st = BufferedPrint() main(args=[ 'profile_stat', '-f', "temp_gr_stat.prof", '--calls', '1', '-o', 'temp_gr_output.xlsx' ], fLOG=st.fprint) self.assertIn('+++', str(st)) self.assertExists('temp_gr_output.xlsx')
def test_main(self): st = BufferedPrint() main(args=[], fLOG=st.fprint) res = str(st) self.assertIn("python -m pyquickhelper <command>", res) self.assertIn("Synchronizes a folder", res) st = BufferedPrint() main(args=["clean_files", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: clean_files", res) st = BufferedPrint() main(args=["df2rst", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "usage: df2rst [-h] [--df DF] [-a ADD_LINE] [-al ALIGN] [-c COLUMN_SIZE]", res) st = BufferedPrint() main(args=["encrypt", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "usage: encrypt [-h] [-s STATUS] [-m MAP] source dest password", res) st = BufferedPrint() main(args=["encrypt_file", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: encrypt_file [-h] source dest password", res) st = BufferedPrint() main(args=["encrypts", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("Command not found: 'encrypts'.", res) st = BufferedPrint() main(args=["synchronize_folder", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "synchronize_folder [-h] [--p1 P1] [--p2 P2] [-ha HASH_SIZE]", res) st = BufferedPrint() main(args=["process_notebooks", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "process_notebooks [-h] [-n NOTEBOOKS] [-o OUTFOLD] [-b BUILD]", res) st = BufferedPrint() main(args=["visual_diff", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "visual_diff [-h] [-f FILE1] [-fi FILE2]", res) st = BufferedPrint() main(args=["ls", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "ls [-h] [-f FOLDER] [-p PATTERN] [-n NEG_PATTERN]", res) st = BufferedPrint() main(args=["run_test_function", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "run_test_function [-h] [-m MODULE] [-p PATTERN] [-s STOP_FIRST]", res) st = BufferedPrint() main(args=["sphinx_rst", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "sphinx_rst [-h] [-i INPUT] [-w WRITER] [-k KEEP_WARNINGS]", res) st = BufferedPrint() main(args=["run_notebook", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "run_notebook [-h] [-f FILENAME] [-p PROFILE_DIR] [-w WORKING_DIR]", res)
def test_zoom_img_help(self): st = BufferedPrint() main(args=['zoom_img', '--help'], fLOG=st.fprint) res = str(st) self.assertIn("usage: zoom_img", res)
def to_profile(args): st = BufferedPrint() main(args=args, fLOG=st.fprint) return str(st)
def test_set_passwrd(self): st = BufferedPrint() main(args=['set_password', '--help'], fLOG=st.fprint) res = str(st) self.assertIn("usage: set_password", res)
def test_images2pdf_help(self): st = BufferedPrint() main(args=['images2pdf', '--help'], fLOG=st.fprint) res = str(st) self.assertIn("usage: images2pdf", res)
def test_encrypts(self): st = BufferedPrint() main(args=["encrypts", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("Command not found: 'encrypts'.", res)
def test_sync(self): st = BufferedPrint() main(args=["synchronize_folder", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: synchronize_folder", res)
def test_profile_stat_help(self): st = BufferedPrint() main(args=['profile_stat', '--help'], fLOG=st.fprint) res = str(st) self.assertIn("usage: profile_stat", res)
def test_vdiff(self): st = BufferedPrint() main(args=["visual_diff", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: visual_diff", res)
def test_repeat(self): st = BufferedPrint() main(args=["repeat_script", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: repeat_script", res)
def test_rtf(self): st = BufferedPrint() main(args=["run_test_function", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: run_test_function", res)
def test_ftp(self): st = BufferedPrint() main(args=["ftp_upload", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: ftp_upload", res)
def test_runnb2(self): st = BufferedPrint() main(args=["run_notebook", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: run_notebook", res)
def test_main_epkg(self): st = BufferedPrint() main(args=["clean_files", "--help"], fLOG=st.fprint) res = str(st) self.assertNotIn("<<", res)
def test_main(self): st = BufferedPrint() main(args=[], fLOG=st.fprint) res = str(st) self.assertIn("python -m pyquickhelper <command>", res) self.assertIn("Synchronizes a folder", res) st = BufferedPrint() main(args=["clean_files", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: clean_files", res) st = BufferedPrint() main(args=["df2rst", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "usage: df2rst [-h] [--df DF] [-a ADD_LINE] [-al ALIGN] [-c COLUMN_SIZE]", res) st = BufferedPrint() main(args=["encrypt", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "usage: encrypt [-h] [-s STATUS] [-m MAP] source dest password", res) st = BufferedPrint() main(args=["encrypt_file", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("usage: encrypt_file [-h] source dest password", res) st = BufferedPrint() main(args=["encrypts", "--help"], fLOG=st.fprint) res = str(st) self.assertIn("Command not found: 'encrypts'.", res) st = BufferedPrint() main(args=["synchronize_folder", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "synchronize_folder [-h] [--p1 P1] [--p2 P2] [-ha HASH_SIZE]", res) st = BufferedPrint() main(args=["convert_notebook", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "convert_notebook [-h] [-f FILENAME] [-o OUTFOLD] [-b BUILD]", res) st = BufferedPrint() main(args=["run_notebook", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "run_notebook [-h] [-f FILENAME]", res) st = BufferedPrint() main(args=["visual_diff", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "visual_diff [-h] [-f FILE1] [-fi FILE2]", res) st = BufferedPrint() main(args=["ls", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "ls [-h] [-f FOLDER] [-p PATTERN] [-n NEG_PATTERN]", res) st = BufferedPrint() main(args=["run_test_function", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "run_test_function [-h] [-m MODULE] [-p PATTERN] [-s STOP_FIRST]", res) st = BufferedPrint() main(args=["sphinx_rst", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "sphinx_rst [-h] [-i INPUT] [-w WRITER] [-k KEEP_WARNINGS]", res) st = BufferedPrint() main(args=["run_notebook", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "run_notebook [-h] [-f FILENAME] [-p PROFILE_DIR] [-w WORKING_DIR]", res) st = BufferedPrint() main(args=["repeat_script", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "repeat_script [-h] [-s SCRIPT] [-e EVERY_SECOND]", res) st = BufferedPrint() main(args=["ftp_upload", "--help"], fLOG=st.fprint) res = str(st) self.assertIn( "ftp_upload [-h] [-f FILES] [-d DEST] [-ho HOST] [-u USER]", res)