Skip to content

Commit

Permalink
Merge pull request #5 from miki725/caching-property-set
Browse files Browse the repository at this point in the history
* allowing cache property to be set via foo = “bar” syntax

* fixed flake8 violation and fixed py.test warnings when using Test* for non test-case classes

* using Py3.5 in travis

* bumping version to 0.1.1 [ci skip]

* pinning pytist to version range for travis to be happy
  • Loading branch information
miki725 committed Sep 27, 2016
2 parents 65fa950 + cee4bbb commit 9134304
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,7 +1,7 @@
language: python

python:
- "3.4"
- "3.5"
- "2.7"

env:
Expand Down
7 changes: 7 additions & 0 deletions HISTORY.rst
Expand Up @@ -3,6 +3,13 @@
History
-------

0.1.1 (2016-09-26)
~~~~~~~~~~~~~~~~~~

* Fixed: Cache properties now allow to set cache value via ``foo = bar``
syntax when cache descriptor has ``as_property == True``


0.1.0 (2015-11-26)
~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion django_auxilium/__init__.py
@@ -1,2 +1,2 @@
__version__ = '0.1'
__version__ = '0.1.1'
__author__ = 'Miroslav Shubernetskiy'
5 changes: 5 additions & 0 deletions django_auxilium/utils/functools/cache.py
Expand Up @@ -309,6 +309,11 @@ def __get__(self, instance, owner):
return f

def __set__(self, instance, value):
if self.as_property:
cache = self.get_cache(instance)
# no args and kwargs since this is only for case when cache is used as property
return cache.set(value)

# required to be overwritten for pypy
# see https://bitbucket.org/pypy/pypy/issues/2033/attributeerror-object-attribute-is-read
# even though ticket is resolved its still affecting pypy3
Expand Down
3 changes: 2 additions & 1 deletion django_auxilium/utils/functools/lazy.py
Expand Up @@ -216,7 +216,8 @@ def __getattribute__(self, name):
and for everything else returns attribute from the
computed lazy object.
"""
get = lambda x: object.__getattribute__(self, x)
def get(x):
return object.__getattribute__(self, x)

# retrieve lazy attributes as normal
if name.startswith('_lazy_'):
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Expand Up @@ -5,7 +5,7 @@ django-formtools
flake8
importanize
mock
pytest
pytest>=2.9
pytest-cov
pytest-django
python-magic
Expand Down
11 changes: 9 additions & 2 deletions tests/utils/functools/test_cache.py
Expand Up @@ -176,12 +176,19 @@ def test_get_instance_property(self):

assert self.instance.foo == 'bar'

def test_set_read_only(self):
self.descriptor.as_property = True
def test_set_read_only_method(self):
self.descriptor.as_property = False

with pytest.raises(AttributeError):
self.instance.foo = 'foo'

def test_set_writable_property(self):
self.descriptor.as_property = True

self.instance.foo = 'foo'

assert self.instance.foo == 'foo'

def test_delete_property_not_present(self):
self.descriptor.as_property = True

Expand Down
10 changes: 5 additions & 5 deletions tests/views/test_wizard.py
Expand Up @@ -5,15 +5,15 @@
from django_auxilium.views.wizard import WizardView


class TestForm(forms.Form):
class _TestForm(forms.Form):
pass


class TestWizardView(WizardView):
form_list = [TestForm]
class _TestWizardView(WizardView):
form_list = [_TestForm]


def test_wizard_view():
assert TestWizardView.get_initkwargs()['form_list'] == {
'0': TestForm,
assert _TestWizardView.get_initkwargs()['form_list'] == {
'0': _TestForm,
}

0 comments on commit 9134304

Please sign in to comment.