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


Python BaseSettings.getpriority方法代码示例

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


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

示例1: test_setitem

# 需要导入模块: from scrapy.settings import BaseSettings [as 别名]
# 或者: from scrapy.settings.BaseSettings import getpriority [as 别名]
 def test_setitem(self):
     settings = BaseSettings()
     settings.set('key', 'a', 'default')
     settings['key'] = 'b'
     self.assertEqual(settings['key'], 'b')
     self.assertEqual(settings.getpriority('key'), 20)
     settings['key'] = 'c'
     self.assertEqual(settings['key'], 'c')
     settings['key2'] = 'x'
     self.assertIn('key2', settings)
     self.assertEqual(settings['key2'], 'x')
     self.assertEqual(settings.getpriority('key2'), 20)
开发者ID:q1ang,项目名称:scrapy,代码行数:14,代码来源:__init__.py

示例2: test_update

# 需要导入模块: from scrapy.settings import BaseSettings [as 别名]
# 或者: from scrapy.settings.BaseSettings import getpriority [as 别名]
    def test_update(self):
        settings = BaseSettings({'key_lowprio': 0}, priority=0)
        settings.set('key_highprio', 10, priority=50)
        custom_settings = BaseSettings({'key_lowprio': 1, 'key_highprio': 11}, priority=30)
        custom_settings.set('newkey_one', None, priority=50)
        custom_dict = {'key_lowprio': 2, 'key_highprio': 12, 'newkey_two': None}

        settings.update(custom_dict, priority=20)
        self.assertEqual(settings['key_lowprio'], 2)
        self.assertEqual(settings.getpriority('key_lowprio'), 20)
        self.assertEqual(settings['key_highprio'], 10)
        self.assertIn('newkey_two', settings)
        self.assertEqual(settings.getpriority('newkey_two'), 20)

        settings.update(custom_settings)
        self.assertEqual(settings['key_lowprio'], 1)
        self.assertEqual(settings.getpriority('key_lowprio'), 30)
        self.assertEqual(settings['key_highprio'], 10)
        self.assertIn('newkey_one', settings)
        self.assertEqual(settings.getpriority('newkey_one'), 50)

        settings.update({'key_lowprio': 3}, priority=20)
        self.assertEqual(settings['key_lowprio'], 1)
开发者ID:q1ang,项目名称:scrapy,代码行数:25,代码来源:__init__.py

示例3: _map_keys

# 需要导入模块: from scrapy.settings import BaseSettings [as 别名]
# 或者: from scrapy.settings.BaseSettings import getpriority [as 别名]
 def _map_keys(compdict):
     if isinstance(compdict, BaseSettings):
         compbs = BaseSettings()
         for k, v in six.iteritems(compdict):
             prio = compdict.getpriority(k)
             if compbs.getpriority(convert(k)) == prio:
                 raise ValueError('Some paths in {!r} convert to the same '
                                  'object, please update your settings'
                                  ''.format(list(compdict.keys())))
             else:
                 compbs.set(convert(k), v, priority=prio)
         return compbs
     else:
         _check_components(compdict)
         return {convert(k): v for k, v in six.iteritems(compdict)}
开发者ID:nick198205,项目名称:scrapy,代码行数:17,代码来源:conf.py

示例4: BaseSettingsTest

