From 02522ddbb6b65298441a268035ed7c35f0341ddf Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 25 Apr 2024 15:00:54 +0200 Subject: [PATCH] feat: implemented more tests --- python_sponsorblock/__init__.py | 1 + tests/__init__.py | 0 tests/test_error_handling.py | 27 +++++++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_error_handling.py diff --git a/python_sponsorblock/__init__.py b/python_sponsorblock/__init__.py index 32e02f7..53c96c7 100644 --- a/python_sponsorblock/__init__.py +++ b/python_sponsorblock/__init__.py @@ -26,6 +26,7 @@ def error_handling(default: Any) -> Callable: return default self.logger.error(repr(e)) + return default return _wrapper diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_error_handling.py b/tests/test_error_handling.py new file mode 100644 index 0000000..9d8b3f1 --- /dev/null +++ b/tests/test_error_handling.py @@ -0,0 +1,27 @@ +import unittest + +from python_sponsorblock import SponsorBlock, error_handling +from python_sponsorblock.exceptions import SponsorBlockError + + +SILENT_WORKS = "silent_works" + + +@error_handling(default=SILENT_WORKS) +def raise_error(self): + raise SponsorBlockError("Error") + + +class TestErrorHandling(unittest.TestCase): + def test_silent(self): + s = SponsorBlock(silent=True) + self.assertEqual(raise_error(s), SILENT_WORKS) + + def test_not_silent(self): + s = SponsorBlock(silent=False) + with self.assertRaises(SponsorBlockError): + raise_error(s) + + +if __name__ == "__main__": + unittest.main()