Skip to content

Commit

Permalink
Merge branch 'release/v1.0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
twidi committed Feb 12, 2016
2 parents ec7f8b2 + 5f370ba commit 6efa607
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 28 deletions.
21 changes: 19 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
language: python
sudo: false

cache:
directories:
- $HOME/.cache/pip

python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"

env:
- DJANGO="Django<1.6"
- DJANGO="Django<1.7"
- DJANGO="Django<1.8"
- DJANGO="Django>=1.8"
- DJANGO="Django<1.9"
- DJANGO="Django<1.10"

install:
- pip install -q $DJANGO
Expand All @@ -22,6 +29,12 @@ script: "python -m extended_choices.tests"

matrix:
exclude:
- python: "3.5"
env: DJANGO="Django<1.6"
- python: "3.5"
env: DJANGO="Django<1.7"
- python: "3.5"
env: DJANGO="Django<1.8"

- python: "3.4"
env: DJANGO="Django<1.6"
Expand All @@ -30,8 +43,12 @@ matrix:

- python: "3.3"
env: DJANGO="Django<1.6"
- python: "3.3"
env: DJANGO="Django<1.10"

- python: "2.6"
env: DJANGO="Django<1.8"
- python: "2.6"
env: DJANGO="Django>=1.8"
env: DJANGO="Django<1.9"
- python: "2.6"
env: DJANGO="Django<1.10"
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

Release *v1.0.6* - ``2016-02-12``
---------------------------------
* add compatibility with "display" values set using ``ugettext_lazy``

Release *v1.0.5* - ``2015-10-14``
---------------------------------
* add compatibility with the ``pickle`` module
Expand Down
2 changes: 1 addition & 1 deletion extended_choices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
__author__ = 'Stephane "Twidi" Ange;'
__contact__ = "[email protected]"
__homepage__ = "https://pypi.python.org/pypi/django-extended-choices"
__version__ = "1.0.5"
__version__ = "1.0.6"
11 changes: 3 additions & 8 deletions extended_choices/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class ChoiceAttributeMixin(object):
Returns the choice field holding the value of the attached ``ChoiceEntry``.
display : property
Returns the choice field holding the display name of the attached ``ChoiceEntry``.
original_type : type (class attribute)
The class of the value used to create a new class.
original_value : ?
The value used to create the current instance.
creator_type : type
The class that created a new class. Will be ``ChoiceAttributeMixin`` except if it was
overridden by the author.
Expand Down Expand Up @@ -112,6 +112,7 @@ def __init__(self, value, choice_entry):
else:
super(ChoiceAttributeMixin, self).__init__()

self.original_value = value
self.choice_entry = choice_entry

@property
Expand All @@ -129,11 +130,6 @@ def display(self):
"""Property that returns the ``display`` attribute of the attached ``ChoiceEntry``."""
return self.choice_entry.display

@property
def original_value(self):
"""Return the original value used to create the current instance."""
return self.original_type(self)

