<s> """<STR_LIT>""" <EOL> import itertools <EOL> from twisted . positioning import _sentence <EOL> from twisted . trial . unittest import TestCase <EOL> sentinelValueOne = "<STR_LIT>" <EOL> sentinelValueTwo = "<STR_LIT>" <EOL> class DummyProtocol ( object ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def getSentenceAttributes ( ) : <EOL> return [ "<STR_LIT:type>" , sentinelValueOne , sentinelValueTwo ] <EOL> class DummySentence ( _sentence . _BaseSentence ) : <EOL> """<STR_LIT>""" <EOL> ALLOWED_ATTRIBUTES = DummyProtocol . getSentenceAttributes ( ) <EOL> class MixinProtocol ( _sentence . _PositioningSentenceProducerMixin ) : <EOL> """<STR_LIT>""" <EOL> _SENTENCE_CONTENTS = { <EOL> None : [ <EOL> sentinelValueOne , <EOL> sentinelValueTwo , <EOL> None <EOL> ] , <EOL> } <EOL> class MixinSentence ( _sentence . _BaseSentence ) : <EOL> """<STR_LIT>""" <EOL> ALLOWED_ATTRIBUTES = MixinProtocol . getSentenceAttributes ( ) <EOL> class SentenceTestsMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def test_attributeAccess ( self ) : <EOL> """<STR_LIT>""" <EOL> thisSentinel = object ( ) <EOL> sentence = self . sentenceClass ( { sentinelValueOne : thisSentinel } ) <EOL> self . assertEqual ( getattr ( sentence , sentinelValueOne ) , thisSentinel ) <EOL> self . assertEqual ( getattr ( sentence , sentinelValueTwo ) , None ) <EOL> def test_raiseOnMissingAttributeAccess ( self ) : <EOL> """<STR_LIT>""" <EOL> sentence = self . sentenceClass ( { } ) <EOL> self . assertRaises ( AttributeError , getattr , sentence , "<STR_LIT>" ) <EOL> def test_raiseOnBadAttributeAccess ( self ) : <EOL> """<STR_LIT>""" <EOL> sentence = self . sentenceClass ( { "<STR_LIT>" : None } ) <EOL> self . assertRaises ( AttributeError , getattr , sentence , "<STR_LIT>" ) <EOL> sentenceType = "<STR_LIT>" <EOL> reprTemplate = "<STR_LIT>" <EOL> def _expectedRepr ( self , sentenceType = "<STR_LIT>" , dataRepr = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> clsName = self . sentenceClass . __name__ <EOL> return self . reprTemplate % ( clsName , sentenceType , dataRepr ) <EOL> def test_unknownTypeRepr ( self ) : <EOL> """<STR_LIT>""" <EOL> sentence = self . sentenceClass ( { } ) <EOL> expectedRepr = self . _expectedRepr ( ) <EOL> self . assertEqual ( repr ( sentence ) , expectedRepr ) <EOL> def test_knownTypeRepr ( self ) : <EOL> """<STR_LIT>""" <EOL> sentence = self . sentenceClass ( { "<STR_LIT:type>" : self . sentenceType } ) <EOL> expectedRepr = self . _expectedRepr ( self . sentenceType ) <EOL> self . assertEqual ( repr ( sentence ) , expectedRepr ) <EOL> class DummyTests ( TestCase , SentenceTestsMixin ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . protocol = DummyProtocol ( ) <EOL> self . sentenceClass = DummySentence <EOL> class MixinTests ( TestCase , SentenceTestsMixin ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . protocol = MixinProtocol ( ) <EOL> self . sentenceClass = MixinSentence <EOL> def test_noNoneInSentenceAttributes ( self ) : <EOL> """<STR_LIT>""" <EOL> sentenceAttributes = self . protocol . getSentenceAttributes ( ) <EOL> self . assertNotIn ( None , sentenceAttributes ) <EOL> sentenceContents = self . protocol . _SENTENCE_CONTENTS <EOL> sentenceSpecAttributes = itertools . chain ( * sentenceContents . values ( ) ) <EOL> self . assertIn ( None , sentenceSpecAttributes ) </s>
