Changeset 276


Ignore:
Timestamp:
09/07/09 20:59:20 (10 years ago)
Author:
orlandov
Message:

Ticket #67: Refactor unit tests into runnable shape

  • Move tests to their own top level directory
  • Fix unit test failures
  • Add base/composed classes to test suite
  • Run like "nosetests ./run_python.py" OR "./run_python.py"
Location:
trunk/game
Files:
2 added
2 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/game/run_tests.py

    r262 r276  
    1010        sys.path.append(_jp(p)) 
    1111 
    12 from scripts.tests.classTests import WoodenCrateTest 
     12from tests.test_objects_base import * 
     13from tests.test_crate import * 
    1314 
    1415if __name__ == '__main__': 
  • trunk/game/scripts/objects/base.py

    r262 r276  
    255255    def __init__ (self, **kwargs): 
    256256        self.is_trappable = True 
    257          
    258 if __name__=="__main__": 
    259     """This will be turned into a test suite""" 
    260     class Wildcard (GameObject, Lockable, Container, Living, Scriptable,  
    261                     CharStats, Wearable, Usable, Weapon, Destructable, 
    262                     Trappable, Carryable, ): 
    263         def __init__ (self, ID, *args, **kwargs): 
    264             self.name = 'All-purpose carry-all' 
    265             self.text = 'What is this? I dont know'     
    266             GameObject.  __init__( self, ID, **kwargs ) 
    267             Lockable.    __init__( self, **kwargs ) 
    268             Container.   __init__( self, **kwargs ) 
    269             Living.      __init__( self, **kwargs ) 
    270             Scriptable.  __init__( self, **kwargs ) 
    271             CharStats.   __init__( self, **kwargs ) 
    272             Wearable.    __init__( self, **kwargs ) 
    273             Usable.      __init__( self, **kwargs ) 
    274             Weapon.      __init__( self, **kwargs ) 
    275             Destructable.__init__( self, **kwargs ) 
    276             Trappable.   __init__( self, **kwargs ) 
    277             Carryable.   __init__( self, **kwargs ) 
    278      
    279     test = GameObject (1, {'map':'img/test.png'}, (1,1), None, 'Test object','Description') 
    280     print test 
    281     assert test.X == 1 
    282     assert test.Y == 1 
    283     assert test.coords == (1,1) 
    284     test.coords = (2,2) 
    285     assert test.X == 2.0 
    286     assert test.Y == 2.0 
    287      
    288     wc = Wildcard (2) 
    289     print wc 
    290     print wc.is_carryable 
    291  
  • trunk/game/tests/test_crate.py

    r275 r276  
     1#!/usr/bin/python 
     2 
    13import unittest 
    24from scripts.objects.containers import WoodenCrate 
     
    1012        self.assertEqual(self.crate.ID, 'crate01') 
    1113        self.assertEqual(self.crate.name, 'Wooden Crate') 
    12         self.assertEqual(self.crate.text, 'A battered down crate') 
    13         self.assertEqual(self.crate.gfx, \ 
    14                 {'map': 'objects/objects/crate/image.png'}) 
     14        self.assertEqual(self.crate.text, 'A battered crate') 
     15        self.assertEqual(self.crate.gfx, 'crate') 
    1516        self.assertEqual(self.crate.coords, (0.0, 0.0)) 
    1617        self.assertEqual(self.crate.map_id, None) 
     
    2425 
    2526    # can't test containing functionality...there are no containable objects 
    26     
     27 
    2728    def test_lockable(self): 
    2829        self.crate2.lock() 
     
    3031        self.crate2.unlock() 
    3132        self.assertEqual(self.crate2.locked, False) 
    32  
    33 if __name__=='__main__': 
    34     unittest.main() 
Note: See TracChangeset for help on using the changeset viewer.