<s> import sys <EOL> import traceback <EOL> from unittest import TestCase <EOL> from muntjac . terminal . key_mapper import KeyMapper <EOL> class TestKeyMapper ( TestCase ) : <EOL> def testAdd ( self ) : <EOL> mapper = KeyMapper ( ) <EOL> o1 = object ( ) <EOL> o2 = object ( ) <EOL> o3 = object ( ) <EOL> key1 = mapper . key ( o1 ) <EOL> key2 = mapper . key ( o2 ) <EOL> key3 = mapper . key ( o3 ) <EOL> self . assertEquals ( mapper . get ( key1 ) , o1 ) <EOL> self . assertEquals ( mapper . get ( key2 ) , o2 ) <EOL> self . assertEquals ( mapper . get ( key3 ) , o3 ) <EOL> self . assertNotEquals ( key1 , key2 ) <EOL> self . assertNotEquals ( key1 , key3 ) <EOL> self . assertNotEquals ( key2 , key3 ) <EOL> self . assertSize ( mapper , <NUM_LIT:3> ) <EOL> self . assertEquals ( mapper . key ( o3 ) , key3 ) <EOL> self . assertSize ( mapper , <NUM_LIT:3> ) <EOL> mapper . remove ( o1 ) <EOL> newkey1 = mapper . key ( o1 ) <EOL> self . assertNotEqual ( key1 , newkey1 ) <EOL> def testRemoveAll ( self ) : <EOL> mapper = KeyMapper ( ) <EOL> o1 = object ( ) <EOL> o2 = object ( ) <EOL> o3 = object ( ) <EOL> mapper . key ( o1 ) <EOL> mapper . key ( o2 ) <EOL> mapper . key ( o3 ) <EOL> self . assertSize ( mapper , <NUM_LIT:3> ) <EOL> mapper . removeAll ( ) <EOL> self . assertSize ( mapper , <NUM_LIT:0> ) <EOL> def testRemove ( self ) : <EOL> mapper = KeyMapper ( ) <EOL> o1 = object ( ) <EOL> o2 = object ( ) <EOL> o3 = object ( ) <EOL> mapper . key ( o1 ) <EOL> mapper . key ( o2 ) <EOL> mapper . key ( o3 ) <EOL> self . assertSize ( mapper , <NUM_LIT:3> ) <EOL> mapper . remove ( o1 ) <EOL> self . assertSize ( mapper , <NUM_LIT:2> ) <EOL> mapper . key ( o1 ) <EOL> self . assertSize ( mapper , <NUM_LIT:3> ) <EOL> mapper . remove ( o1 ) <EOL> self . assertSize ( mapper , <NUM_LIT:2> ) <EOL> mapper . remove ( o2 ) <EOL> mapper . remove ( o3 ) <EOL> self . assertSize ( mapper , <NUM_LIT:0> ) <EOL> def assertSize ( self , mapper , i ) : <EOL> try : <EOL> h1 = getattr ( mapper , '<STR_LIT>' ) <EOL> h2 = getattr ( mapper , '<STR_LIT>' ) <EOL> self . assertEquals ( i , len ( h1 ) ) <EOL> self . assertEquals ( i , len ( h2 ) ) <EOL> except Exception : <EOL> traceback . print_exc ( file = sys . stdout ) <EOL> self . fail ( ) </s>
