Ejemplo n.º 1
0
def test_href_url_same_suffix():
    f = e.css('#links a') | e.href_url_same_suffix
    res = f(create_response(example))
    # we want the result to be an iterable, but not a list
    assert hasattr(res, '__iter__')
    assert not isinstance(res, list)
    assert list(res) == ['http://base.com/1', 'http://subdomain.base.com/2']
Ejemplo n.º 2
0
def test_href_url_same_suffix():
    f = e.css('#links a') | e.href_url_same_suffix
    res = f(create_response(example))
    # we want the result to be an iterable, but not a list
    assert hasattr(res, '__iter__')
    assert not isinstance(res, list)
    assert list(res) == ['http://base.com/1', 'http://subdomain.base.com/2']
Ejemplo n.º 3
0
def test_text_content_with_br():
    f = e.css('#br') | e.text_content
    assert f(create_response(example)) == ['oh\nmy']
Ejemplo n.º 4
0
def test_text():
    f = e.css('h1') | e.text | list
    assert f(create_response(example)) == ['hi']
Ejemplo n.º 5
0
def test_href_url_single():
    f = e.css('#div1 a') | item0 | e.href_url
    assert f(create_response(example)) == 'http://base.com/1'
Ejemplo n.º 6
0
def test_img_src():
    f = e.css('img') | e.src_url
    res = f(create_response(example))
    assert hasattr(res, '__iter__')
    assert not isinstance(res, list)
    assert list(res) == ['http://other.com/src']
Ejemplo n.º 7
0
def test_attrib():
    f = e.css('#div1 a') | e.attrib('href') | list
    r = create_response(example)
    assert f(r) == ['/1', ' /2 ', None]
Ejemplo n.º 8
0
def test_css():
    f = e.css('h1')
    response = create_response(example)
    res = f(response)
    assert isinstance(res, list)
    assert [elem.tag for elem in res] == ['h1']
Ejemplo n.º 9
0
def test_normalize_space_nbsp():
    f = e.css('#nbsp') | e.normalize_space
    assert f(create_response(example)) == ['']
Ejemplo n.º 10
0
def test_href_url_single():
    f = e.css('#div1 a') | item0 | e.href_url
    assert f(create_response(example)) == 'http://base.com/1'
Ejemplo n.º 11
0
def test_img_src():
    f = e.css('img') | e.src_url
    res = f(create_response(example))
    assert hasattr(res, '__iter__')
    assert not isinstance(res, list)
    assert list(res) == ['http://other.com/src']
Ejemplo n.º 12
0
def test_attrib_default():
    f = e.css('#div1 a') | e.attrib('nosuch', '') | list
    assert f(create_response(example)) == ['', '', '']
Ejemplo n.º 13
0
def test_attrib():
    f = e.css('#div1 a') | e.attrib('href') | list
    r = create_response(example)
    assert f(r) == ['/1', ' /2 ', None]
Ejemplo n.º 14
0
def test_css_called_twice():
    f = e.css('h1')
    response = create_response(example)
    with Cache():
        assert f(response)== f(response)
Ejemplo n.º 15
0
def test_list_normalize_space():
    func = e.css('ul li') | e.normalize_space
    assert func(create_response(example)) == ['1', '', '2']
Ejemplo n.º 16
0
def test_itertext():
    f = e.css('.thing') | e.itertext() | flatten | list
    expected = ['First ', 'one thing', 'then ', 'another thing', '.']
    assert f(create_response(example)) == expected
Ejemplo n.º 17
0
def test_href_empty():
    f = e.css('#nosuch') | e.href_url | list
    assert f(create_response(example)) == []
Ejemplo n.º 18
0
def test_css():
    f = e.css('h1')
    response = create_response(example)
    res = f(response)
    assert isinstance(res, list)
    assert [elem.tag for elem in res] == ['h1']
Ejemplo n.º 19
0
def test_text():
    f = e.css('h1') | e.text | list
    assert f(create_response(example)) == ['hi']
Ejemplo n.º 20
0
def test_css_called_twice():
    f = e.css('h1')
    response = create_response(example)
    with Cache():
        assert f(response) == f(response)
Ejemplo n.º 21
0
def test_nbsp():
    func = e.css('#nbsp') | e.itertext() | list
    assert func(create_response(example)) == [u'\xa0\xa0']
Ejemplo n.º 22
0
def test_attrib_default():
    f = e.css('#div1 a') | e.attrib('nosuch', '') | list
    assert f(create_response(example)) == ['', '', '']
Ejemplo n.º 23
0
def test_text_content_with_br():
    f = e.css('#br') | e.text_content
    assert f(create_response(example)) == ['oh\nmy']
Ejemplo n.º 24
0
def test_list_text_content():
    func = e.css('ul li') | e.text_content
    assert func(create_response(example)) == [' 1', '', '2 ']
Ejemplo n.º 25
0
def test_list_normalize_space():
    func = e.css('ul li') | e.normalize_space
    assert func(create_response(example)) == ['1', '', '2']
Ejemplo n.º 26
0
def test_href_empty():
    f = e.css('#nosuch') | e.href_url | list
    assert f(create_response(example)) == []
Ejemplo n.º 27
0
def test_href_when_url_contains_dodgy_characters():
    f = e.css('a') | e.href_url | list
    r = create_response(example_with_dodgy_url)
    # This will fail if we don't quote/unquote the base_url
    assert f(r) == ['http://foo.com/1']
Ejemplo n.º 28
0
def test_nbsp():
    func = e.css('#nbsp') | e.itertext() | list
    assert func(create_response(example)) == [u'\xa0\xa0']
Ejemplo n.º 29
0
def test_itertext():
    f = e.css('.thing') | e.itertext() | flatten | list
    expected = ['First ', 'one thing', 'then ', 'another thing', '.']
    assert f(create_response(example)) == expected
Ejemplo n.º 30
0
def test_list_text_content():
    func = e.css('ul li') | e.text_content
    assert func(create_response(example)) == [' 1', '', '2 ']
Ejemplo n.º 31
0
def test_itertext_elem():
    f = e.css('.thing') | first | e.itertext() | list
    expected = ['First ', 'one thing']
    assert f(create_response(example)) == expected
Ejemplo n.º 32
0
def test_href_when_url_contains_non_ascii_characters():
    f = e.css('a') | e.href_url | list
    r = create_response(example_with_non_ascii_url)
    assert f(r) == ['http://foo.com/bar™/1']
Ejemplo n.º 33
0
def test_normalize_space_nbsp():
    f = e.css('#nbsp') | e.normalize_space
    assert f(create_response(example)) == ['']
Ejemplo n.º 34
0
def test_itertext_elem():
    f = e.css('.thing') | first | e.itertext() | list
    expected = ['First ', 'one thing']
    assert f(create_response(example)) == expected
Ejemplo n.º 35
0
def test_drop_tree():
    f = (e.xpath('//*[@id="drop-tree"]') |
         e.drop_tree(e.css('script')) |
         e.xpath('string()'))
    assert f(create_response(example)) == ['Drop this please.']
Ejemplo n.º 36
0
def test_drop_tree():
    f = (e.xpath('//*[@id="drop-tree"]') | e.drop_tree(e.css('script'))
         | e.xpath('string()'))
    assert f(create_response(example)) == ['Drop this please.']
Ejemplo n.º 37
0
def test_href_when_url_contains_non_ascii_characters():
    f = e.css('a') | e.href_url | list
    r = create_response(example_with_non_ascii_url)
    assert f(r) == ['http://foo.com/bar™/1']