<s> import ddt <EOL> from falcon . routing import DefaultRouter <EOL> import falcon . testing as testing <EOL> class ResourceWithId ( object ) : <EOL> def __init__ ( self , resource_id ) : <EOL> self . resource_id = resource_id <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . resource_id ) <EOL> def on_get ( self , req , resp ) : <EOL> resp . body = self . resource_id <EOL> class TestRegressionCases ( testing . TestBase ) : <EOL> """<STR_LIT>""" <EOL> def before ( self ) : <EOL> self . router = DefaultRouter ( ) <EOL> def test_versioned_url ( self ) : <EOL> self . router . add_route ( '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:2> ) ) <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT:2> ) <EOL> self . router . add_route ( '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:1> ) ) <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT:1> ) <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT:2> ) <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT:2> ) <EOL> route = self . router . find ( '<STR_LIT>' ) <EOL> self . assertIs ( route , None ) <EOL> def test_recipes ( self ) : <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:1> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:2> ) ) <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT:1> ) <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT:2> ) <EOL> route = self . router . find ( '<STR_LIT>' ) <EOL> self . assertIs ( route , None ) <EOL> @ ddt . ddt <EOL> class TestComplexRouting ( testing . TestBase ) : <EOL> def before ( self ) : <EOL> self . router = DefaultRouter ( ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:1> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:2> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:3> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:4> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , <EOL> { } , ResourceWithId ( <NUM_LIT:5> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:6> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:7> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:8> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:9> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , <EOL> { } , ResourceWithId ( <NUM_LIT:10> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:11> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:12> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , <EOL> { } , ResourceWithId ( <NUM_LIT:15> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , <EOL> { } , ResourceWithId ( <NUM_LIT:16> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , <EOL> { } , ResourceWithId ( <NUM_LIT> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT> ) ) <EOL> self . router . add_route ( <EOL> '<STR_LIT>' , { } , ResourceWithId ( <NUM_LIT:20> ) ) <EOL> @ ddt . data ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def test_collision ( self , template ) : <EOL> self . assertRaises ( <EOL> ValueError , <EOL> self . router . add_route , template , { } , ResourceWithId ( - <NUM_LIT:1> ) <EOL> ) <EOL> @ ddt . data ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def test_non_collision ( self , template ) : <EOL> self . router . add_route ( template , { } , ResourceWithId ( - <NUM_LIT:1> ) ) <EOL> def test_dump ( self ) : <EOL> print ( self . router . _src ) <EOL> def test_override ( self ) : <EOL> self . router . add_route ( '<STR_LIT>' , { } , ResourceWithId ( - <NUM_LIT:1> ) ) <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , - <NUM_LIT:1> ) <EOL> def test_literal_segment ( self ) : <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT:12> ) <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT> ) <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT> ) <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT> ) <EOL> route = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( route , None ) <EOL> @ ddt . data ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def test_dead_segment ( self , template ) : <EOL> route = self . router . find ( template ) <EOL> self . assertIs ( route , None ) <EOL> def test_malformed_pattern ( self ) : <EOL> route = self . router . find ( <EOL> '<STR_LIT>' ) <EOL> self . assertIs ( route , None ) <EOL> route = self . router . find ( <EOL> '<STR_LIT>' ) <EOL> self . assertIs ( route , None ) <EOL> def test_literal ( self ) : <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT:8> ) <EOL> def test_variable ( self ) : <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT:6> ) <EOL> self . assertEqual ( params , { '<STR_LIT:id>' : '<STR_LIT>' } ) <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( params , { '<STR_LIT:id>' : '<STR_LIT>' } ) <EOL> resource , method_map , params = self . router . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( params , { '<STR_LIT:id>' : '<STR_LIT>' } ) <EOL> @ ddt . data ( <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:7> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:6> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:7> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:20> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ) <EOL> @ ddt . unpack <EOL> def test_literal_vs_variable ( self , path , expected_id ) : <EOL> resource , method_map , params = self . router . find ( path ) <EOL> self . assertEqual ( resource . resource_id , expected_id ) <EOL> @ ddt . data ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def test_not_found ( self , path ) : <EOL> route = self . router . find ( path ) <EOL> self . assertIs ( route , None ) <EOL> def test_subsegment_not_found ( self ) : <EOL> route = self . router . find ( '<STR_LIT>' ) <EOL> self . assertIs ( route , None ) <EOL> def test_multivar ( self ) : <EOL> resource , method_map , params = self . router . find ( <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT:4> ) <EOL> self . assertEqual ( params , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> resource , method_map , params = self . router . find ( <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( resource . resource_id , <NUM_LIT:11> ) <EOL> self . assertEqual ( params , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> @ ddt . data ( ( '<STR_LIT>' , <NUM_LIT:5> ) , ( '<STR_LIT>' , <NUM_LIT:10> ) , ( '<STR_LIT>' , <NUM_LIT:15> ) ) <EOL> @ ddt . unpack <EOL> def test_complex ( self , url_postfix , resource_id ) : <EOL> uri = '<STR_LIT>' <EOL> resource , method_map , params = self . router . find ( uri + url_postfix ) <EOL> self . assertEqual ( resource . resource_id , resource_id ) <EOL> self . assertEqual ( params , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> @ ddt . data ( ( '<STR_LIT>' , <NUM_LIT:16> ) , ( '<STR_LIT>' , <NUM_LIT> ) ) <EOL> @ ddt . unpack <EOL> def test_complex_alt ( self , url_postfix , resource_id ) : <EOL> uri = '<STR_LIT>' <EOL> resource , method_map , params = self . router . find ( uri + url_postfix ) <EOL> self . assertEqual ( resource . resource_id , resource_id ) <EOL> self . assertEqual ( params , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) </s>
