def test_transform_raise_key_error(): src = { 'l1': { '/': 'takemedowntotheparadisecity', 'badlinksibling': 'icauseakeyerror', 'badlinksibling2': 'icauseakeyerror' }, } with pytest.raises(KeyError): marshal(src)
def test_transformation_doesnt_mutate_input(): src = { 'l1': { '/': 'takemedowntotheparadisecity', }, } expected = { 'l1': { '/': 'takemedowntotheparadisecity', }, } marshal(src) assert src == expected
def test_transform_dict_to_cbor(): src = { 'hello': 'world', 'num': 1, } expected = { 'num': 1, 'hello': 'world', } assert marshal(src) == dumps(expected, sort_keys=True)
def test_transform_dict_with_link_to_cbor(): src = { 'hello': 'world', 'num': 1, 'l1': { '/': 'takemedowntotheparadisecity', }, } expected = { 'num': 1, 'hello': 'world', 'l1': Tag(LINK_TAG, 'takemedowntotheparadisecity'), } assert marshal(src) == dumps(expected, sort_keys=True)
def test_transform_dict_to_cbor_with_multiaddr(): addr1 = Multiaddr('/ip4/127.0.0.1/udp/1234') addr2 = Multiaddr('/ipfs/Qmafmh1Cw3H1bwdYpaaj5AbCW4LkYyUWaM7Nykpn5NZoYL') src = { 'data': 'hello world', 'size': 11, 'l1': { '/': str(addr1), }, 'l2': { '/': str(addr2), } } expected = { 'data': 'hello world', 'size': 11, 'l1': Tag(LINK_TAG, addr1.to_bytes()), 'l2': Tag(LINK_TAG, addr2.to_bytes()), } assert marshal(src) == dumps(expected, sort_keys=True)