def test_get_raise_no_option_error(self): target = Config() try: target.get('SomeNotExistOption') self.fail('No Error caught') except NoOptionError: pass v = target.get('SomeNotExistOption', 'DefaultValue') self.assertEqual(v, 'DefaultValue')
def upgrade(): ioloop = IOLoop.current() config = Config() runner_factory = RunnerFactory(config) with session_scope() as session: for project in session.query(Project): if project.package is not None: continue storage = ProjectStorage(config.get('project_storage_dir'), project) version, eggf = storage.get_egg() runner = runner_factory.build(eggf) try: project_settings_module = ioloop.run_sync( runner.settings_module) spider_list = ioloop.run_sync(runner.list) package = ProjectPackage() package.project = project package.type = 'scrapy' package.settings_module = project_settings_module package.spider_list = ','.join(spider_list) session.add(package) session.commit() except (ProcessFailed, InvalidProjectEgg) as ex: logger.error(ex)
def test_get(self): target = Config() self.assertEqual('0.0.0.0', target.get('bind_address'))
def test_get_from_values(self): target = Config(values={'SomeSetting': 'Value'}) self.assertEqual('Value', target.get('SomeSetting'))
def test_get_from_env(self): target = Config() database_url = 'sqlite:///test.db' os.environ['SCRAPYDD_DATABASE_URL'] = 'sqlite:///test.db' self.assertEqual( database_url,target.get('database_url')) del os.environ['SCRAPYDD_DATABASE_URL']