only sort on order, SchemaNode is not comparable

fixes #279
This commit is contained in:
Michael Merickel
2017-01-31 23:02:54 -06:00
parent 16158817ab
commit 713b8807f1
3 changed files with 15 additions and 1 deletions

View File

@@ -4,6 +4,9 @@ unreleased
- Allow deferred schema nodes.
See https://github.com/Pylons/colander/pull/280
- Fix an issue when using a node multiple times in a schema by cloning it.
See https://github.com/Pylons/colander/issues/279
1.3.1 (2016-05-23)
==================

View File

@@ -2242,7 +2242,7 @@ class _SchemaMeta(type):
value.title = name.replace('_', ' ').title()
nodes.append((value._order, value))
nodes.sort()
nodes.sort(key=lambda n: n[0])
cls.__class_schema_nodes__ = [ n[1] for n in nodes ]
# Combine all attrs from this class and its _SchemaNode superclasses.

View File

@@ -3403,6 +3403,17 @@ class TestSchema(unittest.TestCase):
self.assertEqual(schema.schema_type, colander.Mapping)
self.assertEqual(schema.children[0], node)
def test_schema_with_cloned_nodes(self):
import colander
test_node = colander.SchemaNode(colander.String())
class TestSchema(colander.Schema):
a = test_node.clone()
b = test_node.clone()
node = TestSchema()
expected = {'a': 'foo', 'b': 'bar'}
result = node.serialize(expected)
self.assertEqual(result, expected)
class TestSequenceSchema(unittest.TestCase):
def test_succeed(self):
import colander