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