diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_repr.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/test_repr.py b/tests/test_repr.py new file mode 100644 index 0000000..9c1f961 --- /dev/null +++ b/tests/test_repr.py | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | import adblock | ||
| 2 | import re | ||
| 3 | |||
| 4 | |||
| 5 | def assert_acceptable_repr(obj): | ||
| 6 | # Default repr is r"<[A-Za-z]+ object at 0x[0-9a-f]+>" | ||
| 7 | assert "object at" not in repr(obj) | ||
| 8 | assert re.match(r"[A-Z][a-zA-Z]+\(.*\)", repr(obj)) or re.match( | ||
| 9 | r"([A-Z][a-zA-Z]+)?<.*>", repr(obj) | ||
| 10 | ) | ||
| 11 | |||
| 12 | |||
| 13 | def test_has_nondefault_repr(): | ||
| 14 | for b in (True, False): | ||
| 15 | fs = adblock.FilterSet(debug=b) | ||
| 16 | assert_acceptable_repr(fs) | ||
| 17 | assert repr(b) in repr(fs) | ||
| 18 | |||
| 19 | fs.add_filters(["||example.com^"]) | ||
| 20 | |||
| 21 | e = adblock.Engine(fs) | ||
| 22 | assert_acceptable_repr(e) | ||
| 23 | |||
| 24 | result = e.check_network_urls( | ||
| 25 | "https://example.com/picture.png", "https://example.net", "image" | ||
| 26 | ) | ||
| 27 | assert_acceptable_repr(result) | ||
| 28 | assert repr(result) == ( | ||
| 29 | "BlockerResult(matched={}, important={}, redirect={}, exception={}, filter={}, error={})".format( | ||
| 30 | repr(result.matched), | ||
| 31 | repr(result.important), | ||
| 32 | repr(result.redirect), | ||
| 33 | repr(result.exception), | ||
| 34 | repr(result.filter), | ||
| 35 | repr(result.error), | ||
| 36 | ) | ||
| 37 | ) | ||
