Skip to content

Commit

Permalink
* Fixed encoding issue in parse_pyobject by decoding it as latin_1. T…
Browse files Browse the repository at this point in the history
…his might relate to IPFS Bug #1817 ipfs/kubo#1817

* Added  test for get_pyobject() and add_pyobject() in test/functional/tests.py which works fine.

NB: Other tests in tests.py fail, there might be an issue with the multipart code. At the moment test/functional/tests.py is not evaluated by tox because setup.cfg limits tests to tests/unit.
  • Loading branch information
gersonkevin23 committed Mar 16, 2016
1 parent 1cb3739 commit 0f11b06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ipfsApi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def parse_pyobj(pickled):
[1, 2, 3, True, 4.5, None, 6000.0]
"""
if isinstance(pickled, six.text_type):
pickled = pickled.encode('ascii')
pickled = pickled.encode('latin_1')
return pickle.loads(pickled)


Expand Down
10 changes: 9 additions & 1 deletion test/functional/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# _*_ coding: utf-8 -*-
import os
import unittest

Expand All @@ -6,6 +7,7 @@

HERE = os.path.dirname(os.path.abspath(__file__))


class IpfsApiTest(unittest.TestCase):

api = ipfsApi.Client()
Expand Down Expand Up @@ -38,7 +40,7 @@ class IpfsApiTest(unittest.TestCase):
u'Name': u'popoiopiu'},
{u'Hash': u'QmVkNdzCBukBRdpyFiKPyL2R15qPExMr9rV9RFV2kf9eeV',
u'Name': u''}]

## test_add_multiple_from_dirname
fake_dir_test2 = 'fake_dir/test2'
fake_dir_res = [{u'Hash': u'QmNuvmuFeeWWpxjCQwLkHshr8iqhGLWXFzSGzafBeawTTZ',
Expand Down Expand Up @@ -106,6 +108,12 @@ def test_add_recursive(self):
sorted(self.fake_dir_recursive_res,
key=lambda x: x['Name']))

def test_add_get_pyobject(self):
data = [-1, 3.14, u'Hän€', b'23' ]
res = self.api.add_pyobj(data)
self.assertEqual(data,
self.api.get_pyobj(res))


if __name__ == "__main__":
unittest.main()

0 comments on commit 0f11b06

Please sign in to comment.