<s> from twisted . trial import unittest <EOL> from twisted . internet import task <EOL> from axiom import store <EOL> from imaginary import iimaginary , events , objects <EOL> from imaginary . test import commandutils <EOL> from examplegame import mice <EOL> class IntelligenceTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . store = store . Store ( ) <EOL> self . locationContainer = commandutils . createLocation ( <EOL> self . store , u"<STR_LIT>" , None ) <EOL> self . location = self . locationContainer . thing <EOL> self . alice = objects . Thing ( store = self . store , name = u"<STR_LIT>" ) <EOL> self . actor = objects . Actor . createFor ( self . alice ) <EOL> self . alice . moveTo ( self . location ) <EOL> self . intelligence = commandutils . MockIntelligence ( store = self . store ) <EOL> self . actor . setEnduringIntelligence ( self . intelligence ) <EOL> def test_intelligenceReceivesEvent ( self ) : <EOL> """<STR_LIT>""" <EOL> evt = events . Success ( <EOL> location = self . location , <EOL> otherMessage = u"<STR_LIT>" ) <EOL> self . actor . send ( evt ) <EOL> self . assertEquals ( self . intelligence . concepts , [ evt ] ) <EOL> def test_persistentIntelligence ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertIdentical ( <EOL> self . store . findUnique ( <EOL> objects . Actor , <EOL> objects . Actor . _enduringIntelligence == self . intelligence ) , <EOL> self . actor ) <EOL> class MouseTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . store = store . Store ( ) <EOL> self . clock = objects . Thing ( store = self . store , name = u"<STR_LIT>" ) <EOL> self . clockContainer = objects . Container . createFor ( self . clock , capacity = <NUM_LIT:10> ) <EOL> self . mouse = mice . createMouse ( store = self . store , name = u"<STR_LIT>" ) <EOL> self . mouseActor = iimaginary . IActor ( self . mouse ) <EOL> self . mousehood = self . mouseActor . getIntelligence ( ) <EOL> self . mouse . moveTo ( self . clock ) <EOL> self . player = objects . Thing ( store = self . store , name = u"<STR_LIT>" ) <EOL> self . playerActor = objects . Actor . createFor ( self . player ) <EOL> self . playerIntelligence = commandutils . MockIntelligence ( <EOL> store = self . store ) <EOL> self . playerActor . setEnduringIntelligence ( self . playerIntelligence ) <EOL> self . player . moveTo ( self . clock ) <EOL> def test_mouseSqueaksAtIntruders ( self ) : <EOL> """<STR_LIT>""" <EOL> clock = task . Clock ( ) <EOL> self . mousehood . _callLater = clock . callLater <EOL> evt = events . ArrivalEvent ( actor = self . player ) <EOL> self . mouseActor . send ( evt ) <EOL> self . assertEquals ( len ( self . playerIntelligence . concepts ) , <NUM_LIT:0> ) <EOL> clock . advance ( <NUM_LIT:0> ) <EOL> self . assertEquals ( len ( self . playerIntelligence . concepts ) , <NUM_LIT:1> ) <EOL> event = self . playerIntelligence . concepts [ <NUM_LIT:0> ] <EOL> self . assertEquals ( <EOL> commandutils . flatten ( event . otherMessage . plaintext ( self . player ) ) , <EOL> u"<STR_LIT>" ) <EOL> def test_mouseCanSqueak ( self ) : <EOL> events . runEventTransaction ( self . store , self . mousehood . squeak ) <EOL> self . assertEquals ( len ( self . playerIntelligence . concepts ) , <NUM_LIT:1> ) <EOL> event = self . playerIntelligence . concepts [ <NUM_LIT:0> ] <EOL> self . assertEquals ( <EOL> commandutils . flatten ( event . otherMessage . plaintext ( self . player ) ) , <EOL> u"<STR_LIT>" ) <EOL> def test_mouseActivation ( self ) : <EOL> """<STR_LIT>""" <EOL> from twisted . internet import reactor <EOL> self . assertEquals ( self . mousehood . _callLater , reactor . callLater ) <EOL> class MouseReactionTestCase ( commandutils . CommandTestCaseMixin , <EOL> unittest . TestCase ) : <EOL> def testCreation ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _test ( <EOL> "<STR_LIT>" , <EOL> [ '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' ] ) <EOL> [ mouse ] = list ( self . playerContainer . getContents ( ) ) <EOL> self . failUnless ( isinstance ( iimaginary . IActor ( mouse ) . getIntelligence ( ) , mice . Mouse ) ) <EOL> def testSqueak ( self ) : <EOL> """<STR_LIT>""" <EOL> mouse = mice . createMouse ( store = self . store , name = u"<STR_LIT>" ) <EOL> clock = task . Clock ( ) <EOL> intelligence = iimaginary . IActor ( mouse ) . getIntelligence ( ) <EOL> intelligence . _callLater = clock . callLater <EOL> elsewhere = commandutils . createLocation ( <EOL> self . store , u"<STR_LIT>" , None ) . thing <EOL> objects . Exit . link ( self . location , elsewhere , u"<STR_LIT>" ) <EOL> mouse . moveTo ( elsewhere ) <EOL> self . _test ( <EOL> "<STR_LIT>" , <EOL> [ commandutils . E ( "<STR_LIT>" ) , <EOL> commandutils . E ( "<STR_LIT>" ) , <EOL> commandutils . E ( "<STR_LIT>" ) ] , <EOL> [ '<STR_LIT>' ] ) <EOL> clock . advance ( <NUM_LIT:0> ) <EOL> self . _test ( None , [ "<STR_LIT>" ] ) </s>
