Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Apr 29, 2016
2 parents dc0fdbe + bfd7fe9 commit f662c07
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision History

## 0.8.1 (2016/04/28)

- Now invoking `__init__` in `Dictionary` converters to run custom validations.

## 0.8 (2016/04/14)

- Replaced all utility functions with ORM-like tools.
Expand Down
20 changes: 16 additions & 4 deletions tests/test_nested_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@
from unittest.mock import patch
import logging

from expecter import expect

import yorm

from . import strip


@yorm.attr(status=yorm.types.Boolean)
@yorm.attr(checked=yorm.types.Integer)
class StatusDictionary(yorm.types.Dictionary):

pass
def __init__(self, status, checked):
self.status = status
self.checked = checked
if self.checked == 42:
raise RuntimeError


@yorm.attr(all=yorm.types.Float)
Expand Down Expand Up @@ -309,17 +316,17 @@ def test_alias_list(self):
def test_alias_dict(self):
var5_ref = self.sample.var5
self._log_ref('var5', self.sample.var5, var5_ref)
assert {'status': False} == self.sample.var5
assert {'status': False, 'checked': 0} == self.sample.var5

logging.info("Setting status=True in var5_ref...")
var5_ref['status'] = True
self._log_ref('var5', self.sample.var5, var5_ref)
assert {'status': True} == self.sample.var5
assert {'status': True, 'checked': 0} == self.sample.var5

logging.info("Setting status=False in var5_ref...")
var5_ref['status'] = False
self._log_ref('var5', self.sample.var5, var5_ref)
assert {'status': False} == self.sample.var5
assert {'status': False, 'checked': 0} == self.sample.var5

def test_alias_dict_in_list(self):
top = Top()
Expand All @@ -340,3 +347,8 @@ def test_alias_list_in_dict(self):
ref2 = top.nested_dict.nested_list_2
assert id(ref1) == id(top.nested_dict)
assert id(ref2) == id(top.nested_dict.nested_list_2)

def test_custom_init_is_invoked(self):
self.sample.__mapper__.text = "var5:\n checked: 42"
with expect.raises(RuntimeError):
print(self.sample.var5)
2 changes: 1 addition & 1 deletion yorm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

__project__ = 'YORM'
__version__ = '0.8'
__version__ = '0.8.1.post1'

VERSION = __project__ + '-' + __version__

Expand Down
6 changes: 6 additions & 0 deletions yorm/types/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ def update_value(self, data, *, auto_track=True):
msg = "Default value for missing nested object attribute: %s = %r"
log.info(msg, name, value[name])

# Execute custom __init__ validations
try:
cls(**value)
except TypeError as exception:
log.warning("%s: %s", cls.__name__, exception)

# Apply the new value
self.clear()
self.update(value)
Expand Down

0 comments on commit f662c07

Please sign in to comment.