How to use is_gzip_file method in avocado

Best Python code snippet using avocado_python

jsc_pydecrypt_tool.py

Source:jsc_pydecrypt_tool.py Github

copy

Full Screen

1import argparse2import gzip3import io4import sys5import zlib6from typing import Optional7from zipfile import BadZipFile, ZipFile8import xxtea9from reversebox.io_files.check_file import check_file10from logger import get_logger11# Ver Date Author Comment12# v0.1 03.09.2022 Bartlomiej Duda -13# v0.2 04.09.2022 Bartlomiej Duda -14logger = get_logger(__name__)15VERSION_NUM = "v0.2"16EXE_FILE_NAME = f"jsc_pydecrypt_tool_{VERSION_NUM}.exe"17PROGRAM_NAME = f"JSC PyDecrypt Tool {VERSION_NUM}"18def export_data(19 jsc_file_path: str, encryption_key_str: str, output_file_path: str20) -> Optional[tuple]:21 """22 Function for decrypting JSC files23 """24 logger.info("Starting export_data...")25 code, status = check_file(jsc_file_path, ".JSC", True)26 if code != "OK":27 return code, status28 jsc_file_data = open(jsc_file_path, "rb").read()29 logger.info(f"Decrypting with key = {encryption_key_str}")30 output_data = xxtea.decrypt(jsc_file_data, encryption_key_str)31 if len(output_data) == 0:32 return "WRONG_KEY", "Invalid encryption key!"33 is_gzip_file = True34 try:35 output_data = gzip.decompress(output_data)36 logger.info("IT IS a GZIP archive.")37 except gzip.BadGzipFile as error:38 logger.info("It's NOT a GZIP archive.")39 is_gzip_file = False40 if not is_gzip_file:41 try:42 zip_file = io.BytesIO(output_data)43 ZipFile(zip_file)44 output_file_path += ".zip"45 logger.info("IT IS a ZIP archive.")46 except BadZipFile as error:47 logger.info("It is NOT a ZIP archive.")48 js_file = open(output_file_path, "wb")49 js_file.write(output_data)50 js_file.close()51 logger.info(f"File exported: {output_file_path}")52 return "OK", ""53def main():54 """55 Main function of this program.56 """57 parser = argparse.ArgumentParser(prog=EXE_FILE_NAME, description=PROGRAM_NAME)58 # fmt: off59 parser.add_argument("-d", "--decrypt", metavar=("<jsc_file_path>", "<encryption_key>", "<output_file_path>"),60 type=str, nargs=3, required=False, help="Decrypt data")61 # fmt: on62 if len(sys.argv) == 1:63 parser.print_help()64 sys.exit(1)65 args = parser.parse_args()66 if args.decrypt is not None:67 code, status = export_data(args.decrypt[0], args.decrypt[1], args.decrypt[2])68 if code != "OK":69 logger.error(f"{code}: {status}")70 sys.exit(-1)71 logger.info("End of main... Program has been executed successfully!")72 sys.exit(0)73if __name__ == "__main__":...

Full Screen

Full Screen

test_log_analyzer.py

Source:test_log_analyzer.py Github

copy

Full Screen

...27 # def setUp(self):28 # print("setUp")29 # def tearDown(self):30 # print("tearDown")31 def test_is_gzip_file(self):32 print("test_is_gzip_file")33 self.assertTrue(log_analyzer.is_gzip_file("./test.gz"))34 self.assertFalse(log_analyzer.is_gzip_file("./test.bz2"))35 self.assertFalse(log_analyzer.is_gzip_file("./test"))36 def test_get_latest_log_info(self):37 latest_log_info = log_analyzer.get_latest_log_info(TMP_DIR)38 self.assertEqual(latest_log_info.path, os.path.join(TMP_DIR, LOGS[0]))39if __name__ == "__main__":...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

...345class TestIsGzipFileFunction(unittest.TestCase):6 def test_is_gzip_file__xml(self):7 self.assertEqual(is_gzip_file("testpath/file.xml"), False)89 def test_is_gzip_file__txt(self):10 self.assertEqual(is_gzip_file("testpath/file.txt"), False)1112 def test_is_gzip_file__gzip(self):13 self.assertEqual(is_gzip_file("testpath/file.gz"), True)141516class TestParseRecord(unittest.TestCase):17 def test_parse_record(self):18 str = b'1.196.116.32 - - [29/Jun/2017:03:51:01 +0300] "GET /api/v2/banner/1662508 HTTP/1.1" 200 948 "-" "Lynx/2.8.8dev.9 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.10.5" "-" "1498697460-2190034393-4708-9753194" "dc7161be3" 0.689\n'19 self.assertEqual(parse_log_record(20 str), ("/api/v2/banner/1662508", "0.689\n"))212223if __name__ == '__main__': ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful