jason kirtland avatar jason kirtland committed 255aa2c

Use "Unset" sentinal value for initial .raw, reset .raw when calling set_flat(), unicode literals fix for tests.

Comments (0)

Files changed (7)

flatland/__init__.py

                 'String',
                 'Time',
                 'Unevaluated',
+                'Unset',
                 ),
      'signals': (),
      'util': ('Unspecified', 'class_cloner',),

flatland/schema/__init__.py

     SkipAllFalse,
     Slot,
     Unevaluated,
+    Unset,
     )
 from .scalars import (
     Boolean,

flatland/schema/base.py

 NoneType = type(None)
 Root = symbol('Root')
 NotEmpty = symbol('NotEmpty')
+Unset = symbol('Unset')
 
 Skip = named_int_factory('Skip', True, doc="""\
 Abort validation of the element & mark as valid.
     :meth:`set` to update the element's value.
     """
 
-    raw = None
+    raw = Unset
     """The element's raw, unadapted value from input."""
 
     u = u''
         structured tree of value elements.
 
         """
+        self.raw = Unset
         if hasattr(pairs, 'items'):
             pairs = pairs.items()
 

tests/schema/test_containers.py

     assert el.validate()
 
 
-def test_raw_value():
-    schema = Dict.of(Integer.named('x').using(optional=False))
-    el = schema()
-    assert el.raw is None
-
-    el = schema('foo')
-    assert el.raw == 'foo'
-
-    el = schema({'x': 'bar'})
-    assert el.raw == {'x': 'bar'}
-
-    el = schema([('x', 'bar')])
-    assert el.raw == [('x', 'bar')]
-
-    schema = List.of(Integer)
-    el = schema()
-    assert el.raw is None
-
-    el = schema('foo')
-    assert el.raw == 'foo'
-
-    el = schema([1, 2, 3])
-    assert el.raw == [1, 2, 3]
-
-    el = schema((1, 2, 3))
-    assert el.raw == (1, 2, 3)
-
-    el = schema({'x': 'bar'})
-    assert el.raw == {'x': 'bar'}
-
-
 class TestContainerValidation(object):
 
     def setup(self):

tests/schema/test_dicts.py

     Integer,
     String,
     SparseDict,
+    Unset,
     )
 from flatland.util import Unspecified, keyslice_pairs
 from tests._util import (
     assert_raises(KeyError, el.set, {u'x': 123, u'y': 456, u'z': 7})
 
 
+def test_dict_raw():
+    schema = Dict.of(Integer.named('x').using(optional=False))
+    el = schema()
+    assert el.raw is Unset
+
+    el = schema({u'x': u'bar'})
+    assert el.raw == {u'x': u'bar'}
+
+    el = schema([(u'x', u'bar')])
+    assert el.raw == [(u'x', u'bar')]
+    el.set_flat([(u'x', u'123')])
+    assert el.raw is Unset
+
+    el = schema.from_flat([(u'x', u'123')])
+    assert el.raw is Unset
+    assert el[u'x'].raw == u'123'
+
+
 def test_dict_as_unicode():
     schema = Dict.of(Integer.named(u'x'), Integer.named(u'y'))
     el = schema({u'x': 1, u'y': 2})

tests/schema/test_lists.py

     Integer,
     List,
     String,
+    Unset,
 )
 from flatland.schema.base import Unspecified
 
     assert el.value == []
 
 
+def test_raw():
+    schema = List.of(Integer)
+    el = schema()
+    assert el.raw is Unset
+
+    el = schema(u'foo')
+    assert el.raw == u'foo'
+
+    el = schema([1, 2, 3])
+    assert el.raw == [1, 2, 3]
+
+    el = schema((1, 2, 3))
+    assert el.raw == (1, 2, 3)
+
+    el = schema({u'x': u'bar'})
+    assert el.raw == {u'x': u'bar'}
+
+
 def test_access():
     pairs = ((u'l_0_i', u'10'), (u'l_1_i', u'11'), (u'l_2_i', u'12'),)
 

tests/schema/test_scalars.py

     Scalar,
     String,
     Time,
+    Unset,
     )
 
 from tests._util import eq_, assert_raises, requires_unicode_coercion
     eq_(element_for(u'b').value, u'2')
     eq_(element_for(u'b').raw, u'2')
     eq_(element_for(u'c').value, None)
-    eq_(element_for(u'c').raw, None)
+    eq_(element_for(u'c').raw, Unset)
 
 
 @requires_unicode_coercion
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.