Beispiel #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
Beispiel #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>'
Beispiel #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
Beispiel #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)
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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"
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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"
Beispiel #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>'
Beispiel #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
Beispiel #17
0
def test_find_no_match_all(fake_html_1):
    soup = Soup(fake_html_1)
    result = soup.find("a", mode="all")
    assert result == []
Beispiel #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
Beispiel #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
Beispiel #20
0
def test_malformed_void_tags(fake_html_5):
    soup = Soup(fake_html_5)
    result = soup.find("img")
    assert len(result) == 3
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #24
0
def test_undocumented_last_mode(fake_html_6):
    soup = Soup(fake_html_6)
    assert soup.find("p", mode="last").text == "G"
Beispiel #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
Beispiel #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
Beispiel #27
0
def test_bad_mode_argument(fake_html_1):
    with pytest.raises(ValueError):
        soup = Soup(fake_html_1)
        soup.find("div", mode="bad")
Beispiel #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
Beispiel #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
Beispiel #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>"