[Python-modules-commits] [jsonpickle] 01/06: Import jsonpickle_0.9.3.orig.tar.gz
Raphaël Hertzog
hertzog at moszumanska.debian.org
Wed Mar 9 09:39:26 UTC 2016
This is an automated email from the git hooks/post-receive script.
hertzog pushed a commit to branch master
in repository jsonpickle.
commit e937fb67527297c47b28988d26a27bae533355f7
Author: Raphaël Hertzog <hertzog at debian.org>
Date: Wed Mar 9 10:08:49 2016 +0100
Import jsonpickle_0.9.3.orig.tar.gz
---
COPYING | 2 +-
PKG-INFO | 2 +-
README.rst | 19 ++++++++++-
Rakefile | 74 -----------------------------------------
docs/source/api.rst | 2 ++
docs/source/changelog.rst | 15 +++++++++
docs/source/index.rst | 2 +-
jsonpickle.egg-info/PKG-INFO | 2 +-
jsonpickle.egg-info/SOURCES.txt | 2 +-
jsonpickle/__init__.py | 8 +++--
jsonpickle/backend.py | 35 +++++++++++++++----
jsonpickle/compat.py | 2 ++
jsonpickle/ext/numpy.py | 21 ++++++++++--
jsonpickle/handlers.py | 14 ++++++++
jsonpickle/pickler.py | 17 +++++++---
jsonpickle/unpickler.py | 15 +++++++--
jsonpickle/version.py | 2 +-
requirements-3.txt | 2 ++
setup.py | 2 +-
tests/backend_test.py | 26 ++++++++-------
tests/helper.py | 1 +
tests/numpy_test.py | 2 ++
tests/object_test.py | 11 ++++++
tests/runtests.py | 2 ++
tests/stdlib_test.py | 39 ++++++++++++++++++++++
25 files changed, 206 insertions(+), 113 deletions(-)
diff --git a/COPYING b/COPYING
index 5e94808..3bda2ef 100644
--- a/COPYING
+++ b/COPYING
@@ -1,5 +1,5 @@
Copyright (C) 2008 John Paulett (john -at- paulett.org)
-Copyright (C) 2009, 2011, 2013 David Aguilar (davvid -at- gmail.com)
+Copyright (C) 2009-2016 David Aguilar (davvid -at- gmail.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
diff --git a/PKG-INFO b/PKG-INFO
index 8aefb4f..b6dd592 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: jsonpickle
-Version: 0.9.2
+Version: 0.9.3
Summary: Python library for serializing any arbitrary object graph into JSON
Home-page: http://jsonpickle.github.io/
Author: David Aguilar
diff --git a/README.rst b/README.rst
index 4c15824..b4fd724 100644
--- a/README.rst
+++ b/README.rst
@@ -13,9 +13,26 @@ Bug reports and merge requests are encouraged at the
Install
=======
+Install from pip for the latest stable release:
+
+::
+
+ pip install jsonpickle
+
+Install from github for the latest changes:
+
::
- python setup.py install
+ pip install git+https://github.com/jsonpickle/jsonpickle.git
+
+If you have the files checked out for development:
+
+::
+
+ git clone https://github.com/jsonpickle/jsonpickle.git
+ cd jsonpickle
+ python setup.py develop
+
jsonpickleJS
============
diff --git a/Rakefile b/Rakefile
deleted file mode 100644
index c0e18fb..0000000
--- a/Rakefile
+++ /dev/null
@@ -1,74 +0,0 @@
-VERSION_FILE = File.open('jsonpickle/version.py').gets.strip
-eval VERSION_FILE
-PYTHON_ENVS = [:env26, :env27, :env32, :env33, :env34]
-PYTHON_EXECS = {:env26 => "python2.6",
- :env27 => "python2.7",
- :env32 => "python3.2",
- :env33 => "python3.3",
- :env34 => "python3.4"}
-
-def colorize(text, color)
- color_codes = {
- :black => 30,
- :red => 31,
- :green => 32,
- :yellow => 33,
- :blue => 34,
- :magenta => 35,
- :cyan => 36,
- :white => 37
- }
- code = color_codes[color]
- if code == nil
- text
- else
- "\033[#{code}m#{text}\033[0m"
- end
-end
-
-def virtual_env(command, env="env33")
- sh "source #{env}/bin/activate ; #{command}"
-end
-
-def create_virtual_env(dir, python)
- sh "virtualenv #{dir} -p #{python}"
-end
-
-task :clean => [] do
- sh "rm -rf ~*"
- sh "rm -rf *.pyc *.pyo"
- sh "rm -rf data/"
- sh "rm -rf *.egg-info"
- sh "rm -rf dist/"
-end
-
-task :install => [] do
- sh "python --version"
- sh "ruby --version"
- sh "easy_install pip"
-end
-
-task :dev_env => [] do
- PYTHON_ENVS.each { |env|
- puts colorize("Environment #{env}", :blue)
- create_virtual_env(env, PYTHON_EXECS[env])
- }
-end
-
-task :dependencies => [:dev_env] do
- PYTHON_ENVS.each { |env|
- puts colorize("Environment #{env}", :blue)
- virtual_env("pip install -r requirements.txt", "#{env}")
- virtual_env("pip install -r requirements-test.txt", "#{env}")
- }
-end
-
-task :tests => [] do
- PYTHON_ENVS.each { |env|
- puts colorize("Environment #{env}", :blue)
- virtual_env("nosetests", env)
- }
-end
-
-task :default => [:tests]
-
diff --git a/docs/source/api.rst b/docs/source/api.rst
index a944ae0..31c330a 100644
--- a/docs/source/api.rst
+++ b/docs/source/api.rst
@@ -57,6 +57,8 @@ Experimental backends:
.. autofunction:: jsonpickle.set_encoder_options
+.. autofunction:: jsonpickle.set_decoder_options
+
Customizing JSON output
-----------------------
diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst
index eb0b1c1..f137cc6 100644
--- a/docs/source/changelog.rst
+++ b/docs/source/changelog.rst
@@ -1,5 +1,20 @@
Change Log
==========
+
+Version 0.9.3 - March 9, 2016
+-----------------------------
+ * UUID objects can now be serialized
+ (`#130 <https://github.com/jsonpickle/jsonpickle/issues/130>`_).
+
+ * Added `set_decoder_options` method to allow decoder specific options
+ equal to `set_encoder_options`.
+
+ * Int keys can be encoded directly by e.g. demjson by passing
+ `numeric_keys=True` and setting its backend options via
+ `jsonpickle.set_encoder_options('demjson', strict=False)`.
+
+ * Newer Numpy versions (v1.10+) are now supported.
+
Version 0.9.2 - March 20, 2015
------------------------------
* Fixes for serializing objects with custom handlers.
diff --git a/docs/source/index.rst b/docs/source/index.rst
index b8f336e..64be8b0 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -96,4 +96,4 @@ jsonpickle is provided under a
`New BSD license <https://github.com/jsonpickle/jsonpickle/raw/master/COPYING>`_,
Copyright (C) 2008-2011 John Paulett (john -at- paulett.org)
-Copyright (C) 2009-2013 David Aguilar (davvid -at- gmail.com)
+Copyright (C) 2009-2016 David Aguilar (davvid -at- gmail.com)
diff --git a/jsonpickle.egg-info/PKG-INFO b/jsonpickle.egg-info/PKG-INFO
index 8aefb4f..b6dd592 100644
--- a/jsonpickle.egg-info/PKG-INFO
+++ b/jsonpickle.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: jsonpickle
-Version: 0.9.2
+Version: 0.9.3
Summary: Python library for serializing any arbitrary object graph into JSON
Home-page: http://jsonpickle.github.io/
Author: David Aguilar
diff --git a/jsonpickle.egg-info/SOURCES.txt b/jsonpickle.egg-info/SOURCES.txt
index dfa7d5e..8190ada 100644
--- a/jsonpickle.egg-info/SOURCES.txt
+++ b/jsonpickle.egg-info/SOURCES.txt
@@ -1,7 +1,6 @@
COPYING
MANIFEST.in
README.rst
-Rakefile
requirements-2.txt
requirements-3.txt
requirements-test.txt
@@ -50,4 +49,5 @@ tests/jsonpickle_test.py
tests/numpy_test.py
tests/object_test.py
tests/runtests.py
+tests/stdlib_test.py
tests/util_test.py
\ No newline at end of file
diff --git a/jsonpickle/__init__.py b/jsonpickle/__init__.py
index 446eddf..e735da8 100644
--- a/jsonpickle/__init__.py
+++ b/jsonpickle/__init__.py
@@ -68,6 +68,7 @@ json = JSONBackend()
# Export specific JSONPluginMgr methods into the jsonpickle namespace
set_preferred_backend = json.set_preferred_backend
+set_decoder_options = json.set_decoder_options
set_encoder_options = json.set_encoder_options
load_backend = json.load_backend
remove_backend = json.remove_backend
@@ -81,7 +82,8 @@ def encode(value,
max_depth=None,
backend=None,
warn=False,
- max_iter=None):
+ max_iter=None,
+ numeric_keys=False):
"""Return a JSON formatted representation of value, a Python object.
:param unpicklable: If set to False then the output will not contain the
@@ -128,7 +130,9 @@ def encode(value,
make_refs=make_refs,
keys=keys,
max_depth=max_depth,
- warn=warn)
+ warn=warn,
+ max_iter=max_iter,
+ numeric_keys=numeric_keys)
def decode(string, backend=None, keys=False):
diff --git a/jsonpickle/backend.py b/jsonpickle/backend.py
index e1601cf..67e4f88 100644
--- a/jsonpickle/backend.py
+++ b/jsonpickle/backend.py
@@ -33,6 +33,9 @@ class JSONBackend(object):
'django.util.simplejson': json_opts,
}
+ # Options to pass to specific encoders
+ self._decoder_options = {}
+
# The exception class that is thrown when a decoding error occurs
self._decoder_exceptions = {}
@@ -120,8 +123,9 @@ class JSONBackend(object):
# simplejson uses ValueError
self._decoder_exceptions[name] = loads_exc
- # Setup the default args and kwargs for this encoder
+ # Setup the default args and kwargs for this encoder/decoder
self._encoder_options[name] = ([], {})
+ self._decoder_options[name] = ([], {})
# Add this backend to the list of candidate backends
self._backend_names.append(name)
@@ -135,6 +139,7 @@ class JSONBackend(object):
self._encoders.pop(name, None)
self._decoders.pop(name, None)
self._decoder_exceptions.pop(name, None)
+ self._decoder_options.pop(name, None)
self._encoder_options.pop(name, None)
if name in self._backend_names:
self._backend_names.remove(name)
@@ -156,10 +161,7 @@ class JSONBackend(object):
for idx, name in enumerate(self._backend_names):
try:
- optargs, optkwargs = self._encoder_options[name]
- encoder_kwargs = optkwargs.copy()
- encoder_args = (obj,) + tuple(optargs)
- return self._encoders[name](*encoder_args, **encoder_kwargs)
+ return self.backend_encode(name, obj)
except Exception as e:
if idx == len(self._backend_names) - 1:
raise e
@@ -198,7 +200,9 @@ class JSONBackend(object):
loads = decode
def backend_decode(self, name, string):
- return self._decoders[name](string)
+ optargs, optkwargs = self._decoder_options.get(name, ((), {}))
+ decoder_kwargs = optkwargs.copy()
+ return self._decoders[name](string, *optargs, **decoder_kwargs)
def set_preferred_backend(self, name):
"""
@@ -244,6 +248,25 @@ class JSONBackend(object):
"""
self._encoder_options[name] = (args, kwargs)
+ def set_decoder_options(self, name, *args, **kwargs):
+ """
+ Associate decoder-specific options with a decoder.
+
+ After calling set_decoder_options, any calls to jsonpickle's
+ decode method will pass the supplied args and kwargs along to
+ the appropriate backend's decode method.
+
+ For example::
+
+ set_decoder_options('simplejson', encoding='utf8', cls=JSONDecoder)
+ set_decoder_options('demjson', strict=True)
+
+ See the appropriate decoder's documentation for details about
+ the supported arguments and keyword arguments.
+
+ """
+ self._decoder_options[name] = (args, kwargs)
+
def _store(self, dct, backend, obj, name):
try:
dct[backend] = getattr(obj, name)
diff --git a/jsonpickle/compat.py b/jsonpickle/compat.py
index 7d8b361..b03a3e2 100644
--- a/jsonpickle/compat.py
+++ b/jsonpickle/compat.py
@@ -26,8 +26,10 @@ except NameError:
try:
long = long
+ numeric_types = (int, long)
except NameError:
long = int
+ numeric_types = (int,)
try:
unichr = unichr
diff --git a/jsonpickle/ext/numpy.py b/jsonpickle/ext/numpy.py
index afe86d3..c4a8a79 100644
--- a/jsonpickle/ext/numpy.py
+++ b/jsonpickle/ext/numpy.py
@@ -12,16 +12,29 @@ __all__ = ['register_handlers', 'unregister_handlers']
class NumpyBaseHandler(jsonpickle.handlers.BaseHandler):
+
def restore_dtype(self, data):
dtype = data['dtype']
if dtype.startswith(('{', '[')):
return ast.literal_eval(dtype)
return np.dtype(dtype)
+ def flatten_dtype(self, dtype, data):
+
+ if hasattr(dtype, 'tostring'):
+ data['dtype'] = dtype.tostring()
+ else:
+ dtype = unicode(dtype)
+ prefix = '(numpy.record, '
+ if dtype.startswith(prefix):
+ dtype = dtype[len(prefix):-1]
+ data['dtype'] = dtype
+
class NumpyDTypeHandler(NumpyBaseHandler):
+
def flatten(self, obj, data):
- data['dtype'] = unicode(obj)
+ self.flatten_dtype(obj, data)
return data
def restore(self, data):
@@ -29,8 +42,9 @@ class NumpyDTypeHandler(NumpyBaseHandler):
class NumpyGenericHandler(NumpyBaseHandler):
+
def flatten(self, obj, data):
- data['dtype'] = unicode(obj.dtype)
+ self.flatten_dtype(obj.dtype, data)
data['value'] = self.context.flatten(obj.tolist(), reset=False)
return data
@@ -40,8 +54,9 @@ class NumpyGenericHandler(NumpyBaseHandler):
class NumpyNDArrayHandler(NumpyBaseHandler):
+
def flatten(self, obj, data):
- data['dtype'] = unicode(obj.dtype)
+ self.flatten_dtype(obj.dtype, data)
data['values'] = self.context.flatten(obj.tolist(), reset=False)
return data
diff --git a/jsonpickle/handlers.py b/jsonpickle/handlers.py
index 5ae5af6..53f12b9 100644
--- a/jsonpickle/handlers.py
+++ b/jsonpickle/handlers.py
@@ -29,6 +29,7 @@ import decimal
import re
import sys
import time
+import uuid
from jsonpickle import util
from jsonpickle.compat import unicode
@@ -278,3 +279,16 @@ class CloneFactory(object):
def __repr__(self):
return ('<CloneFactory object at 0x%x (%s)>' % (id(self), self.exemplar))
+
+
+class UUIDHandler(BaseHandler):
+ """Serialize uuid.UUID objects"""
+
+ def flatten(self, obj, data):
+ data['hex'] = obj.hex
+ return data
+
+ def restore(self, data):
+ return uuid.UUID(data['hex'])
+
+UUIDHandler.handles(uuid.UUID)
diff --git a/jsonpickle/pickler.py b/jsonpickle/pickler.py
index f0440c2..f616f4e 100644
--- a/jsonpickle/pickler.py
+++ b/jsonpickle/pickler.py
@@ -17,7 +17,7 @@ import jsonpickle.tags as tags
import jsonpickle.handlers as handlers
from jsonpickle.backend import JSONBackend
-from jsonpickle.compat import unicode, PY3, PY2
+from jsonpickle.compat import numeric_types, unicode, PY3, PY2
def encode(value,
@@ -29,7 +29,8 @@ def encode(value,
backend=None,
warn=False,
context=None,
- max_iter=None):
+ max_iter=None,
+ numeric_keys=False):
backend = _make_backend(backend)
if context is None:
context = Pickler(unpicklable=unpicklable,
@@ -38,7 +39,8 @@ def encode(value,
backend=backend,
max_depth=max_depth,
warn=warn,
- max_iter=max_iter)
+ max_iter=max_iter,
+ numeric_keys=numeric_keys)
return backend.encode(context.flatten(value, reset=reset))
@@ -58,12 +60,14 @@ class Pickler(object):
backend=None,
keys=False,
warn=False,
- max_iter=None):
+ max_iter=None,
+ numeric_keys=False):
self.unpicklable = unpicklable
self.make_refs = make_refs
self.backend = _make_backend(backend)
self.keys = keys
self.warn = warn
+ self.numeric_keys = numeric_keys
# The current recursion depth
self._depth = -1
# The maximal recursion depth
@@ -482,7 +486,10 @@ class Pickler(object):
else:
if k is None:
k = 'null' # for compatibility with common json encoders
- if not isinstance(k, (str, unicode)):
+
+ if self.numeric_keys and isinstance(k, numeric_types):
+ pass
+ elif not isinstance(k, (str, unicode)):
try:
k = repr(k)
except:
diff --git a/jsonpickle/unpickler.py b/jsonpickle/unpickler.py
index 7f246a5..737cadd 100644
--- a/jsonpickle/unpickler.py
+++ b/jsonpickle/unpickler.py
@@ -14,7 +14,7 @@ import jsonpickle.util as util
import jsonpickle.tags as tags
import jsonpickle.handlers as handlers
-from jsonpickle.compat import set
+from jsonpickle.compat import numeric_types, set, unicode
from jsonpickle.backend import JSONBackend
@@ -204,6 +204,7 @@ class Unpickler(object):
for k, v in dictitems:
stage1.__setitem__(k, v)
+ self._mkref(stage1)
return stage1
def _restore_id(self, obj):
@@ -315,7 +316,11 @@ class Unpickler(object):
# ignore the reserved attribute
if ignorereserved and k in tags.RESERVED:
continue
- self._namestack.append(k)
+ if isinstance(k, numeric_types):
+ str_k = unicode(k)
+ else:
+ str_k = k
+ self._namestack.append(str_k)
k = restore_key(k)
# step into the namespace
value = self._restore(v)
@@ -398,7 +403,11 @@ class Unpickler(object):
data = {}
restore_key = self._restore_key_fn()
for k, v in sorted(obj.items(), key=util.itemgetter):
- self._namestack.append(k)
+ if isinstance(k, numeric_types):
+ str_k = unicode(k)
+ else:
+ str_k = k
+ self._namestack.append(str_k)
k = restore_key(k)
data[k] = self._restore(v)
self._namestack.pop()
diff --git a/jsonpickle/version.py b/jsonpickle/version.py
index bb8bac8..aa11178 100644
--- a/jsonpickle/version.py
+++ b/jsonpickle/version.py
@@ -1 +1 @@
-VERSION = '0.9.2'
+VERSION = '0.9.3'
diff --git a/requirements-3.txt b/requirements-3.txt
index aec266b..095fbda 100644
--- a/requirements-3.txt
+++ b/requirements-3.txt
@@ -1,2 +1,4 @@
+feedparser
+demjson
simplejson
ujson
diff --git a/setup.py b/setup.py
index adcd45d..b9426ef 100644
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2008 John Paulett (john -at- paulett.org)
-# Copyright (C) 2009-2013 David Aguilar (davvid -at- gmail.com)
+# Copyright (C) 2009-2016 David Aguilar (davvid -at- gmail.com)
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
diff --git a/tests/backend_test.py b/tests/backend_test.py
index e973920..34eb157 100644
--- a/tests/backend_test.py
+++ b/tests/backend_test.py
@@ -107,13 +107,11 @@ def has_module(module):
class DemjsonTestCase(BackendBase):
+
def setUp(self):
- if PY2:
- self.set_preferred_backend('demjson')
+ self.set_preferred_backend('demjson')
def test_backend(self):
- if PY3:
- return self.skip('no demjson for python3')
expected_pickled = unicode(
'{"things":[{'
'"child":null,'
@@ -122,6 +120,13 @@ class DemjsonTestCase(BackendBase):
']}')
self.assertEncodeDecode(expected_pickled)
+ def test_int_dict_keys_with_numeric_keys(self):
+ jsonpickle.set_encoder_options('demjson', strict=False)
+ int_dict = {1000: [1, 2]}
+ pickle = jsonpickle.encode(int_dict, numeric_keys=True)
+ actual = jsonpickle.decode(pickle)
+ self.assertEqual(actual[1000], [1, 2])
+
class JsonlibTestCase(BackendBase):
def setUp(self):
@@ -141,12 +146,9 @@ class JsonlibTestCase(BackendBase):
class YajlTestCase(BackendBase):
def setUp(self):
- if PY2:
- self.set_preferred_backend('yajl')
+ self.set_preferred_backend('yajl')
def test_backend(self):
- if PY3:
- return self.skip('no yajl for python3')
expected_pickled = (
'{"things":[{'
'"py/object":"backend_test.Thing",'
@@ -175,11 +177,11 @@ def suite():
suite.addTest(unittest.makeSuite(UJsonTestCase))
if not PY32:
suite.addTest(unittest.makeSuite(SimpleJsonTestCase))
+ if has_module('demjson'):
+ suite.addTest(unittest.makeSuite(DemjsonTestCase))
+ if has_module('yajl'):
+ suite.addTest(unittest.makeSuite(YajlTestCase))
if PY2:
- if has_module('demjson'):
- suite.addTest(unittest.makeSuite(DemjsonTestCase))
- if has_module('yajl'):
- suite.addTest(unittest.makeSuite(YajlTestCase))
if has_module('jsonlib'):
suite.addTest(unittest.makeSuite(JsonlibTestCase))
return suite
diff --git a/tests/helper.py b/tests/helper.py
index 2711b57..91b0489 100644
--- a/tests/helper.py
+++ b/tests/helper.py
@@ -2,6 +2,7 @@ import unittest
class SkippableTest(unittest.TestCase):
+
def skip(self, msg):
if hasattr(self, 'skipTest'):
return self.skipTest(msg)
diff --git a/tests/numpy_test.py b/tests/numpy_test.py
index 68d29bf..a4a5858 100644
--- a/tests/numpy_test.py
+++ b/tests/numpy_test.py
@@ -25,6 +25,8 @@ class NumpyTestCase(SkippableTest):
jsonpickle.ext.numpy.register_handlers()
def tearDown(self):
+ if self.should_skip:
+ return
import jsonpickle.ext.numpy
jsonpickle.ext.numpy.unregister_handlers()
diff --git a/tests/object_test.py b/tests/object_test.py
index c85f366..faa6ebd 100644
--- a/tests/object_test.py
+++ b/tests/object_test.py
@@ -732,6 +732,17 @@ class AdvancedObjectsTestCase(SkippableTest):
self.assertEqual(ec.enum_a, decoded.enum_a)
self.assertEqual(ec.enum_b, decoded.enum_b)
+ def test_enum_references(self):
+ if IntEnumTest is None:
+ return self.skip('enum34 module is not installed')
+ a = IntEnumTest.X
+ b = IntEnumTest.X
+
+ enums_list = [a, b]
+ encoded = jsonpickle.encode(enums_list)
+ decoded = jsonpickle.decode(encoded)
+ self.assertEqual(enums_list, decoded)
+
def test_bytes_unicode(self):
b1 = b'foo'
b2 = b'foo\xff'
diff --git a/tests/runtests.py b/tests/runtests.py
index 28551e9..69cd7c2 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -21,6 +21,7 @@ import document_test
import handler_test
import jsonpickle_test
import object_test
+import stdlib_test
import util_test
import feedparser_test
import bson_test
@@ -36,6 +37,7 @@ def suite():
suite.addTest(datetime_test.suite())
suite.addTest(document_test.suite())
suite.addTest(object_test.suite())
+ suite.addTest(stdlib_test.suite())
suite.addTest(feedparser_test.suite())
suite.addTest(numpy_test.suite())
suite.addTest(bson_test.suite())
diff --git a/tests/stdlib_test.py b/tests/stdlib_test.py
new file mode 100644
index 0000000..2a0f10f
--- /dev/null
+++ b/tests/stdlib_test.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+"""Test miscellaneous objects from the standard library"""
+
+import uuid
+import unittest
+
+import jsonpickle
+
+
+class UUIDTestCase(unittest.TestCase):
+
+ def test_random_uuid(self):
+ u = uuid.uuid4()
+ encoded = jsonpickle.encode(u)
+ decoded = jsonpickle.decode(encoded)
+
+ expect = u.hex
+ actual = decoded.hex
+ self.assertEqual(expect, actual)
+
+ def test_known_uuid(self):
+ hex = '28b56adbd18f44e2a5556bba2f23e6f6'
+ exemplar = uuid.UUID(hex)
+ encoded = jsonpickle.encode(exemplar)
+ decoded = jsonpickle.decode(encoded)
+
+ expect = hex
+ actual = decoded.hex
+ self.assertEqual(expect, actual)
+
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(UUIDTestCase))
+ return suite
+
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='suite')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/jsonpickle.git
More information about the Python-modules-commits
mailing list