diff options
| author | Árni Dagur <arni@dagur.eu> | 2021-06-26 16:20:29 +0000 |
|---|---|---|
| committer | Árni Dagur <arni@dagur.eu> | 2021-06-26 19:10:50 +0000 |
| commit | fb1832feb868a81e2d10a1707c57df4623304313 (patch) | |
| tree | f77f31d340f19b0e4d96a92ccc23cdeb6b135738 /tests | |
| parent | 0d5c8b8cfa1025c29b96db3c52ff54a7d204923f (diff) | |
Create a custom exception type for this library
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_engine.py | 11 | ||||
| -rw-r--r-- | tests/test_exceptions.py | 10 | ||||
| -rw-r--r-- | tests/test_imports.py | 6 |
3 files changed, 25 insertions, 2 deletions
diff --git a/tests/test_engine.py b/tests/test_engine.py index a3d2898..8a7421c 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py | |||
| @@ -52,6 +52,17 @@ def test_serde_file(tmpdir): | |||
| 52 | assert deserialization_result is None | 52 | assert deserialization_result is None |
| 53 | 53 | ||
| 54 | 54 | ||
| 55 | def test_deserialize_corrupt(tmpdir): | ||
| 56 | path = str(tmpdir / "corrupt_cache.dat") | ||
| 57 | with open(path, "w", encoding="utf-8") as f: | ||
| 58 | f.write("abc") | ||
| 59 | |||
| 60 | engine = empty_engine() | ||
| 61 | with pytest.raises(adblock.DeserializationError): | ||
| 62 | engine.deserialize_from_file(path) | ||
| 63 | with pytest.raises(adblock.DeserializationError): | ||
| 64 | engine.deserialize(b"abc") | ||
| 65 | |||
| 55 | def test_serde(): | 66 | def test_serde(): |
| 56 | engine = empty_engine() | 67 | engine = empty_engine() |
| 57 | serialization_result = engine.serialize() | 68 | serialization_result = engine.serialize() |
diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py new file mode 100644 index 0000000..497b3ef --- /dev/null +++ b/tests/test_exceptions.py | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | import adblock | ||
| 2 | |||
| 3 | def test_correct_baseclasses(): | ||
| 4 | assert issubclass(adblock.AdblockException, Exception) | ||
| 5 | assert issubclass(adblock.BlockerException, adblock.AdblockException) | ||
| 6 | assert issubclass(adblock.SerializationError, adblock.BlockerException) | ||
| 7 | assert issubclass(adblock.DeserializationError, adblock.BlockerException) | ||
| 8 | assert issubclass(adblock.OptimizedFilterExistence, adblock.BlockerException) | ||
| 9 | assert issubclass(adblock.BadFilterAddUnsupported, adblock.BlockerException) | ||
| 10 | assert issubclass(adblock.FilterExists, adblock.BlockerException) \ No newline at end of file | ||
diff --git a/tests/test_imports.py b/tests/test_imports.py index 7692483..09ef5d5 100644 --- a/tests/test_imports.py +++ b/tests/test_imports.py | |||
| @@ -14,16 +14,18 @@ def get_added_classes(): | |||
| 14 | match = re.match(r"m\.add_class::<(.+)>\(\)\?;", line.strip()) | 14 | match = re.match(r"m\.add_class::<(.+)>\(\)\?;", line.strip()) |
| 15 | if match is not None: | 15 | if match is not None: |
| 16 | classes.append(match.group(1)) | 16 | classes.append(match.group(1)) |
| 17 | continue | ||
| 17 | return classes | 18 | return classes |
| 18 | 19 | ||
| 19 | 20 | ||
| 20 | def test_added_classes(): | 21 | def test_added_classes(): |
| 21 | """ | 22 | """ |
| 22 | Make sure that there's no class that we added in Rust but didn't import in | 23 | Make sure that there's no class that we added in Rust but didn't import in |
| 23 | `__init__.py` and vice versa. | 24 | `__init__.py`. |
| 24 | """ | 25 | """ |
| 25 | added_classes = get_added_classes() | 26 | added_classes = get_added_classes() |
| 26 | assert added_classes == list(adblock.__all__) | 27 | for c in added_classes: |
| 28 | assert c in adblock.__all__ | ||
| 27 | 29 | ||
| 28 | 30 | ||
| 29 | def test_dunder_all_classes_imported(): | 31 | def test_dunder_all_classes_imported(): |
