Skip to content

Commit

Permalink
Merge branch 'release/0.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhayes committed Nov 11, 2016
2 parents 9faf66a + a1ab2b8 commit 3e272fe
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
# Release 0.2.1 - Friday 11 November 15:54:21 AEDT 2016

- Ensure that lists with `None` value aren't turned into `[None]` (#7)

# Release 0.2.0 - Thursday 3 November 23:49:32 AEDT 2016

- Allow user to set XML encoding (#6)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.2.0
0.2.1
2 changes: 1 addition & 1 deletion schematics_xml/__init__.py
Expand Up @@ -10,7 +10,7 @@
'VersionInfo', ('major', 'minor', 'micro', 'releaselevel', 'serial'),
)

VERSION = VersionInfo(0, 2, 0, '', '')
VERSION = VersionInfo(0, 2, 1, '', '')
__version__ = '{0.major}.{0.minor}.{0.micro}{0.releaselevel}'.format(VERSION)
__author__ = 'Alex Hayes'
__contact__ = 'alex@alution.com'
Expand Down
4 changes: 4 additions & 0 deletions schematics_xml/models.py
Expand Up @@ -191,6 +191,10 @@ def ensure_lists_in_model(raw_data: dict, model_cls: XMLModel):

def ensure_lists_in_value(value: 'typing.Any', field: BaseType):

if value is None:
# Don't turn None items into a list of None items
return None

if isinstance(field, ListType):
if not isinstance(value, list):
value = [
Expand Down
34 changes: 34 additions & 0 deletions schematics_xml/tests/test_models.py
Expand Up @@ -842,6 +842,40 @@ class TestModel(XMLModel):
# Assert good data stays good
assert actual == expected

def test_model_with_listtype_of_none(self): # pylint: disable=no-self-use,invalid-name
"""
Ensure a model with a list type that has a value of None isn't turned into ``[None]``.
"""
class TestModel(XMLModel):
numbers = ListType(IntType())

bad_data = dict(numbers=None)
actual = ensure_lists_in_model(bad_data, TestModel)
expected = dict(numbers=None)
# Assert bad data can be turned good
assert actual == expected

actual = ensure_lists_in_model(expected, TestModel)
# Assert good data stays good
assert actual == expected

def test_model_with_listtype_of_mixed_value(self): # pylint: disable=no-self-use,invalid-name
"""
Ensure a model with a list type that has a value ``[1, None]`` is handled correctly.
"""
class TestModel(XMLModel):
numbers = ListType(IntType())

bad_data = dict(numbers=[1, None])
actual = ensure_lists_in_model(bad_data, TestModel)
expected = dict(numbers=[1, None])
# Assert bad data can be turned good
assert actual == expected

actual = ensure_lists_in_model(expected, TestModel)
# Assert good data stays good
assert actual == expected

def test_model_with_listtype_of_modeltype(self): # pylint: disable=no-self-use,invalid-name
"""
Test that a model with a list type of models can correctly be
Expand Down

0 comments on commit 3e272fe

Please sign in to comment.