How to use assert_logged method in Testify

Best Python code snippet using Testify_python

test_logger.py

Source:test_logger.py Github

copy

Full Screen

...27 def setup_logger(self, config):28 """Set up logger and save log filter."""29 setup_component(self.hass, logger.DOMAIN, config)30 self.log_filter = logging.root.handlers[-1].filters[0]31 def assert_logged(self, name, level):32 """Assert that a certain record was logged."""33 assert self.log_filter.filter(RECORD(name, level))34 def assert_not_logged(self, name, level):35 """Assert that a certain record was not logged."""36 assert not self.log_filter.filter(RECORD(name, level))37 def test_logger_setup(self):38 """Use logger to create a logging filter."""39 self.setup_logger(TEST_CONFIG)40 assert len(logging.root.handlers) > 041 handler = logging.root.handlers[-1]42 assert len(handler.filters) == 143 log_filter = handler.filters[0].logfilter44 assert log_filter['default'] == logging.WARNING45 assert log_filter['logs']['test'] == logging.INFO46 def test_logger_test_filters(self):47 """Test resulting filter operation."""48 self.setup_logger(TEST_CONFIG)49 # Blocked default record50 self.assert_not_logged('asdf', logging.DEBUG)51 # Allowed default record52 self.assert_logged('asdf', logging.WARNING)53 # Blocked named record54 self.assert_not_logged('test', logging.DEBUG)55 # Allowed named record56 self.assert_logged('test', logging.INFO)57 def test_set_filter_empty_config(self):58 """Test change log level from empty configuration."""59 self.setup_logger(NO_LOGS_CONFIG)60 self.assert_not_logged('test', logging.DEBUG)61 self.hass.services.call(62 logger.DOMAIN, 'set_level', {'test': 'debug'})63 self.hass.block_till_done()64 self.assert_logged('test', logging.DEBUG)65 def test_set_filter(self):66 """Test change log level of existing filter."""67 self.setup_logger(TEST_CONFIG)68 self.assert_not_logged('asdf', logging.DEBUG)69 self.assert_logged('dummy', logging.WARNING)70 self.hass.services.call(logger.DOMAIN, 'set_level',71 {'asdf': 'debug', 'dummy': 'info'})72 self.hass.block_till_done()73 self.assert_logged('asdf', logging.DEBUG)74 self.assert_logged('dummy', logging.WARNING)75 def test_set_default_filter_empty_config(self):76 """Test change default log level from empty configuration."""77 self.setup_logger(NO_DEFAULT_CONFIG)78 self.assert_logged('test', logging.DEBUG)79 self.hass.services.call(80 logger.DOMAIN, 'set_default_level', {'level': 'warning'})81 self.hass.block_till_done()82 self.assert_not_logged('test', logging.DEBUG)83 def test_set_default_filter(self):84 """Test change default log level with existing default."""85 self.setup_logger(TEST_CONFIG)86 self.assert_not_logged('asdf', logging.DEBUG)87 self.assert_logged('dummy', logging.WARNING)88 self.hass.services.call(89 logger.DOMAIN, 'set_default_level', {'level': 'debug'})90 self.hass.block_till_done()91 self.assert_logged('asdf', logging.DEBUG)...

Full Screen

Full Screen

test_init.py

Source:test_init.py Github

copy

Full Screen

...22 def setup_logger(self, config):23 """Set up logger and save log filter."""24 setup_component(self.hass, logger.DOMAIN, config)25 self.log_filter = logging.root.handlers[-1].filters[0]26 def assert_logged(self, name, level):27 """Assert that a certain record was logged."""28 assert self.log_filter.filter(RECORD(name, level))29 def assert_not_logged(self, name, level):30 """Assert that a certain record was not logged."""31 assert not self.log_filter.filter(RECORD(name, level))32 def test_logger_setup(self):33 """Use logger to create a logging filter."""34 self.setup_logger(TEST_CONFIG)35 assert len(logging.root.handlers) > 036 handler = logging.root.handlers[-1]37 assert len(handler.filters) == 138 log_filter = handler.filters[0].logfilter39 assert log_filter["default"] == logging.WARNING40 assert log_filter["logs"]["test"] == logging.INFO41 def test_logger_test_filters(self):42 """Test resulting filter operation."""43 self.setup_logger(TEST_CONFIG)44 # Blocked default record45 self.assert_not_logged("asdf", logging.DEBUG)46 # Allowed default record47 self.assert_logged("asdf", logging.WARNING)48 # Blocked named record49 self.assert_not_logged("test", logging.DEBUG)50 # Allowed named record51 self.assert_logged("test", logging.INFO)52 def test_set_filter_empty_config(self):53 """Test change log level from empty configuration."""54 self.setup_logger(NO_LOGS_CONFIG)55 self.assert_not_logged("test", logging.DEBUG)56 self.hass.services.call(logger.DOMAIN, "set_level", {"test": "debug"})57 self.hass.block_till_done()58 self.assert_logged("test", logging.DEBUG)59 def test_set_filter(self):60 """Test change log level of existing filter."""61 self.setup_logger(TEST_CONFIG)62 self.assert_not_logged("asdf", logging.DEBUG)63 self.assert_logged("dummy", logging.WARNING)64 self.hass.services.call(65 logger.DOMAIN, "set_level", {"asdf": "debug", "dummy": "info"}66 )67 self.hass.block_till_done()68 self.assert_logged("asdf", logging.DEBUG)69 self.assert_logged("dummy", logging.WARNING)70 def test_set_default_filter_empty_config(self):71 """Test change default log level from empty configuration."""72 self.setup_logger(NO_DEFAULT_CONFIG)73 self.assert_logged("test", logging.DEBUG)74 self.hass.services.call(75 logger.DOMAIN, "set_default_level", {"level": "warning"}76 )77 self.hass.block_till_done()78 self.assert_not_logged("test", logging.DEBUG)79 def test_set_default_filter(self):80 """Test change default log level with existing default."""81 self.setup_logger(TEST_CONFIG)82 self.assert_not_logged("asdf", logging.DEBUG)83 self.assert_logged("dummy", logging.WARNING)84 self.hass.services.call(logger.DOMAIN, "set_default_level", {"level": "debug"})85 self.hass.block_till_done()86 self.assert_logged("asdf", logging.DEBUG)...

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 Testify 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