Example #1
0
def test_rule_with_options(rule_text, results, use_re2):
    rule = AdblockRule(rule_text)
    rules = AdblockRules([rule_text], use_re2=use_re2)

    for url, params, match in results:
        assert rule.match_url(url, params) == match
        assert rules.should_block(url, params) == match
Example #2
0
def test_documented_examples(rule_text, results, use_re2):
    rule = AdblockRule(rule_text)
    rules = AdblockRules([rule_text], use_re2=use_re2)

    for url in results["blocks"]:
        assert rule.match_url(url)
        assert rules.should_block(url)

    for url in results["doesn't block"]:
        assert not rule.match_url(url)
        assert not rules.should_block(url)
Example #3
0
def test_is_comment(text):
    rule = AdblockRule(text)
    assert rule.is_comment
    assert not rule.is_html_rule
    assert not rule.is_exception
    assert rule.options == {}
    assert not rule.regex
Example #4
0
def test_empty_rules():
    rules = AdblockRules(["adv", "", " \t", AdblockRule("adv2")])
    assert len(rules.rules) == 2
Example #5
0
def test_rules_instantiation():
    rule = AdblockRule("adv")
    rules = AdblockRules([rule])
    assert rule.match_url("http://example.com/adv")
    assert rules.should_block("http://example.com/adv")
Example #6
0
def test_is_html_rule(text):
    rule = AdblockRule(text)
    assert rule.is_html_rule
    assert not rule.is_comment
Example #7
0
def test_options_extraction(text, result):
    rule = AdblockRule(text)
    assert rule.options == result
Example #8
0
def test_domain_parsing(text, result):
    assert AdblockRule._parse_domain_option(text) == result
Example #9
0
def test_option_splitting(text, result):
    assert AdblockRule._split_options(text) == result
Example #10
0
def test_domain_parsing(text, result):
    assert AdblockRule._parse_domain_option(text) == result
Example #11
0
def test_option_splitting(text, result):
    assert AdblockRule._split_options(text) == result