forked from PyAV-Org/PyAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_errors.py
More file actions
65 lines (52 loc) · 2.08 KB
/
test_errors.py
File metadata and controls
65 lines (52 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import errno
from traceback import format_exception_only
import quickcodec
from .common import is_windows
def test_stringify() -> None:
for cls in (quickcodec.ValueError, quickcodec.FileNotFoundError, quickcodec.DecoderNotFoundError):
e = cls(1, "foo")
assert f"{e}" == "[Errno 1] foo"
assert f"{e!r}" == f"{cls.__name__}(1, 'foo')"
assert (
format_exception_only(cls, e)[-1]
== f"av.error.{cls.__name__}: [Errno 1] foo\n"
)
for cls in (quickcodec.ValueError, quickcodec.FileNotFoundError, quickcodec.DecoderNotFoundError):
e = cls(1, "foo", "bar.txt")
assert f"{e}" == "[Errno 1] foo: 'bar.txt'"
assert f"{e!r}" == f"{cls.__name__}(1, 'foo', 'bar.txt')"
assert (
format_exception_only(cls, e)[-1]
== f"av.error.{cls.__name__}: [Errno 1] foo: 'bar.txt'\n"
)
def test_bases() -> None:
assert issubclass(quickcodec.ValueError, ValueError)
assert issubclass(quickcodec.ValueError, quickcodec.FFmpegError)
assert issubclass(quickcodec.FileNotFoundError, FileNotFoundError)
assert issubclass(quickcodec.FileNotFoundError, OSError)
assert issubclass(quickcodec.FileNotFoundError, quickcodec.FFmpegError)
def test_filenotfound():
"""Catch using builtin class on Python 3.3"""
try:
quickcodec.open("does not exist")
except FileNotFoundError as e:
assert e.errno == errno.ENOENT
if is_windows:
assert e.strerror in (
"Error number -2 occurred",
"No such file or directory",
)
else:
assert e.strerror == "No such file or directory"
assert e.filename == "does not exist"
else:
assert False, "No exception raised!"
def test_buffertoosmall() -> None:
"""Throw an exception from an enum."""
BUFFER_TOO_SMALL = 1397118274
try:
quickcodec.error.err_check(-BUFFER_TOO_SMALL)
except quickcodec.error.BufferTooSmallError as e:
assert e.errno == BUFFER_TOO_SMALL
else:
assert False, "No exception raised!"