當前位置: 首頁>>代碼示例>>Python>>正文


Python Dependency.error方法代碼示例

本文整理匯總了Python中common.utilities.inversion_of_control.Dependency.error方法的典型用法代碼示例。如果您正苦於以下問題:Python Dependency.error方法的具體用法?Python Dependency.error怎麽用?Python Dependency.error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在common.utilities.inversion_of_control.Dependency的用法示例。


在下文中一共展示了Dependency.error方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestSQLLoggingHandler

# 需要導入模塊: from common.utilities.inversion_of_control import Dependency [as 別名]
# 或者: from common.utilities.inversion_of_control.Dependency import error [as 別名]
class TestSQLLoggingHandler(unittest.TestCase):

    def setUp(self):
        # register mocks
        register_mock_dependencies("DEBUG")

        # get other dependencies
        self.data_repository = Dependency("DataRepository").value

        # create config and change values before registering sql handler
        self._config = Dependency("Config").value
        # set the flush to be .5 seconds so that we can test quickly
        self._config.sql_logging_insert_timer = .1
        self._config.app_version = "9.9.9.9"
        self._config.environment = "unit test"

        # create logger with only SQLLoggingHandler
        self.logger = Dependency("LogManager").value
        self.logger.clear_logging_handlers()
        self.sql_handler = self.logger.add_sql_handler()

    def tearDown(self):
        self.sql_handler.wait_for_threads_to_finish()
        dependencies.clear()

    def test_basic_message(self):
        self.logger.debug("test message")

        # you need to sleep for one second so that the logger flushes correctly
        sleep(.3)

        # make sure only one record is present
        self.assertEqual(len(self.data_repository.logging_records), 1)

        # make sure values are correct
        record = self.data_repository.logging_records[0]
        self.assertEqual(record.log_entry_type_id, 5)
        self.assertEqual(record.version, "9.9.9.9")
        self.assertEqual(record.environment, "unit test")
        # process id is 234234234_process
        self.assertRegexpMatches(record.process_id, "\d*_.*")
        self.assertEqual(record.message.strip(), "test message")
        # compare timestamp without seconds
        utc = str(datetime.utcnow())
        self.assertEqual(utc.split()[0], record.time.split()[0])
        self.assertEqual(record.function_name, "test_sql_logging_handler.py__test_basic_message")
        self.assertIsNone(record.elapsed_time)

    def test_basic_message_with_elapsed_time(self):
        self.logger.debug("test message", elapsed_time=20.1)

        # you need to sleep for one second so that the logger flushes correctly
        sleep(.3)

        # make sure only one record is present
        self.assertEqual(len(self.data_repository.logging_records), 1)

        # make sure values are correct
        record = self.data_repository.logging_records[0]
        self.assertEqual(record.log_entry_type_id, 5)
        self.assertEqual(record.version, "9.9.9.9")
        self.assertEqual(record.environment, "unit test")
        # process id is 234234234_process
        self.assertRegexpMatches(record.process_id, "\d*_.*")
        self.assertEqual(record.message.strip(), "test message")
        # compare timestamp without seconds
        utc = str(datetime.utcnow())
        self.assertEqual(utc.split()[0], record.time.split()[0])
        self.assertEqual(record.function_name, "test_sql_logging_handler.py__test_basic_message_with_elapsed_time")
        self.assertEqual(record.elapsed_time, 20.1)

    def test_all_message_levels(self):
        """
        This test combines critical, error, warning, info, and debug together.
        This is done to save time since we have to wait for the flushing operation
        """
        self.logger.debug("test debug", elapsed_time=1.1)
        self.logger.info("test info", elapsed_time=2.2)
        self.logger.warning("test warning", elapsed_time=3.3)
        self.logger.error("test error", elapsed_time=4.4)
        self.logger.critical("test critical", elapsed_time=5.5)

        # you need to sleep for one second so that the logger flushes correctly
        sleep(.3)

        # make sure we have 5 records
        self.assertEqual(len(self.data_repository.logging_records), 5)

        # make sure every record's type is correct
        self.assertEqual(self.data_repository.logging_records[0].log_entry_type_id, 5)
        self.assertEqual(self.data_repository.logging_records[0].message.strip(), "test debug")
        self.assertEqual(self.data_repository.logging_records[0].elapsed_time, 1.1)
        self.assertEqual(self.data_repository.logging_records[1].log_entry_type_id, 4)
        self.assertEqual(self.data_repository.logging_records[1].message.strip(), "test info")
        self.assertEqual(self.data_repository.logging_records[1].elapsed_time, 2.2)
        self.assertEqual(self.data_repository.logging_records[2].log_entry_type_id, 3)
        self.assertEqual(self.data_repository.logging_records[2].message.strip(), "test warning")
        self.assertEqual(self.data_repository.logging_records[2].elapsed_time, 3.3)
        self.assertEqual(self.data_repository.logging_records[3].log_entry_type_id, 2)
        self.assertEqual(self.data_repository.logging_records[3].message.strip(), "test error")
#.........這裏部分代碼省略.........
開發者ID:erezrubinstein,項目名稱:aa,代碼行數:103,代碼來源:test_sql_logging_handler.py


注:本文中的common.utilities.inversion_of_control.Dependency.error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。