MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / testBackwardCompatibility

Method testBackwardCompatibility

src/Test/TestMsgpack.py:64–87  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

62 assert type(data_unpacked["body"]) == bytes
63
64 def testBackwardCompatibility(self):
65 packed = {}
66 packed["py3"] = Msgpack.pack(self.test_data, use_bin_type=False)
67 packed["py3_bin"] = Msgpack.pack(self.test_data, use_bin_type=True)
68 for key, val in packed.items():
69 unpacked = Msgpack.unpack(val)
70 type(unpacked["utf8"]) == str
71 type(unpacked["bin"]) == bytes
72
73 # Packed with use_bin_type=False (pre-ZeroNet 0.7.0)
74 unpacked = Msgpack.unpack(packed["py3"], decode=True)
75 type(unpacked["utf8"]) == str
76 type(unpacked["bin"]) == bytes
77 assert len(unpacked["utf8"]) == 9
78 assert len(unpacked["bin"]) == 10
79 with pytest.raises(UnicodeDecodeError) as err: # Try to decode binary as utf-8
80 unpacked = Msgpack.unpack(packed["py3"], decode=False)
81
82 # Packed with use_bin_type=True
83 unpacked = Msgpack.unpack(packed["py3_bin"], decode=False)
84 type(unpacked["utf8"]) == str
85 type(unpacked["bin"]) == bytes
86 assert len(unpacked["utf8"]) == 9
87 assert len(unpacked["bin"]) == 10
88

Callers

nothing calls this directly

Calls 3

itemsMethod · 0.80
packMethod · 0.45
unpackMethod · 0.45

Tested by

no test coverage detected