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


Python BaseSettings.maxpriority方法代碼示例

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


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

示例1: BaseSettingsTest

# 需要導入模塊: from scrapy.settings import BaseSettings [as 別名]
# 或者: from scrapy.settings.BaseSettings import maxpriority [as 別名]

#.........這裏部分代碼省略.........
        self.assertEqual(settings['TEST_STRx'], None)
        self.assertEqual(settings.get('TEST_STRx'), None)
        self.assertEqual(settings.get('TEST_STRx', 'default'), 'default')
        self.assertEqual(settings.getdict('TEST_DICT1'), {'key1': 'val1', 'ke2': 3})
        self.assertEqual(settings.getdict('TEST_DICT2'), {'key1': 'val1', 'ke2': 3})
        self.assertEqual(settings.getdict('TEST_DICT3'), {})
        self.assertEqual(settings.getdict('TEST_DICT3', {'key1': 5}), {'key1': 5})
        self.assertRaises(ValueError, settings.getdict, 'TEST_LIST1')

    def test_getpriority(self):
        settings = BaseSettings({'key': 'value'}, priority=99)
        self.assertEqual(settings.getpriority('key'), 99)
        self.assertEqual(settings.getpriority('nonexistentkey'), None)

    def test_getcomposite(self):
        s = BaseSettings({'TEST_BASE': {1: 1, 2: 2},
                          'TEST': BaseSettings({1: 10, 3: 30}, 'default'),
                          'HASNOBASE': BaseSettings({1: 1}, 'default')})
        s['TEST'].set(4, 4, priority='project')
        # When users specify a _BASE setting they explicitly don't want to use
        # Scrapy's defaults, so we don't want to see anything that has a
        # 'default' priority from TEST
        cs = s._getcomposite('TEST')
        self.assertEqual(len(cs), 3)
        self.assertEqual(cs[1], 1)
        self.assertEqual(cs[2], 2)
        self.assertEqual(cs[4], 4)
        cs = s._getcomposite('HASNOBASE')
        self.assertEqual(len(cs), 1)
        self.assertEqual(cs[1], 1)
        cs = s._getcomposite('NONEXISTENT')
        self.assertIsNone(cs)

    def test_maxpriority(self):
        # Empty settings should return 'default'
        self.assertEqual(self.settings.maxpriority(), 0)
        self.settings.set('A', 0, 10)
        self.settings.set('B', 0, 30)
        self.assertEqual(self.settings.maxpriority(), 30)

    def test_copy(self):
        values = {
            'TEST_BOOL': True,
            'TEST_LIST': ['one', 'two'],
            'TEST_LIST_OF_LISTS': [['first_one', 'first_two'],
                                   ['second_one', 'second_two']]
        }
        self.settings.setdict(values)
        copy = self.settings.copy()
        self.settings.set('TEST_BOOL', False)
        self.assertTrue(copy.get('TEST_BOOL'))

        test_list = self.settings.get('TEST_LIST')
        test_list.append('three')
        self.assertListEqual(copy.get('TEST_LIST'), ['one', 'two'])

        test_list_of_lists = self.settings.get('TEST_LIST_OF_LISTS')
        test_list_of_lists[0].append('first_three')
        self.assertListEqual(copy.get('TEST_LIST_OF_LISTS')[0],
                             ['first_one', 'first_two'])

    def test_freeze(self):
        self.settings.freeze()
        with self.assertRaises(TypeError) as cm:
            self.settings.set('TEST_BOOL', False)
            self.assertEqual(str(cm.exception),
開發者ID:q1ang,項目名稱:scrapy,代碼行數:70,代碼來源:__init__.py


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