Skip to content
Snippets Groups Projects
Commit 2ac687e6 authored by jkerdreu's avatar jkerdreu
Browse files

Added list test (need for Golang port) + Lint


git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@3074 b32b6428-25c9-4566-ad07-03861ab6144f
parent 1713675c
No related branches found
No related tags found
No related merge requests found
import unittest
from xaal.lib import cbor
from xaal.lib import bindings
import binascii
class TestCbor(unittest.TestCase):
def test_encode(self):
value = cbor.dumps(42)
self.assertEqual(value, b'\x18*') # 0x18 0x2a
self.assertEqual(value, b"\x18*") # 0x18 0x2a
def test_decode(self):
value = cbor.loads(b'\x18*')
value = cbor.loads(b"\x18*")
self.assertEqual(value, 42)
def test_list(self):
value = []
value.append(7)
value.append(1234567890)
data = cbor.dumps(value)
print(data)
self.assertEqual(data, binascii.unhexlify(b"82071a499602d2"))
def test_uuid(self):
uuid = bindings.UUID.random()
cbor_value = cbor.dumps(uuid)
......@@ -27,11 +36,27 @@ class TestCbor(unittest.TestCase):
self.assertEqual(type(value), bindings.URL)
def test_cleanup(self):
data = [7, 'hello', bindings.UUID('12345678-1234-1234-1234-123456789012'), bindings.URL('http://www.example.com'),{'hello': 'world'}]
data = [
7,
"hello",
bindings.UUID("12345678-1234-1234-1234-123456789012"),
bindings.URL("http://www.example.com"),
{"hello": "world"},
]
cbor_value = cbor.dumps(data)
value = cbor.loads(cbor_value)
cbor.cleanup(value)
self.assertEqual(value, [7, 'hello', '12345678-1234-1234-1234-123456789012', 'http://www.example.com', {'hello': 'world'}])
self.assertEqual(
value,
[
7,
"hello",
"12345678-1234-1234-1234-123456789012",
"http://www.example.com",
{"hello": "world"},
],
)
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
if __name__ == "__main__":
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment