python-sponsorblock/tests/test_error_handling.py

28 lines
639 B
Python
Raw Normal View History

2024-04-25 13:00:54 +00:00
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()