Exemplo n.º 1
0
def test_find_multiple(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("div", {"class": "baz"})
    if len(result) != 2:
        raise AssertionError
    if str(result[1]) != '<div class="baz">Oh No!</div>':
        raise AssertionError
Exemplo n.º 2
0
def test_find_with_attrs(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("p", {"id": "blarg"})
    assert str(result) == '<p id="blarg">Try for 2</p>'
Exemplo n.º 3
0
def test_undocumented_random_mode(fake_html_6):
    soup = Soup(fake_html_6)
    pset = set([soup.find("p", mode="random").attrs["id"] for _ in range(10)])
    if len(pset) <= 1:
        raise AssertionError
Exemplo n.º 4
0
def test_find_strict(fake_html_2):
    with pytest.warns(FutureWarning):
        soup = Soup(fake_html_2)
        soup.find("div", {"class": "foo"}, strict=True)
Exemplo n.º 5
0
def test_find_no_match_auto(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("a", mode="auto")
    if result is not None:
        raise AssertionError
Exemplo n.º 6
0
def test_find_mutliple_imgs(fake_html_3):
    soup = Soup(fake_html_3)
    middle = soup.find("img")[1]
    if middle.attrs["src"] != "bye.jpg":
        raise AssertionError
Exemplo n.º 7
0
def test_find_partial_false(fake_html_2):
    soup = Soup(fake_html_2)
    result = soup.find("div", {"class": "foo"}, partial=False, mode="all")
    if len(result) != 1:
        raise AssertionError
Exemplo n.º 8
0
def test_find_text(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("p", {"id": "blarg"})
    if result.text != "Try for 2":
        raise AssertionError
Exemplo n.º 9
0
def test_find_no_match_first(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("a", mode="first")
    assert result == None
Exemplo n.º 10
0
def test_find_mutliple_imgs(fake_html_3):
    soup = Soup(fake_html_3)
    middle = soup.find("img")[1]
    assert middle.attrs["src"] == "bye.jpg"
Exemplo n.º 11
0
def test_find_nested_empty_tag(fake_html_3):
    soup = Soup(fake_html_3)
    result = soup.find("a", {"class": "foo"})
    assert len(result) == 2
Exemplo n.º 12
0
def test_find_partial_false(fake_html_2):
    soup = Soup(fake_html_2)
    result = soup.find("div", {"class": "foo"}, partial=False, mode="all")
    assert len(result) == 1
Exemplo n.º 13
0
def test_find_nested_groups(fake_html_2):
    soup = Soup(fake_html_2)
    results = soup.find("div", {"class": "foo"})
    assert len(results) == 2
Exemplo n.º 14
0
def test_find_text(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("p", {"id": "blarg"})
    assert result.text == "Try for 2"
Exemplo n.º 15
0
def test_find_multiple(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("div", {"class": "baz"})
    assert len(result) == 2
    assert str(result[1]) == '<div class="baz">Oh No!</div>'
Exemplo n.º 16
0
def test_find_with_attrs(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("p", {"id": "blarg"})
    if str(result) != '<p id="blarg">Try for 2</p>':
        raise AssertionError
Exemplo n.º 17
0
def test_find_no_match_all(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("a", mode="all")
    assert result == []
Exemplo n.º 18
0
def test_find_no_match_auto(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("a", mode="auto")
    assert result == None
Exemplo n.º 19
0
def test_find_nested_groups(fake_html_2):
    soup = Soup(fake_html_2)
    results = soup.find("div", {"class": "foo"})
    if len(results) != 2:
        raise AssertionError
Exemplo n.º 20
0
def test_malformed_void_tags(fake_html_5):
    soup = Soup(fake_html_5)
    result = soup.find("img")
    assert len(result) == 3
Exemplo n.º 21
0
def test_find_nested_empty_tag(fake_html_3):
    soup = Soup(fake_html_3)
    result = soup.find("a", {"class": "foo"})
    if len(result) != 2:
        raise AssertionError
Exemplo n.º 22
0
def test_undocumented_random_mode(fake_html_6):
    soup = Soup(fake_html_6)
    pset = set([soup.find("p", mode="random").attrs["id"] for _ in range(10)])
    assert len(pset) > 1
Exemplo n.º 23
0
def test_find_no_match_all(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("a", mode="all")
    if result != []:
        raise AssertionError
Exemplo n.º 24
0
def test_undocumented_last_mode(fake_html_6):
    soup = Soup(fake_html_6)
    assert soup.find("p", mode="last").text == "G"
Exemplo n.º 25
0
def test_malformed_void_tags(fake_html_5):
    soup = Soup(fake_html_5)
    result = soup.find("img")
    if len(result) != 3:
        raise AssertionError
Exemplo n.º 26
0
def test_find(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("span")
    if str(result) != "<span>Hi</span>":
        raise AssertionError
Exemplo n.º 27
0
def test_bad_mode_argument(fake_html_1):
    with pytest.raises(ValueError):
        soup = Soup(fake_html_1)
        soup.find("div", mode="bad")
Exemplo n.º 28
0
def test_find_first(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("p", mode="first")
    if str(result) != "<p>'IDK!'</p>":
        raise AssertionError
Exemplo n.º 29
0
def test_undocumented_last_mode(fake_html_6):
    soup = Soup(fake_html_6)
    if soup.find("p", mode="last").text != "G":
        raise AssertionError
Exemplo n.º 30
0
def test_find_first(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("p", mode="first")
    assert str(result) == "<p>'IDK!'</p>"