<s> import cPickle as pickle <EOL> import pickletools <EOL> import unittest <EOL> from flask . ext . testing import TestCase <EOL> from tango . app import Tango <EOL> from tango . stash import Route <EOL> class RouteSerializationTestCase ( TestCase ) : <EOL> def create_app ( self ) : <EOL> return Tango . build_app ( '<STR_LIT>' , import_stash = True ) <EOL> def setUp ( self ) : <EOL> self . original_route = self . app . routes [ <NUM_LIT:0> ] <EOL> self . serialized = pickle . dumps ( self . app . routes ) <EOL> self . serialized_optimized = pickletools . optimize ( self . serialized ) <EOL> self . deserialized = pickle . loads ( self . serialized ) <EOL> self . deserialized_optimized = pickle . loads ( self . serialized_optimized ) <EOL> def tearDown ( self ) : <EOL> pass <EOL> def _test_deserialization_type ( self , deserialized ) : <EOL> self . assertEqual ( len ( deserialized ) , <NUM_LIT:1> ) <EOL> route = deserialized [ <NUM_LIT:0> ] <EOL> self . assertEqual ( type ( route ) , Route ) <EOL> def test_deserialization_type ( self ) : <EOL> self . _test_deserialization_type ( self . deserialized ) <EOL> def test_deserialization_type_optimized ( self ) : <EOL> self . _test_deserialization_type ( self . deserialized_optimized ) <EOL> def _test_route_attributes ( self , deserialized ) : <EOL> route = deserialized [ <NUM_LIT:0> ] <EOL> original_route = self . original_route <EOL> self . assertEqual ( route . site , original_route . site ) <EOL> self . assertEqual ( route . rule , original_route . rule ) <EOL> self . assertEqual ( route . exports , original_route . exports ) <EOL> self . assertEqual ( route . static , original_route . static ) <EOL> self . assertEqual ( route . writer_name , original_route . writer_name ) <EOL> self . assertEqual ( route . modules , original_route . modules ) <EOL> def test_route_attributes ( self ) : <EOL> self . _test_route_attributes ( self . deserialized ) <EOL> def test_route_attributes_optimized ( self ) : <EOL> self . _test_route_attributes ( self . deserialized_optimized ) <EOL> def compare_scalars_in_dict ( self , dict1 , dict2 ) : <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertEqual ( dict1 [ key ] , dict2 [ key ] ) <EOL> def _test_stash_scalar_types ( self , deserialized ) : <EOL> context = deserialized [ <NUM_LIT:0> ] . context <EOL> context_original = self . original_route . context <EOL> self . compare_scalars_in_dict ( context , context_original ) <EOL> def test_stash_scalar_types ( self ) : <EOL> self . _test_stash_scalar_types ( self . deserialized ) <EOL> def test_stash_scalar_types_optimized ( self ) : <EOL> self . _test_stash_scalar_types ( self . deserialized_optimized ) <EOL> def _test_stash_iterables ( self , deserialized ) : <EOL> context = deserialized [ <NUM_LIT:0> ] . context <EOL> context_original = self . original_route . context <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertEqual ( context [ key ] , context_original [ key ] ) <EOL> def test_stash_iterables ( self ) : <EOL> self . _test_stash_iterables ( self . deserialized ) <EOL> def test_stash_iterables_optimized ( self ) : <EOL> self . _test_stash_iterables ( self . deserialized_optimized ) <EOL> def _test_stash_nested_dict ( self , deserialized ) : <EOL> a_nested_dict = deserialized [ <NUM_LIT:0> ] . context [ '<STR_LIT>' ] <EOL> a_nested_dict_original = self . original_route . context [ '<STR_LIT>' ] <EOL> self . compare_scalars_in_dict ( a_nested_dict , a_nested_dict_original ) <EOL> more_levels = a_nested_dict [ '<STR_LIT>' ] <EOL> more_levels_original = a_nested_dict_original [ '<STR_LIT>' ] <EOL> another_level = more_levels [ '<STR_LIT>' ] <EOL> another_level_original = more_levels_original [ '<STR_LIT>' ] <EOL> self . assertEqual ( another_level , another_level_original ) <EOL> def test_stash_nested_dict ( self ) : <EOL> self . _test_stash_nested_dict ( self . deserialized ) <EOL> def test_stash_nested_dict_optimized ( self ) : <EOL> self . _test_stash_nested_dict ( self . deserialized_optimized ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
