Exemplo n.º 1
0
 def handle_starttag(self, tag, attrs):
     html, attrs = html_starttag_and_attrs(tag, attrs)
     if tag == self.tag and match(self.attrs, attrs) and not self.count:
         self.count += 1
         self.group += 1
         self.groups.append(Soup(''))
         self.groups[self.group - 1].html += html
         self.groups[self.group - 1].tag = tag
         self.groups[self.group - 1].attrs = attrs
         return
     if self.count:
         self.count += 1
         self.groups[self.group - 1].html += html
         return
     else:
         return
Exemplo n.º 2
0
def test_match_partial():
    a = {"foo": "bar"}
    b = {"foo": "bar baz"}
    assert match(a, b, partial=True)
Exemplo n.º 3
0
def test_match_empty_attrs_fail():
    a = {"foo": "bar"}
    b = {}
    assert not match(a, b)
Exemplo n.º 4
0
def test_match_empty_empty():
    a = {}
    b = {}
    assert match(a, b)
Exemplo n.º 5
0
def test_attr_match_query_empty():
    a = {}
    b = {"foo": "bar"}
    assert match(a, b)
Exemplo n.º 6
0
def test_attr_match_query_empty():
    a = {}
    b = {"foo": "bar"}
    if not match(a, b):
        raise AssertionError
Exemplo n.º 7
0
def test_multiple_partial_fail():
    a = {"foo1": "bar1", "foo2": "bar2"}
    b = {"foo1": "bar1 baz1", "foo2": "bar2"}
    assert not match(a, b, partial=False)
Exemplo n.º 8
0
def test_match_query_too_much_fail():
    a = {"foo1": "bar1 baz1", "foo2": "bar2"}
    b = {"foo1": "bar1", "foo2": "bar2"}
    assert not match(a, b)
Exemplo n.º 9
0
def test_match_query_too_much_fail():
    a = {"foo1": "bar1 baz1", "foo2": "bar2"}
    b = {"foo1": "bar1", "foo2": "bar2"}
    if match(a, b):
        raise AssertionError
Exemplo n.º 10
0
def test_match_multiple_fail():
    a = {"foo1": "bar1", "foo2": "bar2"}
    b = {"foo1": "bar1", "foo2": "baz1"}
    if match(a, b):
        raise AssertionError
Exemplo n.º 11
0
def test_match_multiple():
    a = {"foo1": "bar1", "foo2": "bar2"}
    b = {"foo1": "bar1", "foo2": "bar2"}
    if not match(a, b):
        raise AssertionError
Exemplo n.º 12
0
def test_match_partial():
    a = {"foo": "bar"}
    b = {"foo": "bar baz"}
    if not match(a, b, partial=True):
        raise AssertionError
Exemplo n.º 13
0
def test_match_empty_attrs_fail():
    a = {"foo": "bar"}
    b = {}
    if match(a, b):
        raise AssertionError
Exemplo n.º 14
0
def test_match_empty_empty():
    a = {}
    b = {}
    if not match(a, b):
        raise AssertionError
Exemplo n.º 15
0
def test_match_multiple():
    a = {"foo1": "bar1", "foo2": "bar2"}
    b = {"foo1": "bar1", "foo2": "bar2"}
    assert match(a, b)
Exemplo n.º 16
0
def test_match_multiple_fail():
    a = {"foo1": "bar1", "foo2": "bar2"}
    b = {"foo1": "bar1", "foo2": "baz1"}
    assert not match(a, b)
Exemplo n.º 17
0
def test_match_multiple_partial():
    a = {"foo1": "bar1", "foo2": "bar2"}
    b = {"foo1": "bar1 baz1", "foo2": "bar2"}
    if not match(a, b, partial=True):
        raise AssertionError
Exemplo n.º 18
0
def test_match_multiple_partial():
    a = {"foo1": "bar1", "foo2": "bar2"}
    b = {"foo1": "bar1 baz1", "foo2": "bar2"}
    assert match(a, b, partial=True)
Exemplo n.º 19
0
def test_attr_match():
    a = {"foo": "bar"}
    b = {"foo": "bar"}
    if not match(a, b):
        raise AssertionError
Exemplo n.º 20
0
def test_attr_match():
    a = {"foo": "bar"}
    b = {"foo": "bar"}
    assert match(a, b)
Exemplo n.º 21
0
def test_multiple_partial_fail():
    a = {"foo1": "bar1", "foo2": "bar2"}
    b = {"foo1": "bar1 baz1", "foo2": "bar2"}
    if match(a, b, partial=False):
        raise AssertionError