summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorÁrni Dagur <arni@dagur.eu>2021-01-16 19:47:05 +0000
committerGitHub <noreply@github.com>2021-01-16 19:47:05 +0000
commit9c684f12e1050d8b0dce9cb1e66eb2de0c5f3be6 (patch)
treedc7de30b8e0e653d04056aed28673c04656301f9 /tests
parent78f97d6b35b613b78727a94f3f6064b091665f55 (diff)
Improve __repr__ (#23)
So we get something like: BlockerResult(matched=false, important=false, redirect=None, exception=None, filter=None, error=None) rather than: BlockerResult(false, false, None, None, None, None) Co-authored-by: Florian Bruhin <me@the-compiler.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_repr.py37
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 @@
1import adblock
2import re
3
4
5def 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
13def 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 )