def test_download_zip(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") fold = get_temp_folder(__file__, "temp_download") url = "https://docs.python.org/3/library/ftplib.html" f = download(url, fold) fLOG(f) self.assertTrue(os.path.exists(f)) if not f.endswith("ftplib.html"): raise Exception(f) out1 = os.path.join(fold, "try.html.gz") gzip_files(out1, [f], fLOG=fLOG) self.assertTrue(os.path.exists(out1)) out2 = os.path.join(fold, "try.zip") zip_files(out2, [f], fLOG=fLOG) self.assertTrue(os.path.exists(out2)) if is_travis_or_appveyor() in ("circleci", None): out7 = os.path.join(fold, "try.7z") zip7_files(out7, [out1, out2], fLOG=fLOG, temp_folder=fold) if not os.path.exists(out7): raise FileNotFoundError(out7) else: fLOG("skip 7z")
def test_ensae_2016_answers(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") if is_travis_or_appveyor(): # no stored password return password = keyring.get_password( "cpt", os.environ["COMPUTERNAME"] + "pwd") r = data_cpt_ENSAE_2016_11_blind_set(password) self.assertEqual(len(r), 7500) truth = r r = data_cpt_ENSAE_2016_11_blind_set("dummy") self.assertEqual(len(r), 7500) s = sum(r) assert 0 <= s <= len(r) auc = AUC(truth, r) fLOG(auc) assert 0 <= auc <= 1 temp = get_temp_folder(__file__, "temp_cpt_ensae_2016_answers") out = os.path.join(temp, "answer.txt") with open(out, "w") as f: f.write("\n".join(str(_) for _ in r)) zip_files(os.path.join("submission.zip"), [out])
def test_ensae_2016_answers(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") if is_travis_or_appveyor(): # no stored password return password = keyring.get_password( "cpt", "ensae_teaching_cs,pwd") r = data_cpt_ENSAE_2016_11_blind_set(password) self.assertEqual(len(r), 7500) truth = r r = data_cpt_ENSAE_2016_11_blind_set("dummy") self.assertEqual(len(r), 7500) s = sum(r) assert 0 <= s <= len(r) auc = AUC(truth, r) fLOG(auc) assert 0 <= auc <= 1 temp = get_temp_folder(__file__, "temp_cpt_ensae_2016_answers") out = os.path.join(temp, "answer.txt") with open(out, "w") as f: f.write("\n".join(str(_) for _ in r)) zip_files(os.path.join("submission.zip"), [out])
def test_download_zip(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") fold = get_temp_folder(__file__, "temp_download") url = "https://docs.python.org/3/library/ftplib.html" f = download(url, fold) fLOG(f) self.assertTrue(os.path.exists(f)) if not f.endswith("ftplib.html"): raise Exception(f) out1 = os.path.join(fold, "try.html.gz") gzip_files(out1, [f], fLOG=fLOG) self.assertTrue(os.path.exists(out1)) out2 = os.path.join(fold, "try.zip") zip_files(out2, [f], fLOG=fLOG) self.assertTrue(os.path.exists(out2)) if is_travis_or_appveyor() in ("circleci", None): out7 = os.path.join(fold, "try.7z") zip7_files(out7, [out1, out2], fLOG=fLOG, temp_folder=fold) if not os.path.exists(out7): raise FileNotFoundError(out7) else: fLOG("skip 7z")
def test_compress_helper(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") typbytes = bytes f = os.path.abspath(__file__).replace(".pyc", ".py") rz = zip_files(None, [f], fLOG=fLOG) fLOG(len(rz), type(rz)) if not isinstance(rz, (typbytes, str)): raise TypeError(type(rz)) res = unzip_files(rz) self.assertTrue(isinstance(res, list)) self.assertEqual(len(res), 1) if not isinstance(res[0][1], (typbytes, str)): raise TypeError(type(res[0][1])) self.assertTrue(res[0][0].endswith( "_unittests/ut_filehelper/test_compress_helper.py")) # binary rg = gzip_files(None, [f], fLOG=fLOG) fLOG(len(rg), type(rg)) if not isinstance(rg, typbytes): raise TypeError(type(rg)) res = ungzip_files(rg) self.assertTrue(isinstance(res, list)) self.assertEqual(len(res), 1) if not isinstance(res[0][1], (typbytes, str)): raise TypeError(type(res[0][1])) self.assertTrue(res[0][0].endswith( "_unittests/ut_filehelper/test_compress_helper.py"))
def zip_group(self, group, outfile, addition=None): """ Zips a group. @param group group @param outfile output file @param addition additional files (sequence) @return list of zipped files """ def iter_files(): for _ in self.enumerate_group_files(group): yield _ if addition: for _ in addition: yield _ return zip_files(outfile, iter_files(), root=self._location)