How to use check_logs method in localstack

Best Python code snippet using localstack_python

tools.py

Source:tools.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# Copyright 2021 Tampere University and VTT Technical Research Centre of Finland3# This software was developed as a part of the ProCemPlus project: https://www.senecc.fi/projects/procemplus4# This source code is licensed under the MIT license. See LICENSE in the repository root directory.5# Author(s): Ville Heikkilä <ville.heikkila@tuni.fi>6"""Unit tests for the functions in tools.py."""7import logging8import unittest9from tools.tools import FullLogger, load_environmental_variables10def add_log_message(logger: FullLogger, check_list: list, log_level: int, log_message: str):11 """Adds a log message to a logger and check string to a check list."""12 if log_level == logging.DEBUG:13 logger.debug(log_message)14 elif log_level == logging.INFO:15 logger.info(log_message)16 elif log_level == logging.WARNING:17 logger.warning(log_message)18 elif log_level == logging.ERROR:19 logger.error(log_message)20 elif log_level == logging.CRITICAL:21 logger.critical(log_message)22 check_list.append(":".join([logger.MESSAGE_LEVEL[log_level], logger.logger_name, log_message]))23class TestTools(unittest.TestCase):24 """Unit tests for the tools module."""25 def test_load_environmental_variables(self):26 """Tests for loading environmental variables."""27 # the environmental values that are set in the docker-compose file28 # - ENV_TEST_VALUE_BOOL=true29 # - ENV_TEST_VALUE_INT=1230 # - ENV_TEST_VALUE_FLOAT=2.3431 # - ENV_TEST_VALUE_STRING=hello32 test_env_variables = load_environmental_variables(33 ("ENV_TEST_VALUE_BOOL", bool, False),34 ("ENV_TEST_VALUE_INT", int, 13),35 ("ENV_TEST_VALUE_FLOAT", float, 7.35),36 ("ENV_TEST_VALUE_STRING", str, "world"),37 ("ENV_TEST_VALUE_MISSING", str, "missing")38 )39 self.assertIsInstance(test_env_variables["ENV_TEST_VALUE_BOOL"], bool)40 self.assertEqual(test_env_variables["ENV_TEST_VALUE_BOOL"], True)41 self.assertIsInstance(test_env_variables["ENV_TEST_VALUE_INT"], int)42 self.assertEqual(test_env_variables["ENV_TEST_VALUE_INT"], 12)43 self.assertIsInstance(test_env_variables["ENV_TEST_VALUE_FLOAT"], float)44 self.assertEqual(test_env_variables["ENV_TEST_VALUE_FLOAT"], 2.34)45 self.assertIsInstance(test_env_variables["ENV_TEST_VALUE_STRING"], str)46 self.assertEqual(test_env_variables["ENV_TEST_VALUE_STRING"], "hello")47 self.assertIsInstance(test_env_variables["ENV_TEST_VALUE_MISSING"], str)48 self.assertEqual(test_env_variables["ENV_TEST_VALUE_MISSING"], "missing")49 def test_logging(self):50 """Tests for using FullLogger."""51 logger = FullLogger("test_logger", logger_level=logging.DEBUG, stdout_output=False)52 check_logs = []53 # The output for test_logger will have the default format, not the format used in FullLogger54 with self.assertLogs(logger.logger, logger.level) as test_logger:55 add_log_message(logger, check_logs, logging.DEBUG, "Debug test")56 add_log_message(logger, check_logs, logging.INFO, "Info test")57 add_log_message(logger, check_logs, logging.WARNING, "Warning test")58 add_log_message(logger, check_logs, logging.ERROR, "Error test")59 add_log_message(logger, check_logs, logging.CRITICAL, "Critical test")60 self.assertEqual(test_logger.output, check_logs)61 logger.level = logging.INFO62 check_logs = []63 with self.assertLogs(logger.logger, logger.level) as test_logger:64 logger.debug("Debug test")65 add_log_message(logger, check_logs, logging.INFO, "Info test")66 add_log_message(logger, check_logs, logging.WARNING, "Warning test")67 add_log_message(logger, check_logs, logging.ERROR, "Error test")68 add_log_message(logger, check_logs, logging.CRITICAL, "Critical test")69 self.assertEqual(test_logger.output, check_logs)70 logger.level = logging.WARNING71 check_logs = []72 with self.assertLogs(logger.logger, logger.level) as test_logger:73 logger.debug("Debug test")74 logger.info("Info test")75 add_log_message(logger, check_logs, logging.WARNING, "Warning test")76 add_log_message(logger, check_logs, logging.ERROR, "Error test")77 add_log_message(logger, check_logs, logging.CRITICAL, "Critical test")78 self.assertEqual(test_logger.output, check_logs)79 logger.level = logging.ERROR80 check_logs = []81 with self.assertLogs(logger.logger, logger.level) as test_logger:82 logger.debug("Debug test")83 logger.info("Info test")84 logger.warning("Warning test")85 add_log_message(logger, check_logs, logging.ERROR, "Error test")86 add_log_message(logger, check_logs, logging.CRITICAL, "Critical test")87 self.assertEqual(test_logger.output, check_logs)88 logger.level = logging.CRITICAL89 check_logs = []90 with self.assertLogs(logger.logger, logger.level) as test_logger:91 logger.debug("Debug test")92 logger.info("Info test")93 logger.warning("Warning test")94 logger.error("Error test")95 add_log_message(logger, check_logs, logging.CRITICAL, "Critical test")96 self.assertEqual(test_logger.output, check_logs)97if __name__ == '__main__':...

