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


Python Settings.getlist方法代码示例

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


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

示例1: test_get

# 需要导入模块: from scrapy.settings import Settings [as 别名]
# 或者: from scrapy.settings.Settings import getlist [as 别名]
 def test_get(self):
     settings = Settings({
         'TEST_ENABLED1': '1',
         'TEST_ENABLED2': True,
         'TEST_ENABLED3': 1,
         'TEST_DISABLED1': '0',
         'TEST_DISABLED2': False,
         'TEST_DISABLED3': 0,
         'TEST_INT1': 123,
         'TEST_INT2': '123',
         'TEST_FLOAT1': 123.45,
         'TEST_FLOAT2': '123.45',
         'TEST_LIST1': ['one', 'two'],
         'TEST_LIST2': 'one,two',
         'TEST_STR': 'value',
         'TEST_DICT1': {'key1': 'val1', 'ke2': 3},
         'TEST_DICT2': '{"key1": "val1", "ke2": 3}',
     })
     assert settings.getbool('TEST_ENABLED1') is True
     assert settings.getbool('TEST_ENABLED2') is True
     assert settings.getbool('TEST_ENABLED3') is True
     assert settings.getbool('TEST_ENABLEDx') is False
     assert settings.getbool('TEST_ENABLEDx', True) is True
     assert settings.getbool('TEST_DISABLED1') is False
     assert settings.getbool('TEST_DISABLED2') is False
     assert settings.getbool('TEST_DISABLED3') is False
     self.assertEqual(settings.getint('TEST_INT1'), 123)
     self.assertEqual(settings.getint('TEST_INT2'), 123)
     self.assertEqual(settings.getint('TEST_INTx'), 0)
     self.assertEqual(settings.getint('TEST_INTx', 45), 45)
     self.assertEqual(settings.getfloat('TEST_FLOAT1'), 123.45)
     self.assertEqual(settings.getfloat('TEST_FLOAT2'), 123.45)
     self.assertEqual(settings.getfloat('TEST_FLOATx'), 0.0)
     self.assertEqual(settings.getfloat('TEST_FLOATx', 55.0), 55.0)
     self.assertEqual(settings.getlist('TEST_LIST1'), ['one', 'two'])
     self.assertEqual(settings.getlist('TEST_LIST2'), ['one', 'two'])
     self.assertEqual(settings.getlist('TEST_LISTx'), [])
     self.assertEqual(
         settings.getlist('TEST_LISTx', ['default']), ['default'])
     self.assertEqual(settings['TEST_STR'], 'value')
     self.assertEqual(settings.get('TEST_STR'), 'value')
     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')
开发者ID:pyarnold,项目名称:scrapy,代码行数:54,代码来源:test_settings.py

示例2: test_get

# 需要导入模块: from scrapy.settings import Settings [as 别名]
# 或者: from scrapy.settings.Settings import getlist [as 别名]
 def test_get(self):
     settings = Settings({
         'TEST_ENABLED1': '1',
         'TEST_ENABLED2': True,
         'TEST_ENABLED3': 1,
         'TEST_DISABLED1': '0',
         'TEST_DISABLED2': False,
         'TEST_DISABLED3': 0,
         'TEST_INT1': 123,
         'TEST_INT2': '123',
         'TEST_FLOAT1': 123.45,
         'TEST_FLOAT2': '123.45',
         'TEST_LIST1': ['one', 'two'],
         'TEST_LIST2': 'one,two',
         'TEST_STR': 'value',
     })
     assert settings.getbool('TEST_ENABLED1') is True
     assert settings.getbool('TEST_ENABLED2') is True
     assert settings.getbool('TEST_ENABLED3') is True
     assert settings.getbool('TEST_ENABLEDx') is False
     assert settings.getbool('TEST_ENABLEDx', True) is True
     assert settings.getbool('TEST_DISABLED1') is False
     assert settings.getbool('TEST_DISABLED2') is False
     assert settings.getbool('TEST_DISABLED3') is False
     self.assertEqual(settings.getint('TEST_INT1'), 123)
     self.assertEqual(settings.getint('TEST_INT2'), 123)
     self.assertEqual(settings.getint('TEST_INTx'), 0)
     self.assertEqual(settings.getint('TEST_INTx', 45), 45)
     self.assertEqual(settings.getfloat('TEST_FLOAT1'), 123.45)
     self.assertEqual(settings.getfloat('TEST_FLOAT2'), 123.45)
     self.assertEqual(settings.getfloat('TEST_FLOATx'), 0.0)
     self.assertEqual(settings.getfloat('TEST_FLOATx', 55.0), 55.0)
     self.assertEqual(settings.getlist('TEST_LIST1'), ['one', 'two'])
     self.assertEqual(settings.getlist('TEST_LIST2'), ['one', 'two'])
     self.assertEqual(settings.getlist('TEST_LISTx'), [])
     self.assertEqual(settings.getlist('TEST_LISTx', ['default']), ['default'])
     self.assertEqual(settings['TEST_STR'], 'value')
     self.assertEqual(settings.get('TEST_STR'), 'value')
     self.assertEqual(settings['TEST_STRx'], None)
     self.assertEqual(settings.get('TEST_STRx'), None)
     self.assertEqual(settings.get('TEST_STRx', 'default'), 'default')
开发者ID:073palmer,项目名称:scrapy,代码行数:43,代码来源:test_settings.py


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