Changeset 369 for trunk/game


Ignore:
Timestamp:
11/04/09 20:03:05 (10 years ago)
Author:
eliedebrauwer
Message:

Ticket #147. Patch by eliedebrauwer: Added dialogue-validator code and unittests, already capable of structure checking. Unittest fail atm. Still pending for ticket 147 is a standalone validator. comment[s:trac, t:147]

Location:
trunk/game
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/tests/test_dialogue.py

    r317 r369  
    1616#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>. 
    1717 
     18import os 
    1819import sys 
    1920import unittest 
    2021from scripts.dialogue import DialogueEngine 
     22from scripts.dialoguevalidator import DialogueValidator 
    2123 
    2224class TestDialogue(unittest.TestCase): 
     
    5557        test_vars = { "say": None, "responses": [] } 
    5658 
    57         def say_cb(state, text): 
     59        def sayCb(state, text): 
    5860            state["say"] = text 
    5961 
    6062        self.replies = ["resp1", "back", "stop"] 
    6163 
    62         def npc_avatar_cb(state, image): 
     64        def npcAvatarCb(state, image): 
    6365            state['npc_avatar'] = image 
    6466 
    65         def responses_cb(state, responses): 
     67        def responsesCb(state, responses): 
    6668            state['responses'] = responses 
    6769 
    6870        callbacks = { 
    69             "say": say_cb, 
    70             "responses": responses_cb, 
    71             "npc_avatar": npc_avatar_cb 
     71            "say": sayCb, 
     72            "responses": responsesCb, 
     73            "npc_avatar": npcAvatarCb 
    7274        } 
    7375 
    7476        self.dialogue = DialogueEngine(self.tree, callbacks, test_vars) 
    7577 
    76     def assert_say(self, text): 
     78    def assertSay(self, text): 
    7779        self.assertEqual(text, self.dialogue.state['say']) 
    7880 
    79     def assert_responses(self, responses): 
     81    def assertResponses(self, responses): 
    8082        self.assertEqual(responses, self.dialogue.state['responses']) 
    8183 
    82     def assert_npc_image(self, image): 
     84    def assertNpcImage(self, image): 
    8385        self.assertEqual(image, self.dialogue.state['npc_avatar']) 
    8486 
    85     def test_simple(self): 
     87    def testSimple(self): 
    8688        """Test basic dialogue interaction""" 
    8789        self.dialogue.state['show'] = False 
    8890        self.dialogue.run() 
    8991 
    90         self.assert_npc_image('npc.png') 
    91         self.assert_say('Greetings stranger') 
    92         self.assert_responses([ 
     92        self.assertNpcImage('npc.png') 
     93        self.assertSay('Greetings stranger') 
     94        self.assertResponses([ 
    9395            ["Hi, can you tell me where I am?", "friendly"], 
    9496            ["Watch your words", "aggro"], 
     
    98100        self.dialogue.reply(0) 
    99101 
    100         self.assert_say('You sure are lost') 
    101         self.assert_responses([ 
     102        self.assertSay('You sure are lost') 
     103        self.assertResponses([ 
    102104            ["Thanks, I know", "thanks"], 
    103105            ["Wait what did you say before?", "back"] 
     
    106108        self.dialogue.reply(1) 
    107109 
    108         self.assert_say('Greetings stranger') 
    109         self.assert_responses([ 
     110        self.assertSay('Greetings stranger') 
     111        self.assertResponses([ 
    110112            ["Hi, can you tell me where I am?", "friendly"], 
    111113            ["Watch your words", "aggro"], 
     
    116118        self.dialogue.reply(0) 
    117119 
    118         self.assert_say('You sure are lost') 
     120        self.assertSay('You sure are lost') 
    119121        self.dialogue.reply(1) 
    120122 
    121         self.assert_say('Greetings stranger') 
     123        self.assertSay('Greetings stranger') 
    122124        self.dialogue.reply(0) 
    123125 
    124         self.assert_say('You sure are lost') 
     126        self.assertSay('You sure are lost') 
    125127        self.dialogue.reply(0) 
    126128 
    127         self.assert_say("We haven't seen one of your kind in ages") 
     129        self.assertSay("We haven't seen one of your kind in ages") 
    128130        self.dialogue.reply(1) 
    129131 
    130         self.assert_say('You sure are lost') 
     132        self.assertSay('You sure are lost') 
    131133        self.dialogue.reply(1) 
    132134 
    133         self.assert_say('Greetings stranger') 
     135        self.assertSay('Greetings stranger') 
    134136 
     137    def testAllDialogueFiles(self): 
     138        """ Runs the validator on all dialogue files available. """ 
     139         
     140        val = DialogueValidator() 
     141        diag_dir = os.path.join(os.path.curdir, "dialogue"); 
     142        for dialogue in os.listdir(diag_dir): 
     143            fname = os.path.join(diag_dir, dialogue) 
     144            if os.path.isfile(fname) : 
     145                val.validateDialogue(fname,".") 
     146   
    135147if __name__ == "__main__": 
    136148    unittest.main() 
Note: See TracChangeset for help on using the changeset viewer.