test.py (14066B)
1 relationxml = ''' 2 <osm> 3 <relation id="21855" version="7" timestamp="2012-03-21T21:37:54Z" uid="14020" user="Nick Austin" changeset="11057350"> 4 <member type="way" ref="156255508" role=""/> 5 <member type="way" ref="156255507" role=""/> 6 <tag k="name" v="Hatfield Tunnel"/> 7 <tag k="type" v="tunnel"/> 8 </relation> 9 <relation id="31640" version="81" timestamp="2012-05-19T09:17:44Z" uid="24119" user="Mauls" changeset="11640673"> 10 <member type="way" ref="24541150" role=""/> 11 <member type="way" ref="25896432" role="forward"/> 12 <member type="way" ref="25896435" role="forward"/> 13 <member type="way" ref="136990875" role="forward"/> 14 <member type="way" ref="25896366" role="forward"/> 15 <member type="way" ref="25896438" role="forward"/> 16 <member type="way" ref="136990877" role="forward"/> 17 <member type="way" ref="22329168" role="forward"/> 18 <member type="way" ref="136990870" role=""/> 19 <member type="way" ref="136990880" role=""/> 20 <member type="way" ref="136990882" role=""/> 21 <member type="way" ref="3220127" role=""/> 22 <member type="way" ref="136990873" role=""/> 23 <member type="way" ref="136990872" role=""/> 24 <member type="way" ref="121267851" role=""/> 25 <member type="way" ref="121267847" role=""/> 26 <member type="way" ref="4515378" role=""/> 27 <member type="way" ref="8145197" role=""/> 28 <member type="way" ref="19745207" role=""/> 29 <member type="way" ref="19745206" role=""/> 30 <member type="way" ref="4518667" role=""/> 31 <member type="way" ref="113946003" role=""/> 32 <member type="way" ref="136990884" role=""/> 33 <member type="way" ref="8126872" role=""/> 34 <member type="way" ref="1019866" role=""/> 35 <member type="way" ref="1935841" role=""/> 36 <member type="way" ref="1935842" role=""/> 37 <member type="way" ref="2837807" role=""/> 38 <member type="way" ref="3617718" role=""/> 39 <member type="way" ref="3617750" role=""/> 40 <member type="way" ref="157868716" role=""/> 41 <member type="way" ref="157868712" role=""/> 42 <member type="way" ref="4232426" role=""/> 43 <member type="way" ref="4232450" role=""/> 44 <member type="way" ref="4232523" role=""/> 45 <member type="way" ref="4234302" role=""/> 46 <member type="way" ref="4234304" role=""/> 47 <member type="way" ref="140969196" role=""/> 48 <member type="way" ref="4274177" role=""/> 49 <member type="way" ref="4288798" role=""/> 50 <member type="way" ref="4288804" role=""/> 51 <member type="way" ref="4288817" role=""/> 52 <member type="way" ref="115708422" role=""/> 53 <member type="way" ref="4290564" role=""/> 54 <member type="way" ref="4290566" role=""/> 55 <member type="way" ref="146405866" role=""/> 56 <member type="way" ref="4290567" role=""/> 57 <member type="way" ref="4290569" role=""/> 58 <member type="way" ref="104494931" role=""/> 59 <member type="way" ref="37726893" role=""/> 60 <member type="way" ref="4300013" role=""/> 61 <member type="way" ref="4327072" role=""/> 62 <member type="way" ref="4385337" role=""/> 63 <member type="way" ref="4515181" role=""/> 64 <member type="way" ref="4719529" role=""/> 65 <member type="way" ref="4719530" role=""/> 66 <member type="way" ref="5924137" role="forward"/> 67 <member type="way" ref="136990881" role=""/> 68 <member type="way" ref="135775543" role=""/> 69 <member type="way" ref="135775531" role=""/> 70 <member type="way" ref="6006524" role=""/> 71 <member type="way" ref="9227120" role=""/> 72 <member type="way" ref="9228211" role=""/> 73 <member type="way" ref="9228215" role=""/> 74 <member type="way" ref="9228221" role=""/> 75 <member type="way" ref="9228224" role=""/> 76 <member type="way" ref="9265930" role=""/> 77 <member type="way" ref="9362548" role=""/> 78 <member type="way" ref="10943268" role=""/> 79 <member type="way" ref="10943269" role=""/> 80 <member type="way" ref="10944242" role=""/> 81 <member type="way" ref="10989591" role=""/> 82 <member type="way" ref="10991833" role=""/> 83 <member type="way" ref="10996488" role=""/> 84 <member type="way" ref="11070521" role=""/> 85 <member type="way" ref="11071125" role=""/> 86 <member type="way" ref="71403686" role=""/> 87 <member type="way" ref="11071127" role=""/> 88 <member type="way" ref="11071128" role=""/> 89 <member type="way" ref="11071130" role=""/> 90 <member type="way" ref="11071828" role=""/> 91 <member type="way" ref="11071937" role=""/> 92 <member type="way" ref="11071938" role=""/> 93 <member type="way" ref="11071941" role=""/> 94 <member type="way" ref="11072077" role=""/> 95 <member type="way" ref="11072080" role=""/> 96 <member type="way" ref="15091285" role=""/> 97 <member type="way" ref="15091286" role=""/> 98 <member type="way" ref="15091321" role=""/> 99 <member type="way" ref="15091324" role=""/> 100 <member type="way" ref="15091328" role=""/> 101 <member type="way" ref="15091364" role=""/> 102 <member type="way" ref="15091378" role=""/> 103 <member type="way" ref="73271466" role=""/> 104 <member type="way" ref="73271488" role=""/> 105 <member type="way" ref="58718382" role=""/> 106 <member type="way" ref="15091546" role=""/> 107 <member type="way" ref="15091557" role=""/> 108 <member type="way" ref="15091559" role=""/> 109 <member type="way" ref="15091596" role=""/> 110 <member type="way" ref="15091603" role=""/> 111 <member type="way" ref="15091606" role=""/> 112 <member type="way" ref="48827325" role=""/> 113 <member type="way" ref="15091609" role=""/> 114 <member type="way" ref="164157963" role=""/> 115 <member type="way" ref="15091656" role=""/> 116 <member type="way" ref="43026009" role=""/> 117 <member type="way" ref="43026010" role=""/> 118 <member type="way" ref="15091678" role=""/> 119 <member type="way" ref="19826860" role=""/> 120 <member type="way" ref="19826861" role=""/> 121 <member type="way" ref="164157965" role=""/> 122 <member type="way" ref="19973630" role=""/> 123 <member type="way" ref="22277500" role=""/> 124 <member type="way" ref="22277501" role=""/> 125 <member type="way" ref="22277790" role=""/> 126 <member type="way" ref="22277845" role=""/> 127 <member type="way" ref="22277849" role=""/> 128 <member type="way" ref="22278089" role=""/> 129 <member type="way" ref="22278090" role=""/> 130 <member type="way" ref="22278109" role=""/> 131 <member type="way" ref="22278111" role=""/> 132 <member type="way" ref="22278116" role=""/> 133 <member type="way" ref="22278120" role=""/> 134 <member type="way" ref="22278128" role=""/> 135 <member type="way" ref="22278626" role=""/> 136 <member type="way" ref="22328765" role=""/> 137 <member type="way" ref="22328772" role=""/> 138 <member type="way" ref="22328778" role=""/> 139 <member type="way" ref="22328779" role=""/> 140 <member type="way" ref="22330396" role=""/> 141 <member type="way" ref="22679421" role=""/> 142 <member type="way" ref="23040738" role=""/> 143 <member type="way" ref="23040842" role=""/> 144 <member type="way" ref="23040846" role=""/> 145 <member type="way" ref="23040858" role=""/> 146 <member type="way" ref="23117246" role=""/> 147 <member type="way" ref="23294746" role=""/> 148 <member type="way" ref="23506818" role=""/> 149 <member type="way" ref="23506829" role=""/> 150 <member type="way" ref="23517268" role=""/> 151 <member type="way" ref="23517271" role=""/> 152 <member type="way" ref="157868707" role=""/> 153 <member type="way" ref="23598320" role=""/> 154 <member type="way" ref="23598322" role=""/> 155 <member type="way" ref="23598454" role=""/> 156 <member type="way" ref="23737552" role=""/> 157 <member type="way" ref="23737553" role=""/> 158 <member type="way" ref="23737667" role=""/> 159 <member type="way" ref="145738805" role=""/> 160 <member type="way" ref="24541552" role=""/> 161 <member type="way" ref="24541863" role=""/> 162 <member type="way" ref="24541865" role=""/> 163 <member type="way" ref="25681100" role=""/> 164 <member type="way" ref="25681103" role=""/> 165 <member type="way" ref="25681278" role=""/> 166 <member type="way" ref="25681279" role=""/> 167 <member type="way" ref="25681280" role=""/> 168 <member type="way" ref="25681403" role=""/> 169 <member type="way" ref="25681444" role=""/> 170 <member type="way" ref="25681445" role=""/> 171 <member type="way" ref="25690338" role=""/> 172 <member type="way" ref="25690339" role=""/> 173 <member type="way" ref="25690340" role=""/> 174 <member type="way" ref="25690749" role=""/> 175 <member type="way" ref="43023896" role=""/> 176 <member type="way" ref="43023897" role=""/> 177 <member type="way" ref="25690753" role=""/> 178 <member type="way" ref="25690754" role=""/> 179 <member type="way" ref="25690755" role=""/> 180 <member type="way" ref="25690809" role=""/> 181 <member type="way" ref="25690810" role=""/> 182 <member type="way" ref="38328051" role=""/> 183 <member type="way" ref="38328052" role=""/> 184 <member type="way" ref="25691524" role=""/> 185 <member type="way" ref="101712789" role=""/> 186 <member type="way" ref="101712803" role=""/> 187 <member type="way" ref="25692910" role=""/> 188 <member type="way" ref="25698340" role=""/> 189 <member type="way" ref="25698341" role=""/> 190 <member type="way" ref="25698342" role=""/> 191 <member type="way" ref="25698343" role=""/> 192 <member type="way" ref="25698344" role=""/> 193 <member type="way" ref="25698346" role=""/> 194 <member type="way" ref="25698348" role=""/> 195 <member type="way" ref="25698352" role=""/> 196 <member type="way" ref="25698353" role=""/> 197 <member type="way" ref="25698354" role=""/> 198 <member type="way" ref="25698355" role=""/> 199 <member type="way" ref="26263982" role=""/> 200 <member type="way" ref="26955717" role=""/> 201 <member type="way" ref="28366733" role=""/> 202 <member type="way" ref="33971858" role=""/> 203 <member type="way" ref="33971859" role=""/> 204 <member type="way" ref="145738820" role=""/> 205 <member type="way" ref="33995569" role=""/> 206 <member type="way" ref="23737666" role=""/> 207 <member type="way" ref="41093668" role=""/> 208 <member type="way" ref="44051303" role=""/> 209 <member type="way" ref="44131233" role=""/> 210 <member type="way" ref="44131234" role=""/> 211 <member type="way" ref="25690748" role=""/> 212 <member type="way" ref="25690752" role=""/> 213 <member type="way" ref="44033101" role=""/> 214 <member type="way" ref="44202299" role=""/> 215 <member type="way" ref="44317183" role=""/> 216 <member type="way" ref="44317184" role=""/> 217 <member type="way" ref="44834939" role=""/> 218 <member type="way" ref="45317529" role=""/> 219 <member type="way" ref="45675161" role=""/> 220 <member type="way" ref="4275500" role=""/> 221 <member type="way" ref="53574779" role=""/> 222 <member type="way" ref="55041560" role=""/> 223 <member type="way" ref="62941752" role=""/> 224 <member type="way" ref="70914841" role=""/> 225 <member type="way" ref="100443831" role=""/> 226 <member type="way" ref="103058540" role=""/> 227 <member type="way" ref="103058539" role=""/> 228 <member type="way" ref="25691035" role=""/> 229 <member type="way" ref="145809031" role=""/> 230 <member type="way" ref="140969180" role=""/> 231 <member type="way" ref="140969209" role=""/> 232 <member type="way" ref="10989259" role=""/> 233 <member type="way" ref="141570176" role=""/> 234 <member type="way" ref="157621618" role=""/> 235 <member type="way" ref="157868715" role=""/> 236 <member type="way" ref="157868706" role=""/> 237 <member type="way" ref="157868717" role=""/> 238 <member type="way" ref="157868710" role=""/> 239 <member type="way" ref="157868709" role=""/> 240 <member type="way" ref="157868714" role=""/> 241 <member type="way" ref="157868705" role=""/> 242 <member type="way" ref="157868718" role=""/> 243 <member type="way" ref="157868711" role=""/> 244 <tag k="name" v="NCN National Route 61"/> 245 <tag k="network" v="ncn"/> 246 <tag k="ref" v="61"/> 247 <tag k="route" v="bicycle"/> 248 <tag k="type" v="route"/> 249 </relation> 250 <relation id="267403" version="2" timestamp="2010-02-16T13:21:24Z" uid="91657" user="Pink Duck" changeset="3891683"> 251 <member type="node" ref="502550970" role=""/> 252 <member type="node" ref="502552090" role=""/> 253 <tag k="name" v="Oaktree Close"/> 254 <tag k="naptan:StopAreaCode" v="210G896"/> 255 <tag k="naptan:StopAreaType" v="GPBS"/> 256 <tag k="naptan:verified" v="no"/> 257 <tag k="site" v="stop_area"/> 258 <tag k="source" v="naptan_import"/> 259 <tag k="type" v="site"/> 260 </relation> 261 <relation id="267404" version="2" timestamp="2010-02-16T13:21:22Z" uid="91657" user="Pink Duck" changeset="3891683"> 262 <member type="node" ref="502550921" role=""/> 263 <member type="node" ref="502552074" role=""/> 264 <tag k="name" v="Burfield Close"/> 265 <tag k="naptan:StopAreaCode" v="210G897"/> 266 <tag k="naptan:StopAreaType" v="GPBS"/> 267 <tag k="naptan:verified" v="no"/> 268 <tag k="site" v="stop_area"/> 269 <tag k="source" v="naptan_import"/> 270 <tag k="type" v="site"/> 271 </relation> 272 <relation id="267400" version="2" timestamp="2010-02-16T13:21:23Z" uid="91657" user="Pink Duck" changeset="3891683"> 273 <member type="node" ref="502550963" role=""/> 274 <member type="node" ref="502552081" role=""/> 275 <tag k="name" v="Jasmine Gardens"/> 276 <tag k="naptan:StopAreaCode" v="210G895"/> 277 <tag k="naptan:StopAreaType" v="GPBS"/> 278 <tag k="naptan:verified" v="no"/> 279 <tag k="site" v="stop_area"/> 280 <tag k="source" v="naptan_import"/> 281 <tag k="type" v="site"/> 282 </relation> 283 </osm> 284 ''' 285 286 from xml.etree import ElementTree 287 from functools import reduce 288 289 types = { 290 "way": "Way.class", 291 "node": "Node.class" 292 } 293 294 tree = ElementTree.fromstring(relationxml) 295 for rel in tree.findall('relation'): 296 297 memberTypes = [ types[m.get('type')] for m in rel.findall('member') ] 298 299 memberIDs = [ m.get('ref') for m in rel.findall('member') ] 300 tags = [ [ '"'+m.get('k')+'"', '"'+m.get('v')+'"' ] for m in rel.findall('tag') ] 301 tags = reduce(list.__add__, tags) 302 303 print(f'ExpectedRelation({rel.get("id")}, List.of({", ".join(memberTypes)}), List.of({"l, ".join(memberIDs)}l), List.of({", ".join(tags)})),')