<s> from . . import unittest <EOL> from synapse . util . caches . treecache import TreeCache <EOL> class TreeCacheTestCase ( unittest . TestCase ) : <EOL> def test_get_set_onelevel ( self ) : <EOL> cache = TreeCache ( ) <EOL> cache [ ( "<STR_LIT:a>" , ) ] = "<STR_LIT:A>" <EOL> cache [ ( "<STR_LIT:b>" , ) ] = "<STR_LIT:B>" <EOL> self . assertEquals ( cache . get ( ( "<STR_LIT:a>" , ) ) , "<STR_LIT:A>" ) <EOL> self . assertEquals ( cache . get ( ( "<STR_LIT:b>" , ) ) , "<STR_LIT:B>" ) <EOL> self . assertEquals ( len ( cache ) , <NUM_LIT:2> ) <EOL> def test_pop_onelevel ( self ) : <EOL> cache = TreeCache ( ) <EOL> cache [ ( "<STR_LIT:a>" , ) ] = "<STR_LIT:A>" <EOL> cache [ ( "<STR_LIT:b>" , ) ] = "<STR_LIT:B>" <EOL> self . assertEquals ( cache . pop ( ( "<STR_LIT:a>" , ) ) , "<STR_LIT:A>" ) <EOL> self . assertEquals ( cache . pop ( ( "<STR_LIT:a>" , ) ) , None ) <EOL> self . assertEquals ( cache . get ( ( "<STR_LIT:b>" , ) ) , "<STR_LIT:B>" ) <EOL> self . assertEquals ( len ( cache ) , <NUM_LIT:1> ) <EOL> def test_get_set_twolevel ( self ) : <EOL> cache = TreeCache ( ) <EOL> cache [ ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ] = "<STR_LIT>" <EOL> cache [ ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ] = "<STR_LIT>" <EOL> cache [ ( "<STR_LIT:b>" , "<STR_LIT:a>" ) ] = "<STR_LIT>" <EOL> self . assertEquals ( cache . get ( ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ) , "<STR_LIT>" ) <EOL> self . assertEquals ( cache . get ( ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ) , "<STR_LIT>" ) <EOL> self . assertEquals ( cache . get ( ( "<STR_LIT:b>" , "<STR_LIT:a>" ) ) , "<STR_LIT>" ) <EOL> self . assertEquals ( len ( cache ) , <NUM_LIT:3> ) <EOL> def test_pop_twolevel ( self ) : <EOL> cache = TreeCache ( ) <EOL> cache [ ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ] = "<STR_LIT>" <EOL> cache [ ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ] = "<STR_LIT>" <EOL> cache [ ( "<STR_LIT:b>" , "<STR_LIT:a>" ) ] = "<STR_LIT>" <EOL> self . assertEquals ( cache . pop ( ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ) , "<STR_LIT>" ) <EOL> self . assertEquals ( cache . get ( ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ) , None ) <EOL> self . assertEquals ( cache . get ( ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ) , "<STR_LIT>" ) <EOL> self . assertEquals ( cache . pop ( ( "<STR_LIT:b>" , "<STR_LIT:a>" ) ) , "<STR_LIT>" ) <EOL> self . assertEquals ( cache . pop ( ( "<STR_LIT:b>" , "<STR_LIT:a>" ) ) , None ) <EOL> self . assertEquals ( len ( cache ) , <NUM_LIT:1> ) <EOL> def test_pop_mixedlevel ( self ) : <EOL> cache = TreeCache ( ) <EOL> cache [ ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ] = "<STR_LIT>" <EOL> cache [ ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ] = "<STR_LIT>" <EOL> cache [ ( "<STR_LIT:b>" , "<STR_LIT:a>" ) ] = "<STR_LIT>" <EOL> self . assertEquals ( cache . get ( ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ) , "<STR_LIT>" ) <EOL> cache . pop ( ( "<STR_LIT:a>" , ) ) <EOL> self . assertEquals ( cache . get ( ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ) , None ) <EOL> self . assertEquals ( cache . get ( ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ) , None ) <EOL> self . assertEquals ( cache . get ( ( "<STR_LIT:b>" , "<STR_LIT:a>" ) ) , "<STR_LIT>" ) <EOL> self . assertEquals ( len ( cache ) , <NUM_LIT:1> ) <EOL> def test_clear ( self ) : <EOL> cache = TreeCache ( ) <EOL> cache [ ( "<STR_LIT:a>" , ) ] = "<STR_LIT:A>" <EOL> cache [ ( "<STR_LIT:b>" , ) ] = "<STR_LIT:B>" <EOL> cache . clear ( ) <EOL> self . assertEquals ( len ( cache ) , <NUM_LIT:0> ) <EOL> def test_contains ( self ) : <EOL> cache = TreeCache ( ) <EOL> cache [ ( "<STR_LIT:a>" , ) ] = "<STR_LIT:A>" <EOL> self . assertTrue ( ( "<STR_LIT:a>" , ) in cache ) <EOL> self . assertFalse ( ( "<STR_LIT:b>" , ) in cache ) </s>
