def _load(self): """Load all needed special articles. This is done not at __init__ time because some of this are dynamically generated files, so doesn't need to happen at import time. """ viparts = self._vip_articles = {} # some manually curated pages if config.DESTACADOS is not None: with open(config.DESTACADOS, 'rt', encoding='utf8') as fh: viparts.update( {to3dirs._quote(line.strip()): 1 for line in fh}) # must include according to the config viparts.update({include: 2 for include in config.langconf['include']}) # portal articles from the front-page portal, itself included viparts.update({config.langconf['portal_index']: 2}) _path = os.path.join(config.DIR_TEMP, 'portal_pages.txt') with open(_path, 'rt', encoding='utf-8') as fh: viparts.update({to3dirs._quote(line.strip()): 2 for line in fh}) # add test-infra articles if test mode is enable. if config.TEST_MODE: src = test_infra.TEST_INFRA_FILENAME article_names = test_infra.parse_test_infra_file(src) viparts.update( {to3dirs._quote(line[0]): 3 for line in article_names}) logger.info("Loaded %d VIP articles", len(viparts))
def enable_test_infra(): """Enable test infra web app feature. Copy data file to web assets dir and scrape required articles. """ src = test_infra.TEST_INFRA_FILENAME # file in project root data = test_infra.parse_test_infra_file(src) articles = [d[0] for d in data] logger.info("Scraping test infra articles") with NamedTemporaryFile('wt', encoding='utf8', dir='/tmp/', prefix='cdpedia-') as tf: tf.write('\n'.join(articles) + '\n') tf.flush() _call_scraper(config.LANGUAGE, tf.name) dst = os.path.join(location.resources, src) if not os.path.isfile(dst): os.link(src, dst)
def test_parsing_test_infra_file_empty_section(mocker, test_infra_file): """Return empty list if section is empty.""" mocker.patch('config.LANGUAGE', 'ay') data = parse_test_infra_file(test_infra_file) assert data == []
def test_parsing_test_infra_file_not_existing_section(mocker, test_infra_file): """Return empty list if section not found.""" mocker.patch('config.LANGUAGE', 'xy') data = parse_test_infra_file(test_infra_file) assert data == []
def test_parsing_test_infra_file_load_other_language(mocker, test_infra_file): """All non empty lines not starting by '#' should be a page to check.""" mocker.patch('config.LANGUAGE', 'fr') data = parse_test_infra_file(test_infra_file) assert data == [('Château', "Image galleries shouldn't overflow")]
def test_parsing_test_infra_file_read_empty_check(test_infra_file): """No check after title should be interpreted as None.""" data = parse_test_infra_file(test_infra_file) name = 'Satélites_de_Saturno' assert (name, None) in data
def test_parsing_test_infra_file_read_name_and_check(test_infra_file): """Article name and check to do should be loaded in a tuple.""" data = parse_test_infra_file(test_infra_file) name = 'Portal:Portada' check = 'Check page looks OK' assert (name, check) in data
def test_parsing_test_infra_file_items_number(test_infra_file): """All non empty lines not starting by '#' should be a page to check.""" data = parse_test_infra_file(test_infra_file) assert len(data) == 3