@classmethod
def get_class_for_value(cls, value):
"""Class method to construct a class based on this mixin and the type of the given value.
Expand Down Expand Up @@ -161,7 +157,6 @@ def get_class_for_value(cls, value):
class_name = str('%sChoiceAttribute' % type_.__name__.capitalize())
# Create a new class and save it in the cache.
cls._classes_by_type[type_] = type(class_name, (cls, type_), {
'original_type': type_,
'creator_type': cls,
})

Expand Down
54 changes: 39 additions & 15 deletions extended_choices/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from __future__ import unicode_literals

import os, sys
from copy import copy, deepcopy

try:
import cPickle as pickle
Expand All @@ -38,6 +39,7 @@
settings.configure(DATABASE_ENGINE='sqlite3')

from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy

from .choices import Choices
from .fields import NamedExtendedChoiceFormField
Expand Down Expand Up @@ -924,13 +926,13 @@ def test_pickle_choice_entry(self):
self.assertEqual(unpickled_entry.value, 1)

def test_pickle_choice(self):
"""Test that a choice object could be pickled and unpickled."""
"""Test that a choices object could be pickled and unpickled."""

# Simple choice
pickled_choice = pickle.dumps(self.MY_CHOICES)
unpickled_choice = pickle.loads(pickled_choice)
pickled_choices = pickle.dumps(self.MY_CHOICES)
unpickled_choices = pickle.loads(pickled_choices)

self.assertEqual(unpickled_choice, self.MY_CHOICES)
self.assertEqual(unpickled_choices, self.MY_CHOICES)

# With a name, extra arguments and subsets
OTHER_CHOICES = Choices(
Expand All @@ -945,19 +947,41 @@ def test_pickle_choice(self):
OTHER_CHOICES.add_subset("ODD", ("ONE", "THREE"))
OTHER_CHOICES.add_subset("EVEN", ("TWO", ))

pickled_choice = pickle.dumps(OTHER_CHOICES)
unpickled_choice = pickle.loads(pickled_choice)
pickled_choices = pickle.dumps(OTHER_CHOICES)
unpickled_choices = pickle.loads(pickled_choices)

self.assertEqual(unpickled_choices, OTHER_CHOICES)
self.assertEqual(unpickled_choices.dict_class, OrderedDict)
self.assertFalse(unpickled_choices.retro_compatibility)
self.assertFalse(unpickled_choices._mutable)
self.assertEqual(unpickled_choices.subsets, OTHER_CHOICES.subsets)
self.assertEqual(unpickled_choices.ALL, OTHER_CHOICES.ALL)
self.assertEqual(unpickled_choices.ODD, OTHER_CHOICES.ODD)
self.assertEqual(unpickled_choices.EVEN, OTHER_CHOICES.EVEN)

def test_django_ugettext_lazy(self):
"""Test that a choices object using ugettext_lazy could be pickled and copied."""

lazy_choices = Choices(
('ONE', 1, ugettext_lazy('One for the money')),
('TWO', 2, ugettext_lazy('Two for the show')),
('THREE', 3, ugettext_lazy('Three to get ready')),
)

# try to pickel it, it should not raise
pickled_choices = pickle.dumps(lazy_choices)
unpickled_choices = pickle.loads(pickled_choices)

self.assertEqual(unpickled_choices, lazy_choices)

self.assertEqual(unpickled_choice, OTHER_CHOICES)
self.assertEqual(unpickled_choice.dict_class, OrderedDict)
self.assertFalse(unpickled_choice.retro_compatibility)
self.assertFalse(unpickled_choice._mutable)
self.assertEqual(unpickled_choice.subsets, OTHER_CHOICES.subsets)
self.assertEqual(unpickled_choice.ALL, OTHER_CHOICES.ALL)
self.assertEqual(unpickled_choice.ODD, OTHER_CHOICES.ODD)
self.assertEqual(unpickled_choice.EVEN, OTHER_CHOICES.EVEN)
# try to copy it, it should not raise
copied_choices = copy(lazy_choices)
self.assertEqual(copied_choices, lazy_choices)

# try to deep-copy it, it should not raise
deep_copied_choices = deepcopy(lazy_choices)
self.assertEqual(deep_copied_choices, lazy_choices)


if __name__ == "__main__":
unittest.main()
unittest.main()
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from setuptools import setup, find_packages
import sys


def read_relative_file(filename):
"""Returns contents of the given file, which path is supposed relative
to this module."""
Expand All @@ -18,7 +19,7 @@ def read_relative_file(filename):

setup(
name="django-extended-choices",
version="1.0.5",
version="1.0.6",
license="BSD",
description="Little helper application to improve django choices"
"(for fields)",
Expand All @@ -29,7 +30,7 @@ def read_relative_file(filename):
install_requires=install_requires,
packages=find_packages(),
include_package_data=True,
extras_require= {
extras_require={
'dev': ['django'],
'makedoc': ['django', 'sphinx', 'sphinxcontrib-napoleon', 'sphinx_rtd_theme'],
},
Expand Down

0 comments on commit 6efa607

Please sign in to comment.