FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
msgpack-python/test/test_except.py at master · GuyTuval/msgpack-python · GitHub
GuyTuval
/
msgpack-python
Public
forked from
msgpack/msgpack-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
msgpack-python
/
test
/
test_except.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (45 loc) · 1.68 KB
Breadcrumbs
msgpack-python
/
test
/
test_except.py
Copy path
File metadata and controls
63 lines (45 loc) · 1.68 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python
# coding: utf-8
from
pytest
import
raises
from
msgpack
import
packb
,
unpackb
,
Unpacker
,
FormatError
,
StackError
,
OutOfData
import
datetime
class
DummyException
(
Exception
):
pass
def
test_raise_on_find_unsupported_value
():
with
raises
(
TypeError
):
packb
(
datetime
.
datetime
.
now
())
def
test_raise_from_object_hook
():
def
hook
(
obj
):
raise
DummyException
raises
(
DummyException
,
unpackb
,
packb
({}),
object_hook
=
hook
)
raises
(
DummyException
,
unpackb
,
packb
({
"fizz"
:
"buzz"
}),
object_hook
=
hook
)
raises
(
DummyException
,
unpackb
,
packb
({
"fizz"
:
"buzz"
}),
object_pairs_hook
=
hook
)
raises
(
DummyException
,
unpackb
,
packb
({
"fizz"
: {
"buzz"
:
"spam"
}}),
object_hook
=
hook
)
raises
(
DummyException
,
unpackb
,
packb
({
"fizz"
: {
"buzz"
:
"spam"
}}),
object_pairs_hook
=
hook
,
)
def
test_invalidvalue
():
incomplete
=
b"
\xd9
\x97
#DL_"
# raw8 - length=0x97
with
raises
(
ValueError
):
unpackb
(
incomplete
)
with
raises
(
OutOfData
):
unpacker
=
Unpacker
()
unpacker
.
feed
(
incomplete
)
unpacker
.
unpack
()
with
raises
(
FormatError
):
unpackb
(
b"
\xc1
"
)
# (undefined tag)
with
raises
(
FormatError
):
unpackb
(
b"
\x91
\xc1
"
)
# fixarray(len=1) [ (undefined tag) ]
with
raises
(
StackError
):
unpackb
(
b"
\x91
"
*
3000
)
# nested fixarray(len=1)
def
test_strict_map_key
():
valid
=
{
u"unicode"
:
1
,
b"bytes"
:
2
}
packed
=
packb
(
valid
,
use_bin_type
=
True
)
assert
valid
==
unpackb
(
packed
,
raw
=
False
,
strict_map_key
=
True
)
invalid
=
{
42
:
1
}
packed
=
packb
(
invalid
,
use_bin_type
=
True
)
with
raises
(
ValueError
):
unpackb
(
packed
,
raw
=
False
,
strict_map_key
=
True
)
Back
|
FazBrowse Home
|
New Git URL