Full Screen

Full Screen

compare_benchmark_logs

Source:compare_benchmark_logs Github

copy

Full Screen

...46 def is_same_benchmark(self, other) -> bool:47 return (os.path.basename(self.benchmark_path) == os.path.basename(other.benchmark_path)) and \48 (self.benchmark_size == other.benchmark_size) and \49 len(set(self.benchmark_files()) - set(other.benchmark_files())) == 050def compare_check_logs(check_logs: List[CheckLog]):51 for i in range(len(check_logs)-1):52 assert check_logs[i].is_same_benchmark(check_logs[i+1])53 num_logs = len(check_logs)54 print(f'benchmark_path: {check_logs[0].benchmark_path}')55 print(f'benchmark_size: {check_logs[0].benchmark_size}')56 print('(tool-check_date, #unsat, #sat, #timeout, #unknown, #exception/error)')57 for i in range(num_logs):58 tool_date = f'{check_logs[i].check_tool}-{check_logs[i].check_date}'59 num_unsat = check_logs[i].count_result("unsat")60 num_sat = check_logs[i].count_result("sat")61 num_timeout = check_logs[i].count_result("timeout")62 num_unknown = check_logs[i].count_result("unknown")63 num_exception = check_logs[i].count_result("exception")64 num_error = check_logs[i].count_result("error")65 num_exer = check_logs[i].benchmark_size - num_unsat - num_sat - num_timeout - num_unknown66 print(f'({tool_date}, {num_unsat}, {num_sat}, {num_timeout}, {num_unknown}, {num_exer})')67def main(argv):68 # Set argument parser69 arg_parser = ArgumentParser(prog=None,70 usage=None,71 description="A Python script to compare benchmark checking log of TrauC (z3qses) to "72 "other string solvers.",73 epilog=None)74 arg_parser.add_argument("benchmark_log_name",75 help="Filename of benchmark check log without extensions (before '.<date>.<tool>.log*')")76 args = arg_parser.parse_args()77 """78 if "." in args.benchmark_log_name:79 benchmark_log_name = args.benchmark_log_name.split('.')[0]80 else:81 benchmark_log_name = args.benchmark_log_name82 """83 benchmark_log_name = args.benchmark_log_name84 # prepare benchmark85 all_log_files = [f for f in os.listdir('.')86 if re.match(re.escape(benchmark_log_name) + r'\.[0-9]+\.[a-zA-z0-9]+\.log$', f)]87 print('log files read:')88 print(' ' + '\n '.join(all_log_files))89 check_logs = [CheckLog(log) for log in all_log_files]90 compare_check_logs(check_logs)91if __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 localstack 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