# 需要导入模块: from scrapy.settings import BaseSettings [as 别名]
# 或者: from scrapy.settings.BaseSettings import getpriority [as 别名]
class BaseSettingsTest(unittest.TestCase):

    if six.PY3:
        assertItemsEqual = unittest.TestCase.assertCountEqual

    def setUp(self):
        self.settings = BaseSettings()

    def test_set_new_attribute(self):
        self.settings.set('TEST_OPTION', 'value', 0)
        self.assertIn('TEST_OPTION', self.settings.attributes)

        attr = self.settings.attributes['TEST_OPTION']
        self.assertIsInstance(attr, SettingsAttribute)
        self.assertEqual(attr.value, 'value')
        self.assertEqual(attr.priority, 0)

    def test_set_settingsattribute(self):
        myattr = SettingsAttribute(0, 30) # Note priority 30
        self.settings.set('TEST_ATTR', myattr, 10)
        self.assertEqual(self.settings.get('TEST_ATTR'), 0)
        self.assertEqual(self.settings.getpriority('TEST_ATTR'), 30)

    def test_set_instance_identity_on_update(self):
        attr = SettingsAttribute('value', 0)
        self.settings.attributes = {'TEST_OPTION': attr}
        self.settings.set('TEST_OPTION', 'othervalue', 10)

        self.assertIn('TEST_OPTION', self.settings.attributes)
        self.assertIs(attr, self.settings.attributes['TEST_OPTION'])

    def test_set_calls_settings_attributes_methods_on_update(self):
        attr = SettingsAttribute('value', 10)
        with mock.patch.object(attr, '__setattr__') as mock_setattr, \
                mock.patch.object(attr, 'set') as mock_set:

            self.settings.attributes = {'TEST_OPTION': attr}

            for priority in (0, 10, 20):
                self.settings.set('TEST_OPTION', 'othervalue', priority)
                mock_set.assert_called_once_with('othervalue', priority)
                self.assertFalse(mock_setattr.called)
                mock_set.reset_mock()
                mock_setattr.reset_mock()

    def test_setitem(self):
        settings = BaseSettings()
        settings.set('key', 'a', 'default')
        settings['key'] = 'b'
        self.assertEqual(settings['key'], 'b')
        self.assertEqual(settings.getpriority('key'), 20)
        settings['key'] = 'c'
        self.assertEqual(settings['key'], 'c')
        settings['key2'] = 'x'
        self.assertIn('key2', settings)
        self.assertEqual(settings['key2'], 'x')
        self.assertEqual(settings.getpriority('key2'), 20)

    def test_setdict_alias(self):
        with mock.patch.object(self.settings, 'set') as mock_set:
            self.settings.setdict({'TEST_1': 'value1', 'TEST_2': 'value2'}, 10)
            self.assertEqual(mock_set.call_count, 2)
            calls = [mock.call('TEST_1', 'value1', 10),
                     mock.call('TEST_2', 'value2', 10)]
            mock_set.assert_has_calls(calls, any_order=True)

    def test_setmodule_only_load_uppercase_vars(self):
        class ModuleMock():
            UPPERCASE_VAR = 'value'
            MIXEDcase_VAR = 'othervalue'
            lowercase_var = 'anothervalue'

        self.settings.attributes = {}
        self.settings.setmodule(ModuleMock(), 10)
        self.assertIn('UPPERCASE_VAR', self.settings.attributes)
        self.assertNotIn('MIXEDcase_VAR', self.settings.attributes)
        self.assertNotIn('lowercase_var', self.settings.attributes)
        self.assertEqual(len(self.settings.attributes), 1)

    def test_setmodule_alias(self):
        with mock.patch.object(self.settings, 'set') as mock_set:
            self.settings.setmodule(default_settings, 10)
            mock_set.assert_any_call('TEST_DEFAULT', 'defvalue', 10)
            mock_set.assert_any_call('TEST_DICT', {'key': 'val'}, 10)

    def test_setmodule_by_path(self):
        self.settings.attributes = {}
        self.settings.setmodule(default_settings, 10)
        ctrl_attributes = self.settings.attributes.copy()

        self.settings.attributes = {}
        self.settings.setmodule(
            'tests.test_settings.default_settings', 10)

        self.assertItemsEqual(six.iterkeys(self.settings.attributes),
                              six.iterkeys(ctrl_attributes))

        for key in six.iterkeys(ctrl_attributes):
            attr = self.settings.attributes[key]
            ctrl_attr = ctrl_attributes[key]
#.........这里部分代码省略.........
开发者ID:q1ang,项目名称:scrapy,代码行数:103,代码来源:__init__.py

示例5: test_getpriority

# 需要导入模块: from scrapy.settings import BaseSettings [as 别名]
# 或者: from scrapy.settings.BaseSettings import getpriority [as 别名]
 def test_getpriority(self):
     settings = BaseSettings({'key': 'value'}, priority=99)
     self.assertEqual(settings.getpriority('key'), 99)
     self.assertEqual(settings.getpriority('nonexistentkey'), None)
开发者ID:q1ang,项目名称:scrapy,代码行数:6,代码来源:__init__.py


注:本文中的scrapy.settings.BaseSettings.getpriority方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。