[Python-modules-commits] [django-picklefield] 04/15: Import django-picklefield_0.3.2.orig.tar.gz
Michael Fladischer
fladi at moszumanska.debian.org
Thu Mar 31 20:34:09 UTC 2016
This is an automated email from the git hooks/post-receive script.
fladi pushed a commit to tag debian/0.3.2-1
in repository django-picklefield.
commit 46c6809aea1dfa066aeea21190adb26876b77ee2
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date: Thu Mar 31 20:45:26 2016 +0200
Import django-picklefield_0.3.2.orig.tar.gz
---
PKG-INFO | 78 ++++++++++++++++++----------
README => README.rst | 72 ++++++++++++++++---------
setup.cfg | 13 +++++
setup.py | 18 +++----
src/django_picklefield.egg-info/PKG-INFO | 78 ++++++++++++++++++----------
src/django_picklefield.egg-info/SOURCES.txt | 4 +-
src/django_picklefield.egg-info/requires.txt | 1 -
src/picklefield/__init__.py | 2 +-
src/picklefield/compat.py | 23 ++++----
src/picklefield/fields.py | 49 +++++++----------
src/picklefield/tests.py | 54 ++++++++++---------
11 files changed, 227 insertions(+), 165 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index ac1d486..ccaa561 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,25 +1,31 @@
Metadata-Version: 1.1
Name: django-picklefield
-Version: 0.3.1
+Version: 0.3.2
Summary: Pickled object field for Django
Home-page: http://github.com/gintas/django-picklefield
Author: Gintautas Miliauskas
Author-email: gintautas at miliauskas.lt
License: UNKNOWN
-Description: -----
+Description: .. image:: https://travis-ci.org/gintas/django-picklefield.svg?branch=master
+ :target: https://travis-ci.org/gintas/django-picklefield
+
+ .. image:: https://coveralls.io/repos/gintas/django-picklefield/badge.svg?branch=master&service=github
+ :target: https://coveralls.io/github/gintas/django-picklefield?branch=master
+
+ -----
About
-----
**django-picklefield** provides an implementation of a pickled object field.
Such fields can contain any picklable objects.
- The implementation is taken and adopted from Django snippet #1694
- <http://www.djangosnippets.org/snippets/1694/> by Taavi Taijala, which is in
- turn based on Django snippet #513 <http://www.djangosnippets.org/snippets/513/>
- by Oliver Beattie.
+ The implementation is taken and adopted from `Django snippet #1694`_ by Taavi
+ Taijala, which is in turn based on `Django snippet #513`_ by Oliver Beattie.
django-picklefield is available under the MIT license.
+ .. _Django snippet #1694: http://www.djangosnippets.org/snippets/1694/
+ .. _Django snippet #513: http://www.djangosnippets.org/snippets/513/
-----
Usage
@@ -52,6 +58,17 @@ Description: -----
format is not convenient for parsing in the browser. By overriding
``value_to_string()`` you can choose a more convenient serialization format.
+ -------------
+ Running tests
+ -------------
+
+ The full test suite can be run with `Tox`_::
+
+ >>> pip install tox
+ >>> tox
+
+ .. _Tox: https://testrun.org/tox/latest/
+
--------------
Original notes
--------------
@@ -122,77 +139,84 @@ Description: -----
Changes
-------
+ Changes in version 0.3.2
+ ========================
+
+ * Dropped support for Django 1.3.
+ * Dropped support for Python 2.5.
+ * Silenced deprecation warnings on Django 1.8+.
+
Changes in version 0.3.1
========================
- * Favor the built in json module (thanks to Simon Charette).
+ * Favor the built in json module (thanks to Simon Charette).
Changes in version 0.3.0
========================
- * Python 3 support (thanks to Rafal Stozek).
+ * Python 3 support (thanks to Rafal Stozek).
Changes in version 0.2.0
========================
- * Allow pickling of subclasses of django.db.models.Model (thanks to Simon
- Charette).
+ * Allow pickling of subclasses of django.db.models.Model (thanks to Simon
+ Charette).
Changes in version 0.1.9
========================
- * Added `connection` and `prepared` parameters to `get_db_prep_value()` too
- (thanks to Matthew Schinckel).
+ * Added `connection` and `prepared` parameters to `get_db_prep_value()` too
+ (thanks to Matthew Schinckel).
Changes in version 0.1.8
========================
- * Updated link to code repository.
+ * Updated link to code repository.
Changes in version 0.1.7
========================
- * Added `connection` and `prepared` parameters to `get_db_prep_lookup()` to
- get rid of deprecation warnings in Django 1.2.
+ * Added `connection` and `prepared` parameters to `get_db_prep_lookup()` to
+ get rid of deprecation warnings in Django 1.2.
Changes in version 0.1.6
========================
- * Fixed South support (thanks aehlke at github).
+ * Fixed South support (thanks aehlke at github).
Changes in version 0.1.5
========================
- * Added support for South.
- * Changed default to null=False, as is common throughout Django.
+ * Added support for South.
+ * Changed default to null=False, as is common throughout Django.
Changes in version 0.1.4
========================
- * Updated copyright statements.
+ * Updated copyright statements.
Changes in version 0.1.3
========================
- * Updated serialization tests (thanks to Michael Fladischer).
+ * Updated serialization tests (thanks to Michael Fladischer).
Changes in version 0.1.2
========================
- * Added Simplified BSD licence.
+ * Added Simplified BSD licence.
Changes in version 0.1.1
========================
- * Added test for serialization.
- * Added note about JSON serialization for browser.
- * Added support for different pickle protocol versions (thanks to Michael
- Fladischer).
+ * Added test for serialization.
+ * Added note about JSON serialization for browser.
+ * Added support for different pickle protocol versions (thanks to Michael
+ Fladischer).
Changes in version 0.1
======================
- * First public release.
+ * First public release.
--------
@@ -210,8 +234,8 @@ Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
-Classifier: Programming Language :: Python :: 2.5
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
diff --git a/README b/README.rst
similarity index 74%
rename from README
rename to README.rst
index 8ac6bc6..dfce781 100644
--- a/README
+++ b/README.rst
@@ -1,3 +1,9 @@
+.. image:: https://travis-ci.org/gintas/django-picklefield.svg?branch=master
+ :target: https://travis-ci.org/gintas/django-picklefield
+
+.. image:: https://coveralls.io/repos/gintas/django-picklefield/badge.svg?branch=master&service=github
+ :target: https://coveralls.io/github/gintas/django-picklefield?branch=master
+
-----
About
-----
@@ -5,13 +11,13 @@ About
**django-picklefield** provides an implementation of a pickled object field.
Such fields can contain any picklable objects.
-The implementation is taken and adopted from Django snippet #1694
-<http://www.djangosnippets.org/snippets/1694/> by Taavi Taijala, which is in
-turn based on Django snippet #513 <http://www.djangosnippets.org/snippets/513/>
-by Oliver Beattie.
+The implementation is taken and adopted from `Django snippet #1694`_ by Taavi
+Taijala, which is in turn based on `Django snippet #513`_ by Oliver Beattie.
django-picklefield is available under the MIT license.
+.. _Django snippet #1694: http://www.djangosnippets.org/snippets/1694/
+.. _Django snippet #513: http://www.djangosnippets.org/snippets/513/
-----
Usage
@@ -44,6 +50,17 @@ base64-encoded pickles, which allows reliable deserialization, but such a
format is not convenient for parsing in the browser. By overriding
``value_to_string()`` you can choose a more convenient serialization format.
+-------------
+Running tests
+-------------
+
+The full test suite can be run with `Tox`_::
+
+ >>> pip install tox
+ >>> tox
+
+.. _Tox: https://testrun.org/tox/latest/
+
--------------
Original notes
--------------
@@ -114,77 +131,84 @@ since it is never a good idea to have a PickledObjectField be user editable.
Changes
-------
+Changes in version 0.3.2
+========================
+
+* Dropped support for Django 1.3.
+* Dropped support for Python 2.5.
+* Silenced deprecation warnings on Django 1.8+.
+
Changes in version 0.3.1
========================
- * Favor the built in json module (thanks to Simon Charette).
+* Favor the built in json module (thanks to Simon Charette).
Changes in version 0.3.0
========================
- * Python 3 support (thanks to Rafal Stozek).
+* Python 3 support (thanks to Rafal Stozek).
Changes in version 0.2.0
========================
- * Allow pickling of subclasses of django.db.models.Model (thanks to Simon
- Charette).
+* Allow pickling of subclasses of django.db.models.Model (thanks to Simon
+ Charette).
Changes in version 0.1.9
========================
- * Added `connection` and `prepared` parameters to `get_db_prep_value()` too
- (thanks to Matthew Schinckel).
+* Added `connection` and `prepared` parameters to `get_db_prep_value()` too
+ (thanks to Matthew Schinckel).
Changes in version 0.1.8
========================
- * Updated link to code repository.
+* Updated link to code repository.
Changes in version 0.1.7
========================
- * Added `connection` and `prepared` parameters to `get_db_prep_lookup()` to
- get rid of deprecation warnings in Django 1.2.
+* Added `connection` and `prepared` parameters to `get_db_prep_lookup()` to
+ get rid of deprecation warnings in Django 1.2.
Changes in version 0.1.6
========================
- * Fixed South support (thanks aehlke at github).
+* Fixed South support (thanks aehlke at github).
Changes in version 0.1.5
========================
- * Added support for South.
- * Changed default to null=False, as is common throughout Django.
+* Added support for South.
+* Changed default to null=False, as is common throughout Django.
Changes in version 0.1.4
========================
- * Updated copyright statements.
+* Updated copyright statements.
Changes in version 0.1.3
========================
- * Updated serialization tests (thanks to Michael Fladischer).
+* Updated serialization tests (thanks to Michael Fladischer).
Changes in version 0.1.2
========================
- * Added Simplified BSD licence.
+* Added Simplified BSD licence.
Changes in version 0.1.1
========================
- * Added test for serialization.
- * Added note about JSON serialization for browser.
- * Added support for different pickle protocol versions (thanks to Michael
- Fladischer).
+* Added test for serialization.
+* Added note about JSON serialization for browser.
+* Added support for different pickle protocol versions (thanks to Michael
+ Fladischer).
Changes in version 0.1
======================
- * First public release.
+* First public release.
--------
diff --git a/setup.cfg b/setup.cfg
index 861a9f5..f314eba 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,3 +1,16 @@
+[flake8]
+max-line-length = 119
+
+[isort]
+combine_as_imports = true
+include_trailing_comma = true
+known_third_party = picklefield,south
+multi_line_output = 5
+not_skip = __init__.py
+
+[wheel]
+universal = 1
+
[egg_info]
tag_build =
tag_date = 0
diff --git a/setup.py b/setup.py
index 1bd0b53..51c3145 100644
--- a/setup.py
+++ b/setup.py
@@ -22,32 +22,28 @@
import codecs
from setuptools import setup, find_packages
+long_description = codecs.open('README.rst', encoding='utf-8').read()
-DESC=codecs.open('README', encoding='utf-8').read()
-
-
-setup(name='django-picklefield',
- version='0.3.1',
+setup(
+ name='django-picklefield',
+ version='0.3.2',
description='Pickled object field for Django',
- long_description=DESC,
+ long_description=long_description,
author='Gintautas Miliauskas',
author_email='gintautas at miliauskas.lt',
url='http://github.com/gintas/django-picklefield',
packages=find_packages('src'),
- package_dir={'' : 'src'},
- install_requires=[
- 'six',
- ],
+ package_dir={'': 'src'},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
- 'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
+ 'Programming Language :: Python :: 3.4',
]
)
diff --git a/src/django_picklefield.egg-info/PKG-INFO b/src/django_picklefield.egg-info/PKG-INFO
index ac1d486..ccaa561 100644
--- a/src/django_picklefield.egg-info/PKG-INFO
+++ b/src/django_picklefield.egg-info/PKG-INFO
@@ -1,25 +1,31 @@
Metadata-Version: 1.1
Name: django-picklefield
-Version: 0.3.1
+Version: 0.3.2
Summary: Pickled object field for Django
Home-page: http://github.com/gintas/django-picklefield
Author: Gintautas Miliauskas
Author-email: gintautas at miliauskas.lt
License: UNKNOWN
-Description: -----
+Description: .. image:: https://travis-ci.org/gintas/django-picklefield.svg?branch=master
+ :target: https://travis-ci.org/gintas/django-picklefield
+
+ .. image:: https://coveralls.io/repos/gintas/django-picklefield/badge.svg?branch=master&service=github
+ :target: https://coveralls.io/github/gintas/django-picklefield?branch=master
+
+ -----
About
-----
**django-picklefield** provides an implementation of a pickled object field.
Such fields can contain any picklable objects.
- The implementation is taken and adopted from Django snippet #1694
- <http://www.djangosnippets.org/snippets/1694/> by Taavi Taijala, which is in
- turn based on Django snippet #513 <http://www.djangosnippets.org/snippets/513/>
- by Oliver Beattie.
+ The implementation is taken and adopted from `Django snippet #1694`_ by Taavi
+ Taijala, which is in turn based on `Django snippet #513`_ by Oliver Beattie.
django-picklefield is available under the MIT license.
+ .. _Django snippet #1694: http://www.djangosnippets.org/snippets/1694/
+ .. _Django snippet #513: http://www.djangosnippets.org/snippets/513/
-----
Usage
@@ -52,6 +58,17 @@ Description: -----
format is not convenient for parsing in the browser. By overriding
``value_to_string()`` you can choose a more convenient serialization format.
+ -------------
+ Running tests
+ -------------
+
+ The full test suite can be run with `Tox`_::
+
+ >>> pip install tox
+ >>> tox
+
+ .. _Tox: https://testrun.org/tox/latest/
+
--------------
Original notes
--------------
@@ -122,77 +139,84 @@ Description: -----
Changes
-------
+ Changes in version 0.3.2
+ ========================
+
+ * Dropped support for Django 1.3.
+ * Dropped support for Python 2.5.
+ * Silenced deprecation warnings on Django 1.8+.
+
Changes in version 0.3.1
========================
- * Favor the built in json module (thanks to Simon Charette).
+ * Favor the built in json module (thanks to Simon Charette).
Changes in version 0.3.0
========================
- * Python 3 support (thanks to Rafal Stozek).
+ * Python 3 support (thanks to Rafal Stozek).
Changes in version 0.2.0
========================
- * Allow pickling of subclasses of django.db.models.Model (thanks to Simon
- Charette).
+ * Allow pickling of subclasses of django.db.models.Model (thanks to Simon
+ Charette).
Changes in version 0.1.9
========================
- * Added `connection` and `prepared` parameters to `get_db_prep_value()` too
- (thanks to Matthew Schinckel).
+ * Added `connection` and `prepared` parameters to `get_db_prep_value()` too
+ (thanks to Matthew Schinckel).
Changes in version 0.1.8
========================
- * Updated link to code repository.
+ * Updated link to code repository.
Changes in version 0.1.7
========================
- * Added `connection` and `prepared` parameters to `get_db_prep_lookup()` to
- get rid of deprecation warnings in Django 1.2.
+ * Added `connection` and `prepared` parameters to `get_db_prep_lookup()` to
+ get rid of deprecation warnings in Django 1.2.
Changes in version 0.1.6
========================
- * Fixed South support (thanks aehlke at github).
+ * Fixed South support (thanks aehlke at github).
Changes in version 0.1.5
========================
- * Added support for South.
- * Changed default to null=False, as is common throughout Django.
+ * Added support for South.
+ * Changed default to null=False, as is common throughout Django.
Changes in version 0.1.4
========================
- * Updated copyright statements.
+ * Updated copyright statements.
Changes in version 0.1.3
========================
- * Updated serialization tests (thanks to Michael Fladischer).
+ * Updated serialization tests (thanks to Michael Fladischer).
Changes in version 0.1.2
========================
- * Added Simplified BSD licence.
+ * Added Simplified BSD licence.
Changes in version 0.1.1
========================
- * Added test for serialization.
- * Added note about JSON serialization for browser.
- * Added support for different pickle protocol versions (thanks to Michael
- Fladischer).
+ * Added test for serialization.
+ * Added note about JSON serialization for browser.
+ * Added support for different pickle protocol versions (thanks to Michael
+ Fladischer).
Changes in version 0.1
======================
- * First public release.
+ * First public release.
--------
@@ -210,8 +234,8 @@ Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
-Classifier: Programming Language :: Python :: 2.5
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
diff --git a/src/django_picklefield.egg-info/SOURCES.txt b/src/django_picklefield.egg-info/SOURCES.txt
index 3901fed..2eebcb3 100644
--- a/src/django_picklefield.egg-info/SOURCES.txt
+++ b/src/django_picklefield.egg-info/SOURCES.txt
@@ -1,9 +1,9 @@
-README
+README.rst
+setup.cfg
setup.py
src/django_picklefield.egg-info/PKG-INFO
src/django_picklefield.egg-info/SOURCES.txt
src/django_picklefield.egg-info/dependency_links.txt
-src/django_picklefield.egg-info/requires.txt
src/django_picklefield.egg-info/top_level.txt
src/picklefield/__init__.py
src/picklefield/compat.py
diff --git a/src/django_picklefield.egg-info/requires.txt b/src/django_picklefield.egg-info/requires.txt
deleted file mode 100644
index 64c56a3..0000000
--- a/src/django_picklefield.egg-info/requires.txt
+++ /dev/null
@@ -1 +0,0 @@
-six
\ No newline at end of file
diff --git a/src/picklefield/__init__.py b/src/picklefield/__init__.py
index d8269fd..c5098e2 100644
--- a/src/picklefield/__init__.py
+++ b/src/picklefield/__init__.py
@@ -2,4 +2,4 @@
DEFAULT_PROTOCOL = 2
-from picklefield.fields import PickledObjectField # reexport
+from picklefield.fields import PickledObjectField # noqa
diff --git a/src/picklefield/compat.py b/src/picklefield/compat.py
index e2d617a..e38997d 100644
--- a/src/picklefield/compat.py
+++ b/src/picklefield/compat.py
@@ -1,18 +1,15 @@
-# django 1.5 introduces force_text instead of force_unicode
-try:
- from django.utils.encoding import force_text
-except ImportError:
- from django.utils.encoding import force_unicode as force_text
+import django
+from django.db import models
+from django.utils import six
# python 3.x does not have cPickle module
try:
- from cPickle import loads, dumps # cpython 2.x
+ # cpython 2.x
+ from cPickle import loads, dumps # noqa
except ImportError:
- from pickle import loads, dumps # cpython 3.x, other interpreters
+ from pickle import loads, dumps # noqa
-# django 1.6 will deprecate django.utils.simple_json
-try:
- import json
-except ImportError:
- from django.utils import simplejson as json
-
+if django.VERSION >= (1, 8):
+ _PickledObjectField = models.Field
+else:
+ _PickledObjectField = six.with_metaclass(models.SubfieldBase, models.Field)
diff --git a/src/picklefield/fields.py b/src/picklefield/fields.py
index 4bc6eeb..c53f491 100644
--- a/src/picklefield/fields.py
+++ b/src/picklefield/fields.py
@@ -1,13 +1,12 @@
"""Pickle field implementation for Django."""
+from base64 import b64decode, b64encode
from copy import deepcopy
-from base64 import b64encode, b64decode
from zlib import compress, decompress
-import six
-import django
-from django.db import models
-from picklefield import DEFAULT_PROTOCOL
-from picklefield.compat import force_text, loads, dumps
+from django.utils.encoding import force_text
+
+from . import DEFAULT_PROTOCOL
+from .compat import _PickledObjectField, dumps, loads
class PickledObject(str):
@@ -26,10 +25,10 @@ class PickledObject(str):
class _ObjectWrapper(object):
"""
- A class used to wrap object that have properties that may clash with the
+ A class used to wrap object that have properties that may clash with the
ORM internals.
-
- For example, objects with the `prepare_database_save` property such as
+
+ For example, objects with the `prepare_database_save` property such as
`django.db.Model` subclasses won't work under certain conditions and the
same apply for trying to retrieve any `callable` object.
"""
@@ -55,28 +54,19 @@ def dbsafe_encode(value, compress_object=False, pickle_protocol=DEFAULT_PROTOCOL
value = dumps(deepcopy(value), protocol=pickle_protocol)
if compress_object:
value = compress(value)
- value = b64encode(value).decode() # decode bytes to str
+ value = b64encode(value).decode() # decode bytes to str
return PickledObject(value)
def dbsafe_decode(value, compress_object=False):
- value = value.encode() # encode str to bytes
+ value = value.encode() # encode str to bytes
value = b64decode(value)
if compress_object:
value = decompress(value)
return loads(value)
-def _get_subfield_superclass():
- # hardcore trick to support django < 1.3 - there was something wrong with
- # inheritance and SubfieldBase before django 1.3
- # see https://github.com/django/django/commit/222c73261650201f5ce99e8dd4b1ce0d30a69eb4
- if django.VERSION < (1,3):
- return models.Field
- return six.with_metaclass(models.SubfieldBase, models.Field)
-
-
-class PickledObjectField(_get_subfield_superclass()):
+class PickledObjectField(_PickledObjectField):
"""
A field that will accept *any* python object and store it in the
database. PickledObjectField will optionally compress its values if
@@ -86,7 +76,6 @@ class PickledObjectField(_get_subfield_superclass()):
can still do lookups using None). This way, it is still possible to
use the ``isnull`` lookup type correctly.
"""
- __metaclass__ = models.SubfieldBase # for django < 1.3
def __init__(self, *args, **kwargs):
self.compress = kwargs.pop('compress', False)
@@ -140,6 +129,9 @@ class PickledObjectField(_get_subfield_superclass()):
value = super(PickledObjectField, self).pre_save(model_instance, add)
return wrap_conflictual_object(value)
+ def from_db_value(self, value, expression, connection, context):
+ return self.to_python(value)
+
def get_db_prep_value(self, value, connection=None, prepared=False):
"""
Pickle and b64encode the object, optionally compressing it.
@@ -162,7 +154,7 @@ class PickledObjectField(_get_subfield_superclass()):
return value
def value_to_string(self, obj):
- value = self._get_val_from_obj(obj)
+ value = self.value_from_object(obj)
return self.get_db_prep_value(value)
def get_internal_type(self):
@@ -173,14 +165,9 @@ class PickledObjectField(_get_subfield_superclass()):
raise TypeError('Lookup type %s is not supported.' % lookup_type)
# The Field model already calls get_db_prep_value before doing the
# actual lookup, so all we need to do is limit the lookup types.
- try:
- return super(PickledObjectField, self).get_db_prep_lookup(
- lookup_type, value, connection=connection, prepared=prepared)
- except TypeError:
- # Try not to break on older versions of Django, where the
- # `connection` and `prepared` parameters are not available.
- return super(PickledObjectField, self).get_db_prep_lookup(
- lookup_type, value)
+ return super(PickledObjectField, self).get_db_prep_lookup(
+ lookup_type, value, connection=connection, prepared=prepared
+ )
# South support; see http://south.aeracode.org/docs/tutorial/part4.html#simple-inheritance
diff --git a/src/picklefield/tests.py b/src/picklefield/tests.py
index ea766f4..2430b21 100644
--- a/src/picklefield/tests.py
+++ b/src/picklefield/tests.py
@@ -1,12 +1,11 @@
"""Unit tests for django-picklefield."""
+import json
-from django.test import TestCase
-from django.db import models
from django.core import serializers
-from picklefield.compat import json
-from picklefield.fields import (PickledObjectField, wrap_conflictual_object,
- dbsafe_encode)
+from django.db import models
+from django.test import TestCase
+from .fields import PickledObjectField, dbsafe_encode, wrap_conflictual_object
S1 = 'Hello World'
T1 = (1, 2, 3, 4, 5)
@@ -42,14 +41,13 @@ class PickledObjectFieldTests(TestCase):
the database, whether compression is enabled or not.
"""
for value in self.testing_data:
- model_test = TestingModel(pickle_field=value,
- compressed_pickle_field=value)
+ model_test = TestingModel(pickle_field=value, compressed_pickle_field=value)
model_test.save()
model_test = TestingModel.objects.get(id__exact=model_test.id)
# Make sure that both the compressed and uncompressed fields return
# the same data, even thought it's stored differently in the DB.
- self.assertEquals(value, model_test.pickle_field)
- self.assertEquals(value, model_test.compressed_pickle_field)
+ self.assertEqual(value, model_test.pickle_field)
+ self.assertEqual(value, model_test.compressed_pickle_field)
# Make sure we can also retrieve the model
model_test.save()
model_test.delete()
@@ -59,8 +57,7 @@ class PickledObjectFieldTests(TestCase):
model_test = TestingModel()
model_test.save()
model_test = TestingModel.objects.get(id__exact=model_test.id)
- self.assertEquals((D1, S1, T1, L1),
- model_test.default_pickle_field)
+ self.assertEqual((D1, S1, T1, L1), model_test.default_pickle_field)
def testLookups(self):
"""
@@ -116,7 +113,7 @@ class PickledObjectFieldTests(TestCase):
>>> dumps(copy(t))
"((dp1\nI1\nI1\nsI2\nI4\nsI3\nI6\nsI4\nI8\nsI5\nI10\nsS'Hello World'\n(I1\nI2\nI3\nI4\nI5\nt(lp2\nI1\naI2\naI3\naI4\naI5\natp3\n."
- """
+ """ # noqa
for value in self.testing_data:
model_test = TestingModel(pickle_field=value, compressed_pickle_field=value)
model_test.save()
@@ -125,16 +122,16 @@ class PickledObjectFieldTests(TestCase):
wrapped_value = wrap_conflictual_object(value)
model_test = TestingModel.objects.get(pickle_field__exact=wrapped_value,
compressed_pickle_field__exact=wrapped_value)
- self.assertEquals(value, model_test.pickle_field)
- self.assertEquals(value, model_test.compressed_pickle_field)
+ self.assertEqual(value, model_test.pickle_field)
+ self.assertEqual(value, model_test.compressed_pickle_field)
# Make sure that ``in`` lookups also work correctly.
model_test = TestingModel.objects.get(pickle_field__in=[wrapped_value],
compressed_pickle_field__in=[wrapped_value])
- self.assertEquals(value, model_test.pickle_field)
- self.assertEquals(value, model_test.compressed_pickle_field)
+ self.assertEqual(value, model_test.pickle_field)
+ self.assertEqual(value, model_test.compressed_pickle_field)
# Make sure that ``is_null`` lookups are working.
- self.assertEquals(1, TestingModel.objects.filter(pickle_field__isnull=False).count())
- self.assertEquals(0, TestingModel.objects.filter(pickle_field__isnull=True).count())
+ self.assertEqual(1, TestingModel.objects.filter(pickle_field__isnull=False).count())
+ self.assertEqual(0, TestingModel.objects.filter(pickle_field__isnull=True).count())
model_test.delete()
# Make sure that lookups of the same value work, even when referenced
@@ -144,17 +141,17 @@ class PickledObjectFieldTests(TestCase):
model_test.save()
# Test lookup using an assigned variable.
model_test = TestingModel.objects.get(pickle_field__exact=value)
- self.assertEquals(value, model_test.pickle_field)
+ self.assertEqual(value, model_test.pickle_field)
# Test lookup using direct input of a matching value.
model_test = TestingModel.objects.get(
- pickle_field__exact = (D1, S1, T1, L1),
- compressed_pickle_field__exact = (D1, S1, T1, L1),
+ pickle_field__exact=(D1, S1, T1, L1),
+ compressed_pickle_field__exact=(D1, S1, T1, L1),
)
- self.assertEquals(value, model_test.pickle_field)
+ self.assertEqual(value, model_test.pickle_field)
model_test.delete()
def testSerialization(self):
- model = MinimalTestingModel(pickle_field={'foo': 'bar'})
+ model = MinimalTestingModel(pk=1, pickle_field={'foo': 'bar'})
serialized = serializers.serialize('json', [model])
data = json.loads(serialized)
@@ -162,10 +159,11 @@ class PickledObjectFieldTests(TestCase):
# is different (but compatible with python 2)
p = dbsafe_encode({'foo': 'bar'})
- self.assertEquals(data,
- [{'pk': None, 'model': 'picklefield.minimaltestingmodel',
- 'fields': {"pickle_field": p}}])
+ self.assertEqual(data, [{
+ 'pk': 1,
+ 'model': 'picklefield.minimaltestingmodel',
+ 'fields': {"pickle_field": p}},
+ ])
for deserialized_test in serializers.deserialize('json', serialized):
- self.assertEquals(deserialized_test.object,
- model)
+ self.assertEqual(deserialized_test.object, model)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-picklefield.git
More information about the Python-modules-commits
mailing list