<s> import mock <EOL> import colander <EOL> import pyramid . testing <EOL> from daybed . schemas import ( TypeRegistry , NotRegisteredError , <EOL> TypeField , TypeFieldNode , registry , <EOL> AlreadyRegisteredError , UnknownFieldTypeError ) <EOL> from daybed . tests . support import unittest <EOL> class TypeRegistryTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . config = pyramid . testing . setUp ( ) <EOL> self . types = TypeRegistry ( ) <EOL> def tearDown ( self ) : <EOL> pyramid . testing . tearDown ( ) <EOL> def test_register ( self ) : <EOL> self . assertEqual ( [ ] , list ( self . types . names ) ) <EOL> self . types . register ( '<STR_LIT:foo>' , None ) <EOL> self . assertEqual ( [ '<STR_LIT:foo>' ] , list ( self . types . names ) ) <EOL> def test_unregister_unknown ( self ) : <EOL> self . assertRaises ( NotRegisteredError , <EOL> self . types . unregister , '<STR_LIT:foo>' ) <EOL> def test_unregister ( self ) : <EOL> self . types . register ( '<STR_LIT:bar>' , None ) <EOL> self . assertEqual ( [ '<STR_LIT:bar>' ] , list ( self . types . names ) ) <EOL> self . types . unregister ( '<STR_LIT:bar>' ) <EOL> self . assertEqual ( [ ] , list ( self . types . names ) ) <EOL> self . assertRaises ( UnknownFieldTypeError , <EOL> self . types . definition , '<STR_LIT:bar>' ) <EOL> self . assertRaises ( UnknownFieldTypeError , <EOL> self . types . validation , '<STR_LIT:bar>' ) <EOL> def test_register_again ( self ) : <EOL> self . types . register ( '<STR_LIT:foo>' , None ) <EOL> self . assertRaises ( AlreadyRegisteredError , <EOL> self . types . register , '<STR_LIT:foo>' , None ) <EOL> class TypeFieldNodeTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> class FooField ( TypeField ) : <EOL> @ classmethod <EOL> def definition ( self , ** kwargs ) : <EOL> mocked = mock . Mock ( ) <EOL> mocked . deserialize . return_value = '<STR_LIT>' <EOL> return mocked <EOL> registry . register ( '<STR_LIT:foo>' , FooField ) <EOL> def tearDown ( self ) : <EOL> registry . unregister ( '<STR_LIT:foo>' ) <EOL> def test_node_returns_definition ( self ) : <EOL> fieldnode = TypeFieldNode ( ) <EOL> self . assertEqual ( '<STR_LIT>' , fieldnode . deserialize ( None , { '<STR_LIT:type>' : '<STR_LIT:foo>' } ) ) <EOL> def test_unknown_type_is_invalid ( self ) : <EOL> fieldnode = TypeFieldNode ( ) <EOL> self . assertRaises ( colander . Invalid , <EOL> fieldnode . deserialize , None , { '<STR_LIT:type>' : '<STR_LIT>' } ) </s>
