<s> import unittest <EOL> world = object ( ) <EOL> class TestEntity ( object ) : <EOL> world = world <EOL> class GeneralTestCase ( unittest . TestCase ) : <EOL> def test_fields ( self ) : <EOL> from grease . component import Component <EOL> c = Component ( ) <EOL> self . assertEqual ( len ( c . fields ) , <NUM_LIT:0> ) <EOL> c = Component ( f1 = int , f2 = float , f3 = str ) <EOL> self . assertEqual ( len ( c . fields ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( c . fields [ '<STR_LIT>' ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( c . fields [ '<STR_LIT>' ] . type , int ) <EOL> self . assertTrue ( c . fields [ '<STR_LIT>' ] . component is c ) <EOL> self . assertEqual ( c . fields [ '<STR_LIT>' ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( c . fields [ '<STR_LIT>' ] . type , float ) <EOL> self . assertTrue ( c . fields [ '<STR_LIT>' ] . component is c ) <EOL> self . assertEqual ( c . fields [ '<STR_LIT>' ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( c . fields [ '<STR_LIT>' ] . type , str ) <EOL> self . assertTrue ( c . fields [ '<STR_LIT>' ] . component is c ) <EOL> def test_invalid_field_type ( self ) : <EOL> from grease . component import Component <EOL> self . assertRaises ( AssertionError , Component , t = tuple ) <EOL> def test_add_no_data ( self ) : <EOL> from grease . component import Component <EOL> c = Component ( ) <EOL> c . set_world ( world ) <EOL> entity = TestEntity ( ) <EOL> self . assertFalse ( entity in c ) <EOL> ed = c . set ( entity ) <EOL> self . assertTrue ( entity in c ) <EOL> self . assertEqual ( list ( c ) , [ entity ] ) <EOL> def test_add_kw_data ( self ) : <EOL> from grease . component import Component <EOL> c = Component ( x = float , y = float , name = str ) <EOL> c . set_world ( world ) <EOL> entity = TestEntity ( ) <EOL> self . assertFalse ( entity in c ) <EOL> ed = c . set ( entity , x = <NUM_LIT:10> , y = - <NUM_LIT:1> , name = "<STR_LIT>" ) <EOL> self . assertTrue ( entity in c ) <EOL> self . assertEqual ( ed . x , <NUM_LIT:10> ) <EOL> self . assertEqual ( ed . y , - <NUM_LIT:1> ) <EOL> self . assertEqual ( ed . name , "<STR_LIT>" ) <EOL> def test_add_data_object ( self ) : <EOL> from grease . component import Component <EOL> c = Component ( sweat = int , odor = str ) <EOL> c . set_world ( world ) <EOL> class Data : pass <EOL> d = Data ( ) <EOL> d . sweat = <NUM_LIT:100> <EOL> d . odor = "<STR_LIT>" <EOL> entity = TestEntity ( ) <EOL> ed = c . set ( entity , d ) <EOL> self . assertTrue ( entity in c ) <EOL> self . assertEqual ( ed . sweat , <NUM_LIT:100> ) <EOL> self . assertEqual ( ed . odor , "<STR_LIT>" ) <EOL> def test_add_with_data_object_and_kw ( self ) : <EOL> from grease . component import Component <EOL> c = Component ( state = str , time = float ) <EOL> c . set_world ( world ) <EOL> class Data : pass <EOL> d = Data ( ) <EOL> d . state = "<STR_LIT>" <EOL> d . time = <NUM_LIT> <EOL> entity = TestEntity ( ) <EOL> ed = c . set ( entity , d , state = "<STR_LIT>" ) <EOL> self . assertTrue ( entity in c ) <EOL> self . assertEqual ( ed . state , "<STR_LIT>" ) <EOL> self . assertEqual ( ed . time , <NUM_LIT> ) <EOL> def test_data_defaults ( self ) : <EOL> from grease . component import Component <EOL> from grease . geometry import Vec2d <EOL> c = Component ( speed = int , accel = Vec2d , state = str ) <EOL> c . set_world ( world ) <EOL> e1 = TestEntity ( ) <EOL> e2 = TestEntity ( ) <EOL> ed = c . set ( e1 , accel = ( <NUM_LIT:10> , <NUM_LIT:5> ) ) <EOL> self . assertEqual ( ed . speed , <NUM_LIT:0> ) <EOL> self . assertEqual ( ed . accel , ( <NUM_LIT:10> , <NUM_LIT:5> ) ) <EOL> self . assertEqual ( ed . state , "<STR_LIT>" ) <EOL> ed = c . set ( e2 , state = "<STR_LIT>" ) <EOL> self . assertEqual ( ed . speed , <NUM_LIT:0> ) <EOL> self . assertEqual ( ed . accel , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertEqual ( ed . state , "<STR_LIT>" ) <EOL> def test_step_updates_new_and_deleted_lists ( self ) : <EOL> from grease . component import Component <EOL> c = Component ( x = float , y = float ) <EOL> c . set_world ( world ) <EOL> self . assertEqual ( list ( c . new_entities ) , [ ] ) <EOL> self . assertEqual ( list ( c . deleted_entities ) , [ ] ) <EOL> e1 = TestEntity ( ) <EOL> e2 = TestEntity ( ) <EOL> c . set ( e1 ) <EOL> c . set ( e2 ) <EOL> self . assertEqual ( list ( c . new_entities ) , [ ] ) <EOL> self . assertEqual ( list ( c . deleted_entities ) , [ ] ) <EOL> c . step ( <NUM_LIT:0> ) <EOL> self . assertEqual ( list ( c . new_entities ) , [ e1 , e2 ] ) <EOL> self . assertEqual ( list ( c . deleted_entities ) , [ ] ) <EOL> c . step ( <NUM_LIT:0> ) <EOL> self . assertEqual ( list ( c . new_entities ) , [ ] ) <EOL> self . assertEqual ( list ( c . deleted_entities ) , [ ] ) <EOL> del c [ e1 ] <EOL> del c [ e2 ] <EOL> self . assertEqual ( list ( c . new_entities ) , [ ] ) <EOL> self . assertEqual ( list ( c . deleted_entities ) , [ ] ) <EOL> c . step ( <NUM_LIT:0> ) <EOL> self . assertEqual ( list ( c . new_entities ) , [ ] ) <EOL> self . assertEqual ( list ( c . deleted_entities ) , [ e1 , e2 ] ) <EOL> def test_getitem ( self ) : <EOL> from grease . component import Component <EOL> c = Component ( ) <EOL> c . set_world ( world ) <EOL> entity = TestEntity ( ) <EOL> self . assertRaises ( KeyError , lambda : c [ entity ] ) <EOL> ed = c . set ( entity ) <EOL> self . assertTrue ( c [ entity ] is ed ) <EOL> def test_remove_and_contains ( self ) : <EOL> from grease . component import Component <EOL> c = Component ( ) <EOL> c . set_world ( world ) <EOL> e1 = TestEntity ( ) <EOL> e2 = TestEntity ( ) <EOL> self . assertFalse ( c . remove ( e1 ) ) <EOL> c . set ( e1 ) <EOL> c . set ( e2 ) <EOL> self . assertTrue ( c . remove ( e1 ) ) <EOL> self . assertTrue ( e1 in c ) <EOL> c . step ( <NUM_LIT:0> ) <EOL> self . assertFalse ( e1 in c ) <EOL> self . assertTrue ( e2 in c ) <EOL> self . assertFalse ( c . remove ( e1 ) ) <EOL> c . step ( <NUM_LIT:0> ) <EOL> self . assertTrue ( c . remove ( e2 ) ) <EOL> self . assertTrue ( e2 in c ) <EOL> c . step ( <NUM_LIT:0> ) <EOL> self . assertFalse ( e2 in c ) <EOL> self . assertFalse ( e2 in c ) <EOL> def test_len ( self ) : <EOL> from grease . component import Component <EOL> c = Component ( ) <EOL> c . set_world ( world ) <EOL> self . assertEqual ( len ( c ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( c . entities ) , <NUM_LIT:0> ) <EOL> entities = [ TestEntity ( ) for _ in range ( <NUM_LIT:50> ) ] <EOL> [ c . set ( e ) for e in entities ] <EOL> self . assertEqual ( len ( c ) , <NUM_LIT:50> ) <EOL> self . assertEqual ( len ( c . entities ) , <NUM_LIT:50> ) <EOL> [ c . remove ( e ) for e in entities [ : <NUM_LIT> ] ] <EOL> self . assertEqual ( len ( c . entities ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( c ) , <NUM_LIT:50> ) <EOL> c . step ( <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( c ) , <NUM_LIT> ) <EOL> self . assertEqual ( len ( c . entities ) , <NUM_LIT> ) <EOL> def test_iter ( self ) : <EOL> from grease . component import Component <EOL> c = Component ( ) <EOL> c . set_world ( world ) <EOL> self . assertEqual ( list ( c ) , [ ] ) <EOL> ed = [ c . set ( TestEntity ( ) ) , c . set ( TestEntity ( ) ) , c . set ( TestEntity ( ) ) ] <EOL> self . assertEqual ( sorted ( c . values ( ) ) , sorted ( ed ) ) <EOL> def test_set_world ( self ) : <EOL> from grease . component import Component <EOL> c = Component ( ) <EOL> world = object ( ) <EOL> c . set_world ( world ) <EOL> self . assertTrue ( c . world is world ) <EOL> def test_entities_set ( self ) : <EOL> from grease . component import Component <EOL> c = Component ( ) <EOL> c . set_world ( world ) <EOL> self . assertEqual ( len ( c . entities ) , <NUM_LIT:0> ) <EOL> entity1 = TestEntity ( ) <EOL> entity2 = TestEntity ( ) <EOL> entity3 = TestEntity ( ) <EOL> c . set ( entity1 ) <EOL> c . set ( entity2 ) <EOL> c . set ( entity3 ) <EOL> self . assertEqual ( len ( c . entities ) , <NUM_LIT:3> ) <EOL> self . assertTrue ( entity1 in c . entities ) <EOL> self . assertTrue ( entity2 in c . entities ) <EOL> self . assertTrue ( entity3 in c . entities ) <EOL> c . remove ( entity2 ) <EOL> self . assertEqual ( len ( c . entities ) , <NUM_LIT:2> ) <EOL> self . assertTrue ( entity1 in c . entities ) <EOL> self . assertFalse ( entity2 in c . entities ) <EOL> self . assertTrue ( entity3 in c . entities ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
