コード例 #1
0
def test_gen_html_content():
    tasks._gen_html(SPIDER_NAME, SPIDER_START_URLS)
    test_file_content = read_test_file_content(
        'files/testspider_articles.html.example')
    rendered_content = read_test_file_content('files/testspider_articles.html')
    test_dom = fromstring(test_file_content)
    rendered_dom = fromstring(rendered_content)
    test_title = test_dom.xpath('//title')[0].text
    rendered_title = rendered_dom.xpath('//title')[0].text
    assert test_title == rendered_title
コード例 #2
0
def test_gen_html_filenames():
    FILES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')
    test_filenames = [FILES_DIR + '/testspider_articles.html', FILES_DIR + '/testspider_staff.html', FILES_DIR + '/testspider_is-chicago-any-less-segregated.html']
    rendered_filenames = tasks._gen_html(SPIDER_NAME, SPIDER_START_URLS)
    assert rendered_filenames == test_filenames

    if rendered_filenames == test_filenames:
        for f in rendered_filenames:
            os.remove(f)
コード例 #3
0
def test_gen_html_content():
    with recorder.use_cassette('test_gen_html_content'):
        rendered_filenames = tasks._gen_html(SPIDER_NAME,
                                             SPIDER_START_URLS,
                                             session=session)
    test_file_content = read_test_file_content(
        'files/testspider_articles.html.example')
    rendered_content = read_test_file_content('files/testspider_articles.html')
    test_dom = fromstring(test_file_content)
    rendered_dom = fromstring(rendered_content)
    test_title = test_dom.xpath('//title')[0].text
    rendered_title = rendered_dom.xpath('//title')[0].text
    assert test_title == rendered_title

    if test_title == rendered_title:
        for f in rendered_filenames:
            os.remove(f)