当前位置: 首页>>代码示例>>Python>>正文


Python Dependency.warning方法代码示例

本文整理汇总了Python中common.utilities.inversion_of_control.Dependency.warning方法的典型用法代码示例。如果您正苦于以下问题:Python Dependency.warning方法的具体用法?Python Dependency.warning怎么用?Python Dependency.warning使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common.utilities.inversion_of_control.Dependency的用法示例。


在下文中一共展示了Dependency.warning方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CompetitiveStoreHelper

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import warning [as 别名]
class CompetitiveStoreHelper(object):
    """
    This class represents a set of competitive stores belonging to one home store and one trade area
    This is not a standard business object.  Rather, it is more like a cloud_provider, which helps us synchronize sets of competitive stores.
    """
    def __init__(self, home_store, away_stores, trade_area_id, data_repository):
        self.home_store = home_store
        self.away_stores = away_stores
        self.trade_area_id  = trade_area_id
        self.data_repository = data_repository
        self.is_sql_data_repository = hasattr(self.data_repository, "is_sql") and self.data_repository.is_sql

        # get dependencies
        self._log = Dependency("LogManager").value

        # query the current set of competitive stores, which we need to do the diffs
        self.previous_away_stores = self.data_repository.get_competitive_stores(self.home_store.store_id, self.trade_area_id)

    def synchronize_competitive_stores_in_db(self):
        """
        This method synchronizes the competitive stores:
           - new stores are added
           - existing stores are updated
           - deleted stores are marked with an end_date
        """

        # figure out if there are any stores whose competitive record "disappeared"
        stores_to_close = set(self.previous_away_stores) - set(self.away_stores)

        # if any competitive store disappeared, log an error.  Used to raise an exception, but we changed this for core.
        if len(stores_to_close) > 0:

            # log a warning.  no need to delete these, since core will "update" them away.  this does not happen in SQL
            self._log.warning("several away stores (%s) have disappeared from the list." % str([store.away_store_id for store in stores_to_close]))

        # insert/update new away stores
        batch_competitive_stores = []
        if self.away_stores and len(self.away_stores) > 0:
            batch_competitive_stores = self._upsert_new_away_stores()

        # !IMP! this is for forward compatibility (i.e. the core mongo code)
        # always call, even if it's an empty array
        self.data_repository.batch_upsert_competitive_stores(self.trade_area_id, batch_competitive_stores)


    def synchronize_monopolies_in_db(self):
        """
        This method synchronizes the monopoly record:
           - new monopoly is inserted
           - old monopoly is closed
           - updated monopoly is closed, and then a new one is inserted
        """

        # get all current competitive stores (include closed ones)
        competitive_store_instances = self.data_repository.get_competitive_stores(self.home_store.store_id, self.trade_area_id)

        # delete all monopolies
        self.data_repository.delete_from_monopolies(self.home_store.store_id, self.trade_area_id)

        # declare batch monopolies list for later insertion.  SQL Repository inserts one by one.  Only Core batches.
        batch_monopolies_list = []

        # if there are competitive store instances, figure out historical monopolies
        if competitive_store_instances:
            # figure out new monopoly date range
            transition_parameters = self._get_monopoly_transition_parameters(competitive_store_instances)

            # transition each range
            for transition in transition_parameters:
                # transitioning monopolies is very complex.  We are delegating it to a specific _cloud_provider file
                MonopolyTransitionHelper.transition_monopoly_record(self.home_store, self.trade_area_id, transition.away_stores, transition.previous_away_stores,
                    self.data_repository, batch_monopolies_list)

        # complete monopoly always!!!
        else:
            MonopolyTransitionHelper.transition_monopoly_record(self.home_store, self.trade_area_id, [], [],
                self.data_repository, batch_monopolies_list)


        # if home store closes, make sure to always close that monopoly
        # Erez - I feel like this should never need to happen, but I remember a certain scenario where we needed it
        if self.home_store._assumed_closed_date is not None and self.home_store._assumed_closed_date != END_OF_WORLD:
            self.data_repository.close_monopoly_record(self.home_store.store_id, self.trade_area_id, self.home_store._assumed_closed_date, batch_monopolies_list)


        # batch upsert monopolies (Only in core.  This does nothing in SQL data repository)
        self.data_repository.batch_upsert_monopolies(self.trade_area_id, batch_monopolies_list)



    # -------------------------------------------- Private Methods --------------------------------------------

    def _upsert_new_away_stores(self):

        batch_competitive_stores = []

        # !IMP! the for loop is for backwards compatibility for the SQL code.  CoreDataRepository ignores this.
        for away_store in self.away_stores:

            # figure out the opened date for the store (either it's the store's opened date or the home store's opened date.  whichever is later)
#.........这里部分代码省略.........
开发者ID:erezrubinstein,项目名称:aa,代码行数:103,代码来源:competitive_store_helper.py

示例2: TestSQLLoggingHandler

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import warning [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.warning方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。