<s> import pytest <EOL> try : <EOL> from bson . objectid import ObjectId <EOL> except ImportError : <EOL> ObjectId = None <EOL> else : <EOL> from schematics . contrib . mongo import ObjectIdType <EOL> from schematics . exceptions import ConversionError , ValidationError <EOL> FAKE_OID = ObjectId ( ) <EOL> pytestmark = pytest . mark . skipif ( ObjectId is None , <EOL> reason = '<STR_LIT>' ) <EOL> def test_to_native ( ) : <EOL> oid = ObjectIdType ( ) <EOL> assert oid . to_native ( FAKE_OID ) == FAKE_OID <EOL> assert oid . to_native ( str ( FAKE_OID ) ) == FAKE_OID <EOL> with pytest . raises ( ConversionError ) : <EOL> oid . to_native ( '<STR_LIT:foo>' ) <EOL> def test_to_primitive ( ) : <EOL> oid = ObjectIdType ( ) <EOL> assert oid . to_primitive ( FAKE_OID ) == str ( FAKE_OID ) <EOL> assert oid . to_primitive ( str ( FAKE_OID ) ) == str ( FAKE_OID ) <EOL> def test_validate_id ( ) : <EOL> oid = ObjectIdType ( ) <EOL> oid . validate ( FAKE_OID ) <EOL> oid . validate ( str ( FAKE_OID ) ) <EOL> with pytest . raises ( ConversionError ) : <EOL> oid . validate ( '<STR_LIT:foo>' ) </s>
