mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-04-09 21:10:18 +00:00
Drop python2 support (#519)
The PR removes python2 references and cases. Close #518 Co-authored-by: Inada Naoki <songofacandy@gmail.com>
This commit is contained in:
parent
45f848695c
commit
feec06206c
17 changed files with 58 additions and 143 deletions
|
|
@ -6,7 +6,6 @@ import pytest
|
|||
from msgpack import packb, unpackb
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="Python 2 is not supported")
|
||||
def test_unpack_buffer():
|
||||
from array import array
|
||||
|
||||
|
|
|
|||
|
|
@ -134,4 +134,4 @@ def test_match():
|
|||
|
||||
|
||||
def test_unicode():
|
||||
assert unpackb(packb(u"foobar"), use_list=1) == u"foobar"
|
||||
assert unpackb(packb("foobar"), use_list=1) == "foobar"
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ def test_invalidvalue():
|
|||
|
||||
|
||||
def test_strict_map_key():
|
||||
valid = {u"unicode": 1, b"bytes": 2}
|
||||
valid = {"unicode": 1, b"bytes": 2}
|
||||
packed = packb(valid, use_bin_type=True)
|
||||
assert valid == unpackb(packed, raw=False, strict_map_key=True)
|
||||
|
||||
|
|
|
|||
|
|
@ -55,10 +55,7 @@ def test_extension_type():
|
|||
print("ext_hook called", code, data)
|
||||
assert code == 123
|
||||
obj = array.array("d")
|
||||
try:
|
||||
obj.frombytes(data)
|
||||
except AttributeError: # PY2
|
||||
obj.fromstring(data)
|
||||
obj.frombytes(data)
|
||||
return obj
|
||||
|
||||
obj = [42, b"hello", array.array("d", [1.1, 2.2, 3.3])]
|
||||
|
|
@ -67,20 +64,14 @@ def test_extension_type():
|
|||
assert obj == obj2
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version > "3":
|
||||
long = int
|
||||
|
||||
|
||||
def test_overriding_hooks():
|
||||
def default(obj):
|
||||
if isinstance(obj, long):
|
||||
if isinstance(obj, int):
|
||||
return {"__type__": "long", "__data__": str(obj)}
|
||||
else:
|
||||
return obj
|
||||
|
||||
obj = {"testval": long(1823746192837461928374619)}
|
||||
obj = {"testval": 1823746192837461928374619}
|
||||
refobj = {"testval": default(obj["testval"])}
|
||||
refout = msgpack.packb(refobj)
|
||||
assert isinstance(refout, (str, bytes))
|
||||
|
|
|
|||
|
|
@ -7,11 +7,6 @@ from msgpack import packb, unpackb
|
|||
import sys
|
||||
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
sys.version_info[0] < 3, reason="Only Python 3 supports buffer protocol"
|
||||
)
|
||||
|
||||
|
||||
def make_array(f, data):
|
||||
a = array(f)
|
||||
a.frombytes(data)
|
||||
|
|
|
|||
|
|
@ -80,9 +80,6 @@ def testPackByteArrays():
|
|||
check(td)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 0), reason="Python 2 passes invalid surrogates"
|
||||
)
|
||||
def testIgnoreUnicodeErrors():
|
||||
re = unpackb(
|
||||
packb(b"abc\xeddef", use_bin_type=False), raw=False, unicode_errors="ignore"
|
||||
|
|
@ -96,9 +93,6 @@ def testStrictUnicodeUnpack():
|
|||
unpackb(packed, raw=False, use_list=1)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 0), reason="Python 2 passes invalid surrogates"
|
||||
)
|
||||
def testIgnoreErrorsPack():
|
||||
re = unpackb(
|
||||
packb("abc\uDC80\uDCFFdef", use_bin_type=True, unicode_errors="ignore"),
|
||||
|
|
|
|||
|
|
@ -4,9 +4,6 @@ import datetime
|
|||
import msgpack
|
||||
from msgpack.ext import Timestamp
|
||||
|
||||
if sys.version_info[0] > 2:
|
||||
from msgpack.ext import _utc
|
||||
|
||||
|
||||
def test_timestamp():
|
||||
# timestamp32
|
||||
|
|
@ -85,33 +82,33 @@ def test_timestamp_to():
|
|||
assert t.to_unix_nano() == 42000014000
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="datetime support is PY3+ only")
|
||||
def test_timestamp_datetime():
|
||||
t = Timestamp(42, 14)
|
||||
assert t.to_datetime() == datetime.datetime(1970, 1, 1, 0, 0, 42, 0, tzinfo=_utc)
|
||||
utc = datetime.timezone.utc
|
||||
assert t.to_datetime() == datetime.datetime(1970, 1, 1, 0, 0, 42, 0, tzinfo=utc)
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="datetime support is PY3+ only")
|
||||
def test_unpack_datetime():
|
||||
t = Timestamp(42, 14)
|
||||
utc = datetime.timezone.utc
|
||||
packed = msgpack.packb(t)
|
||||
unpacked = msgpack.unpackb(packed, timestamp=3)
|
||||
assert unpacked == datetime.datetime(1970, 1, 1, 0, 0, 42, 0, tzinfo=_utc)
|
||||
assert unpacked == datetime.datetime(1970, 1, 1, 0, 0, 42, 0, tzinfo=utc)
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="datetime support is PY3+ only")
|
||||
def test_pack_unpack_before_epoch():
|
||||
t_in = datetime.datetime(1960, 1, 1, tzinfo=_utc)
|
||||
utc = datetime.timezone.utc
|
||||
t_in = datetime.datetime(1960, 1, 1, tzinfo=utc)
|
||||
packed = msgpack.packb(t_in, datetime=True)
|
||||
unpacked = msgpack.unpackb(packed, timestamp=3)
|
||||
assert unpacked == t_in
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="datetime support is PY3+ only")
|
||||
def test_pack_datetime():
|
||||
t = Timestamp(42, 14000)
|
||||
dt = t.to_datetime()
|
||||
assert dt == datetime.datetime(1970, 1, 1, 0, 0, 42, 14, tzinfo=_utc)
|
||||
utc = datetime.timezone.utc
|
||||
assert dt == datetime.datetime(1970, 1, 1, 0, 0, 42, 14, tzinfo=utc)
|
||||
|
||||
packed = msgpack.packb(dt, datetime=True)
|
||||
packed2 = msgpack.packb(t)
|
||||
|
|
@ -131,10 +128,10 @@ def test_pack_datetime():
|
|||
assert msgpack.unpackb(packed) is None
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="datetime support is PY3+ only")
|
||||
def test_issue451():
|
||||
# https://github.com/msgpack/msgpack-python/issues/451
|
||||
dt = datetime.datetime(2100, 1, 1, 1, 1, tzinfo=_utc)
|
||||
utc = datetime.timezone.utc
|
||||
dt = datetime.datetime(2100, 1, 1, 1, 1, tzinfo=utc)
|
||||
packed = msgpack.packb(dt, datetime=True)
|
||||
assert packed == b"\xd6\xff\xf4\x86eL"
|
||||
|
||||
|
|
@ -142,7 +139,6 @@ def test_issue451():
|
|||
assert dt == unpacked
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info[0] == 2, reason="datetime support is PY3+ only")
|
||||
def test_pack_datetime_without_tzinfo():
|
||||
dt = datetime.datetime(1970, 1, 1, 0, 0, 42, 14)
|
||||
with pytest.raises(ValueError, match="where tzinfo=None"):
|
||||
|
|
@ -152,7 +148,8 @@ def test_pack_datetime_without_tzinfo():
|
|||
packed = msgpack.packb(dt, datetime=True, default=lambda x: None)
|
||||
assert packed == msgpack.packb(None)
|
||||
|
||||
dt = datetime.datetime(1970, 1, 1, 0, 0, 42, 14, tzinfo=_utc)
|
||||
utc = datetime.timezone.utc
|
||||
dt = datetime.datetime(1970, 1, 1, 0, 0, 42, 14, tzinfo=utc)
|
||||
packed = msgpack.packb(dt, datetime=True)
|
||||
unpacked = msgpack.unpackb(packed, timestamp=3)
|
||||
assert unpacked == dt
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ def test_unpacker_ext_hook():
|
|||
|
||||
|
||||
def test_unpacker_tell():
|
||||
objects = 1, 2, u"abc", u"def", u"ghi"
|
||||
objects = 1, 2, "abc", "def", "ghi"
|
||||
packed = b"\x01\x02\xa3abc\xa3def\xa3ghi"
|
||||
positions = 1, 2, 6, 10, 14
|
||||
unpacker = Unpacker(BytesIO(packed))
|
||||
|
|
@ -80,7 +80,7 @@ def test_unpacker_tell():
|
|||
|
||||
|
||||
def test_unpacker_tell_read_bytes():
|
||||
objects = 1, u"abc", u"ghi"
|
||||
objects = 1, "abc", "ghi"
|
||||
packed = b"\x01\x02\xa3abc\xa3def\xa3ghi"
|
||||
raw_data = b"\x02", b"\xa3def", b""
|
||||
lenghts = 1, 4, 999
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue