<s> from __future__ import absolute_import , division <EOL> from twisted . trial import unittest <EOL> from twisted . python import roots <EOL> class RootsTests ( unittest . TestCase ) : <EOL> def testExceptions ( self ) : <EOL> request = roots . Request ( ) <EOL> try : <EOL> request . write ( b"<STR_LIT>" ) <EOL> except NotImplementedError : <EOL> pass <EOL> else : <EOL> self . fail ( ) <EOL> try : <EOL> request . finish ( ) <EOL> except NotImplementedError : <EOL> pass <EOL> else : <EOL> self . fail ( ) <EOL> def testCollection ( self ) : <EOL> collection = roots . Collection ( ) <EOL> collection . putEntity ( "<STR_LIT:x>" , '<STR_LIT:test>' ) <EOL> self . assertEqual ( collection . getStaticEntity ( "<STR_LIT:x>" ) , <EOL> '<STR_LIT:test>' ) <EOL> collection . delEntity ( "<STR_LIT:x>" ) <EOL> self . assertEqual ( collection . getStaticEntity ( '<STR_LIT:x>' ) , <EOL> None ) <EOL> try : <EOL> collection . storeEntity ( "<STR_LIT:x>" , None ) <EOL> except NotImplementedError : <EOL> pass <EOL> else : <EOL> self . fail ( ) <EOL> try : <EOL> collection . removeEntity ( "<STR_LIT:x>" , None ) <EOL> except NotImplementedError : <EOL> pass <EOL> else : <EOL> self . fail ( ) <EOL> def testConstrained ( self ) : <EOL> class const ( roots . Constrained ) : <EOL> def nameConstraint ( self , name ) : <EOL> return ( name == '<STR_LIT:x>' ) <EOL> c = const ( ) <EOL> self . assertEqual ( c . putEntity ( '<STR_LIT:x>' , '<STR_LIT:test>' ) , None ) <EOL> self . failUnlessRaises ( roots . ConstraintViolation , <EOL> c . putEntity , '<STR_LIT:y>' , '<STR_LIT:test>' ) <EOL> def testHomogenous ( self ) : <EOL> h = roots . Homogenous ( ) <EOL> h . entityType = int <EOL> h . putEntity ( '<STR_LIT:a>' , <NUM_LIT:1> ) <EOL> self . assertEqual ( h . getStaticEntity ( '<STR_LIT:a>' ) , <NUM_LIT:1> ) <EOL> self . failUnlessRaises ( roots . ConstraintViolation , <EOL> h . putEntity , '<STR_LIT:x>' , '<STR_LIT:y>' ) </s>
