def test_import_exam_vigenere(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") if is_travis_or_appveyor(): # no password return from src.ensae_teaching_cs.td_1a.vigenere import code_vigenere with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) import keyring temp = get_temp_folder(__file__, "temp_import_exam_vigenere") pwd = keyring.get_password("exam", "ensae_teaching_cs,key") pwd = pwd.encode("ascii") this = os.path.abspath(os.path.dirname(module_file)) dst = os.path.join(this, "encrypted", "cryptcode_exam_2016.vigenere") assert os.path.exists(dst) with open(dst, "rb") as f: content = f.read() content = code_vigenere(content, pwd, binary=True, decode=True) decr = os.path.join(temp, "onemod_vigenere.py") with open(decr, "wb") as f: f.write(content) assert os.path.exists(decr) fLOG("importing") sys.path.append(temp) import onemod as temp_module del sys.path[-1] answer = temp_module.build(120) exp = """*** H H *** H *** H *** H H *** H *** H *** H H *** H *** H *** H H *** H *** H""".replace(" ", "") self.assertEqual(answer, exp)
def test_import_exam_vigenere(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") if is_travis_or_appveyor(): # no password return from ensae_teaching_cs.td_1a.vigenere import code_vigenere with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) import keyring temp = get_temp_folder(__file__, "temp_import_exam_vigenere") pwd = keyring.get_password("exam", "ensae_teaching_cs,key") pwd = pwd.encode("ascii") this = os.path.abspath(os.path.dirname(module_file)) dst = os.path.join(this, "encrypted", "cryptcode_exam_2016.vigenere") assert os.path.exists(dst) with open(dst, "rb") as f: content = f.read() content = code_vigenere(content, pwd, binary=True, decode=True) decr = os.path.join(temp, "onemod_vigenere.py") with open(decr, "wb") as f: f.write(content) assert os.path.exists(decr) fLOG("importing") sys.path.append(temp) import onemod as temp_module del sys.path[-1] answer = temp_module.build(120) exp = """*** H H *** H *** H *** H H *** H *** H *** H H *** H *** H *** H H *** H *** H""".replace(" ", "") self.assertEqual(answer, exp)
def test_import_exam(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") if is_travis_or_appveyor(): # no password return with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) import keyring temp = get_temp_folder(__file__, "temp_import_exam") pwd = keyring.get_password("exam", "ensae_teaching_cs,key") pwd += "*" * (16 - len(pwd)) pwd = pwd.encode("ascii") this = os.path.abspath(os.path.dirname(module_file)) dst = os.path.join(this, "encrypted", "cryptcode_exam_2016.crypted") assert os.path.exists(dst) decr = os.path.join(temp, "onemod.py") decrypt_stream(pwd, dst, decr) assert os.path.exists(decr) fLOG("importing") sys.path.append(temp) import onemod as temp_module del sys.path[-1] answer = temp_module.build(120) exp = """*** H H *** H *** H *** H H *** H *** H *** H H *** H *** H *** H H *** H *** H""".replace(" ", "") self.assertEqual(answer, exp)