add integration tests

master
Oliver Tonnhofer 2013-08-02 10:58:15 +02:00
parent f3155e9b7a
commit 6857c1f011
4 changed files with 720 additions and 0 deletions

81
test/test.osc Normal file
View File

@ -0,0 +1,81 @@
<?xml version='1.0' encoding='UTF-8'?>
<osmChange version="0.6" generator="Osmosis 0.41">
<modify>
<node id="1001" version="2" lat="47.5" lon="13.5"/>
</modify>
<add>
<node id="10001" version="2" lat="40.0" lon="10.0">
<tag k="name" v="Bar"/>
<tag k="place" v="village"/>
</node>
</add>
<modify>
<!-- modify but not present in initial import -->
<node id="10002" version="2" lat="40.0" lon="10.1">
<tag k="name" v="Baz"/>
<tag k="place" v="city"/>
</node>
</modify>
<delete>
<node id="10000" version="2" lat="40.0" lon="10.1"/>
</delete>
<delete>
<relation id="2001"/>
</delete>
<modify>
<!-- change landuse=park to natural=water -->
<way id="11001" version="2" timestamp="2011-11-11T00:11:11Z">
<nd ref="11001"/>
<nd ref="11002"/>
<nd ref="11003"/>
<nd ref="11004"/>
<nd ref="11001"/>
<tag k="name" v="way 11001"/>
<tag k="natural" v="water"/>
</way>
<way id="12001" version="2" timestamp="2011-11-11T00:11:11Z">
<nd ref="12001"/>
<nd ref="12002"/>
<nd ref="12003"/>
<nd ref="12004"/>
<nd ref="12001"/>
<tag k="name" v="way 12001"/>
<tag k="natural" v="water"/>
</way>
<relation id="13001" version="2" timestamp="2011-11-11T00:11:11Z">
<member type="way" ref="13001" role="outer"/>
<tag k="natural" v="water"/>
<tag k="type" v="multipolygon"/>
</relation>
</modify>
<!-- test for changed tags from way to relation and added tag to contained way -->
<modify>
<way id="14001" version="2" timestamp="2011-11-11T00:11:11Z">
<nd ref="14001"/>
<nd ref="14002"/>
<nd ref="14003"/>
<nd ref="14004"/>
<nd ref="14001"/>
<tag k="name" v="way 14001"/>
</way>
<way id="14011" version="2" timestamp="2011-11-11T00:11:11Z">
<nd ref="14011"/>
<nd ref="14012"/>
<nd ref="14013"/>
<nd ref="14014"/>
<nd ref="14011"/>
<tag k="name" v="way 14011"/>
<tag k="natural" v="water"/>
</way>
<relation id="14001" version="2" timestamp="2011-11-11T00:11:11Z">
<member type="way" ref="14001" role="outer"/>
<member type="way" ref="14011" role="inner"/>
<tag k="type" v="multipolygon"/>
<tag k="landuse" v="park"/>
</relation>
</modify>
</osmChange>

391
test/test.osm Normal file
View File

@ -0,0 +1,391 @@
<?xml version='1.0' encoding='UTF-8'?>
<osm version="0.6" generator="Osmosis SNAPSHOT-r25240">
<node id="10000" version="1" timestamp="2011-11-11T00:11:11Z" lat="40.0" lon="10.0">
<tag k="name" v="Foo"/>
<tag k="place" v="village"/>
</node>
<node id="1001" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.5" lon="13"/>
<node id="1002" version="1" timestamp="2011-11-11T00:11:11Z" lat="50" lon="14.5"/>
<node id="1003" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="16.5"/>
<node id="1004" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="17"/>
<node id="1005" version="1" timestamp="2011-11-11T00:11:11Z" lat="45.5" lon="14.5"/>
<node id="1006" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.5" lon="14"/>
<node id="1007" version="1" timestamp="2011-11-11T00:11:11Z" lat="48.5" lon="14.5"/>
<node id="1008" version="1" timestamp="2011-11-11T00:11:11Z" lat="48" lon="15.5"/>
<node id="1009" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="15"/>
<node id="2001" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.5" lon="23"/>
<node id="2002" version="1" timestamp="2011-11-11T00:11:11Z" lat="50" lon="24.5"/>
<node id="2003" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="26.5"/>
<node id="2004" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="27"/>
<node id="2005" version="1" timestamp="2011-11-11T00:11:11Z" lat="45.5" lon="24.5"/>
<node id="2006" version="1" timestamp="2011-11-11T00:11:11Z" lat="48.25" lon="24.2"/>
<node id="2007" version="1" timestamp="2011-11-11T00:11:11Z" lat="49.25" lon="24.7"/>
<node id="2008" version="1" timestamp="2011-11-11T00:11:11Z" lat="48.8" lon="25.7"/>
<node id="2009" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.7" lon="25.25"/>
<node id="2010" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="24.5"/>
<node id="2011" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.5" lon="25"/>
<node id="2012" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.5" lon="26"/>
<node id="2013" version="1" timestamp="2011-11-11T00:11:11Z" lat="46.5" lon="25.5"/>
<node id="3001" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.5" lon="33"/>
<node id="3002" version="1" timestamp="2011-11-11T00:11:11Z" lat="50" lon="34.5"/>
<node id="3003" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="36.5"/>
<node id="3004" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="37"/>
<node id="3005" version="1" timestamp="2011-11-11T00:11:11Z" lat="45.5" lon="34.5"/>
<node id="3006" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.5" lon="34"/>
<node id="3007" version="1" timestamp="2011-11-11T00:11:11Z" lat="48.5" lon="34.5"/>
<node id="3008" version="1" timestamp="2011-11-11T00:11:11Z" lat="48" lon="35.5"/>
<node id="3009" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="35"/>
<node id="4001" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.5" lon="41"/>
<node id="4002" version="1" timestamp="2011-11-11T00:11:11Z" lat="50" lon="42.5"/>
<node id="4003" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="44.5"/>
<node id="4004" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="45"/>
<node id="4005" version="1" timestamp="2011-11-11T00:11:11Z" lat="45.5" lon="42.5"/>
<node id="4006" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="45"/>
<node id="4007" version="1" timestamp="2011-11-11T00:11:11Z" lat="50" lon="46"/>
<node id="4008" version="1" timestamp="2011-11-11T00:11:11Z" lat="48.5" lon="48"/>
<node id="4009" version="1" timestamp="2011-11-11T00:11:11Z" lat="45.5" lon="46.5"/>
<node id="4010" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="45.5"/>
<node id="5001" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.5" lon="51"/>
<node id="5002" version="1" timestamp="2011-11-11T00:11:11Z" lat="50" lon="52.5"/>
<node id="5003" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="54.5"/>
<node id="5004" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="55"/>
<node id="5005" version="1" timestamp="2011-11-11T00:11:11Z" lat="45.5" lon="52.5"/>
<node id="5006" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="55"/>
<node id="5007" version="1" timestamp="2011-11-11T00:11:11Z" lat="50" lon="56"/>
<node id="5008" version="1" timestamp="2011-11-11T00:11:11Z" lat="48.5" lon="58"/>
<node id="5009" version="1" timestamp="2011-11-11T00:11:11Z" lat="45.5" lon="56.5"/>
<node id="5010" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="55.5"/>
<node id="5011" version="1" timestamp="2011-11-11T00:11:11Z" lat="48" lon="52"/>
<node id="5012" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="53.5"/>
<node id="5013" version="1" timestamp="2011-11-11T00:11:11Z" lat="48" lon="54"/>
<node id="5014" version="1" timestamp="2011-11-11T00:11:11Z" lat="46.5" lon="53.5"/>
<node id="5015" version="1" timestamp="2011-11-11T00:11:11Z" lat="46.5" lon="52.5"/>
<node id="5016" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="55.5"/>
<node id="5017" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="56.5"/>
<node id="5018" version="1" timestamp="2011-11-11T00:11:11Z" lat="48" lon="57"/>
<node id="5019" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="56.5"/>
<node id="5020" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.5" lon="55.7"/>
<node id="6001" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.5" lon="61.5"/>
<node id="6002" version="1" timestamp="2011-11-11T00:11:11Z" lat="50.5" lon="63.5"/>
<node id="6003" version="1" timestamp="2011-11-11T00:11:11Z" lat="50" lon="67"/>
<node id="6004" version="1" timestamp="2011-11-11T00:11:11Z" lat="46.5" lon="67.5"/>
<node id="6005" version="1" timestamp="2011-11-11T00:11:11Z" lat="45" lon="65"/>
<node id="6006" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.5" lon="63"/>
<node id="6007" version="1" timestamp="2011-11-11T00:11:11Z" lat="49.8" lon="64.5"/>
<node id="6008" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.75" lon="66.6"/>
<node id="6009" version="1" timestamp="2011-11-11T00:11:11Z" lat="45.75" lon="65.3"/>
<node id="6010" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.6" lon="63"/>
<node id="6011" version="1" timestamp="2011-11-11T00:11:11Z" lat="48.2" lon="64.5"/>
<node id="6012" version="1" timestamp="2011-11-11T00:11:11Z" lat="48.2" lon="65.5"/>
<node id="6013" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.2" lon="65"/>
<node id="7001" version="1" timestamp="2011-11-11T00:11:11Z" lat="45" lon="72"/>
<node id="7002" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="72"/>
<node id="7003" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="74"/>
<node id="7004" version="1" timestamp="2011-11-11T00:11:11Z" lat="48" lon="74"/>
<node id="7005" version="1" timestamp="2011-11-11T00:11:11Z" lat="50" lon="73"/>
<node id="7006" version="1" timestamp="2011-11-11T00:11:11Z" lat="50" lon="75"/>
<node id="7007" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="76"/>
<node id="7008" version="1" timestamp="2011-11-11T00:11:11Z" lat="45" lon="76"/>
<way id="1001" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="1001"/>
<nd ref="1002"/>
<nd ref="1003"/>
<nd ref="1004"/>
<nd ref="1005"/>
<nd ref="1001"/>
<tag k="name" v="way 1001"/>
<tag k="landuse" v="wood"/>
</way>
<way id="1002" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="1006"/>
<nd ref="1007"/>
<nd ref="1008"/>
<nd ref="1009"/>
<nd ref="1006"/>
<tag k="name" v="way 1002"/>
<tag k="landuse" v="wood"/>
</way>
<way id="2001" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="2001"/>
<nd ref="2002"/>
<nd ref="2003"/>
<nd ref="2004"/>
<nd ref="2005"/>
<nd ref="2001"/>
<tag k="name" v="way 2001"/>
</way>
<way id="2002" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="2006"/>
<nd ref="2007"/>
<nd ref="2008"/>
<nd ref="2009"/>
<nd ref="2006"/>
<tag k="name" v="way 2002"/>
<tag k="landuse" v="wood"/>
</way>
<way id="2003" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="2010"/>
<nd ref="2011"/>
<nd ref="2012"/>
<nd ref="2013"/>
<nd ref="2010"/>
<tag k="name" v="way 2003"/>
<tag k="landuse" v="water"/>
</way>
<way id="3001" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="3001"/>
<nd ref="3002"/>
<nd ref="3003"/>
<tag k="name" v="way 3001"/>
<tag k="landuse" v="park"/>
</way>
<way id="3002" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="3003"/>
<nd ref="3004"/>
<nd ref="3005"/>
<nd ref="3001"/>
<tag k="name" v="way 3002"/>
<tag k="landuse" v="park"/>
</way>
<way id="3003" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="3006"/>
<nd ref="3007"/>
<nd ref="3008"/>
<nd ref="3009"/>
<nd ref="3006"/>
<tag k="name" v="way 3003"/>
<tag k="landuse" v="water"/>
</way>
<way id="4001" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="4001"/>
<nd ref="4002"/>
<nd ref="4003"/>
<nd ref="4004"/>
<nd ref="4005"/>
<nd ref="4001"/>
<tag k="name" v="way 4001"/>
<tag k="landuse" v="park"/>
</way>
<way id="4002" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="4006"/>
<nd ref="4007"/>
<nd ref="4008"/>
<nd ref="4009"/>
<nd ref="4010"/>
<nd ref="4006"/>
<tag k="name" v="way 4002"/>
<tag k="landuse" v="park"/>
</way>
<way id="5001" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="5001"/>
<nd ref="5005"/>
<nd ref="5004"/>
<nd ref="5003"/>
<nd ref="5002"/>
<nd ref="5001"/>
<tag k="name" v="way 5001"/>
<tag k="landuse" v="park"/>
</way>
<way id="5002" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="5006"/>
<nd ref="5007"/>
<nd ref="5008"/>
<nd ref="5009"/>
<nd ref="5010"/>
<nd ref="5006"/>
<tag k="name" v="way 5002"/>
<tag k="landuse" v="park"/>
</way>
<way id="5003" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="5011"/>
<nd ref="5015"/>
<nd ref="5014"/>
<nd ref="5013"/>
<tag k="name" v="way 5003"/>
<tag k="landuse" v="water"/>
</way>
<way id="5004" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="5011"/>
<nd ref="5012"/>
<nd ref="5013"/>
<tag k="name" v="way 5004"/>
<tag k="landuse" v="water"/>
</way>
<way id="5005" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="5016"/>
<nd ref="5017"/>
<nd ref="5018"/>
<nd ref="5019"/>
<nd ref="5020"/>
<nd ref="5016"/>
<tag k="name" v="way 5005"/>
<tag k="landuse" v="wood"/>
</way>
<way id="6001" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="6001"/>
<nd ref="6002"/>
<nd ref="6003"/>
<nd ref="6004"/>
<nd ref="6005"/>
<nd ref="6001"/>
<tag k="name" v="way 6001"/>
<tag k="landuse" v="wood"/>
</way>
<way id="6002" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="6006"/>
<nd ref="6007"/>
<nd ref="6008"/>
<nd ref="6009"/>
<nd ref="6006"/>
<tag k="name" v="way 6002"/>
<tag k="landuse" v="river"/>
</way>
<way id="6003" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="6010"/>
<nd ref="6011"/>
<nd ref="6012"/>
<nd ref="6013"/>
<nd ref="6010"/>
<tag k="name" v="way 6003"/>
<tag k="landuse" v="park"/>
</way>
<way id="7001" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="7008"/>
<nd ref="7007"/>
<nd ref="7003"/>
<nd ref="7004"/>
<nd ref="7006"/>
<nd ref="7005"/>
<nd ref="7004"/>
<nd ref="7003"/>
<nd ref="7002"/>
<nd ref="7001"/>
<nd ref="7008"/>
<tag k="name" v="way 7001"/>
<tag k="landuse" v="none"/>
</way>
<relation id="1001" version="1" timestamp="2011-11-11T00:11:11Z">
<member type="way" ref="1001" role="outer"/>
<member type="way" ref="1002" role="inner"/>
<tag k="type" v="multipolygon"/>
</relation>
<relation id="2001" version="1" timestamp="2011-11-11T00:11:11Z">
<member type="way" ref="2001" role="outer"/>
<member type="way" ref="2002" role="inner"/>
<member type="way" ref="2003" role="inner"/>
<tag k="type" v="multipolygon"/>
<tag k="landuse" v="park"/>
</relation>
<relation id="3001" version="1" timestamp="2011-11-11T00:11:11Z">
<member type="way" ref="3001" role="outer"/>
<member type="way" ref="3002" role="outer"/>
<member type="way" ref="3003" role="inner"/>
<tag k="type" v="multipolygon"/>
</relation>
<relation id="4001" version="1" timestamp="2011-11-11T00:11:11Z">
<member type="way" ref="4001" role="outer"/>
<member type="way" ref="4002" role="outer"/>
<tag k="type" v="multipolygon"/>
</relation>
<relation id="5001" version="1" timestamp="2011-11-11T00:11:11Z">
<member type="way" ref="5001" role="outer"/>
<member type="way" ref="5002" role="outer"/>
<member type="way" ref="5003" role="inner"/>
<member type="way" ref="5004" role="inner"/>
<member type="way" ref="5005" role="outer"/>
<tag k="type" v="multipolygon"/>
</relation>
<relation id="6001" version="1" timestamp="2011-11-11T00:11:11Z">
<member type="way" ref="6001" role="outer"/>
<member type="way" ref="6002" role="inner"/>
<member type="way" ref="6003" role="outer"/>
<tag k="type" v="multipolygon"/>
</relation>
<!-- test for changed tags in way -->
<node id="11001" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="83"/>
<node id="11002" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="84"/>
<node id="11003" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="84"/>
<node id="11004" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="83"/>
<way id="11001" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="11001"/>
<nd ref="11002"/>
<nd ref="11003"/>
<nd ref="11004"/>
<nd ref="11001"/>
<tag k="name" v="way 11001"/>
<tag k="landuse" v="park"/>
</way>
<!-- test for changed tags in way belonging to relation -->
<node id="12001" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="85"/>
<node id="12002" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="86"/>
<node id="12003" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="86"/>
<node id="12004" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="85"/>
<way id="12001" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="12001"/>
<nd ref="12002"/>
<nd ref="12003"/>
<nd ref="12004"/>
<nd ref="12001"/>
<tag k="name" v="way 12001"/>
<tag k="landuse" v="park"/>
</way>
<relation id="12001" version="1" timestamp="2011-11-11T00:11:11Z">
<member type="way" ref="12001" role="outer"/>
<tag k="type" v="multipolygon"/>
</relation>
<!-- test for changed tags in relation -->
<node id="13001" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="87"/>
<node id="13002" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="88"/>
<node id="13003" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="88"/>
<node id="13004" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="87"/>
<way id="13001" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="13001"/>
<nd ref="13002"/>
<nd ref="13003"/>
<nd ref="13004"/>
<nd ref="13001"/>
<tag k="name" v="way 13001"/>
</way>
<relation id="13001" version="1" timestamp="2011-11-11T00:11:11Z">
<member type="way" ref="13001" role="outer"/>
<tag k="landuse" v="park"/>
<tag k="type" v="multipolygon"/>
</relation>
<!-- test for changed tags from way to relation and added tag to contained way -->
<node id="14001" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="89"/>
<node id="14002" version="1" timestamp="2011-11-11T00:11:11Z" lat="47" lon="90"/>
<node id="14003" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="90"/>
<node id="14004" version="1" timestamp="2011-11-11T00:11:11Z" lat="49" lon="89"/>
<node id="14011" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.1" lon="89.1"/>
<node id="14012" version="1" timestamp="2011-11-11T00:11:11Z" lat="47.1" lon="89.9"/>
<node id="14013" version="1" timestamp="2011-11-11T00:11:11Z" lat="48.9" lon="89.9"/>
<node id="14014" version="1" timestamp="2011-11-11T00:11:11Z" lat="48.9" lon="89.1"/>
<way id="14001" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="14001"/>
<nd ref="14002"/>
<nd ref="14003"/>
<nd ref="14004"/>
<nd ref="14001"/>
<tag k="name" v="way 14001"/>
<tag k="landuse" v="park"/>
</way>
<way id="14011" version="1" timestamp="2011-11-11T00:11:11Z">
<nd ref="14011"/>
<nd ref="14012"/>
<nd ref="14013"/>
<nd ref="14014"/>
<nd ref="14011"/>
<tag k="name" v="way 14011"/>
</way>
<relation id="14001" version="1" timestamp="2011-11-11T00:11:11Z">
<member type="way" ref="14001" role="outer"/>
<member type="way" ref="14011" role="inner"/>
<tag k="type" v="multipolygon"/>
</relation>
</osm>

241
test/test.py Normal file
View File

@ -0,0 +1,241 @@
import math
import tempfile
import atexit
import shutil
import subprocess
import psycopg2
import psycopg2.extras
import json
from shapely.wkb import loads as wkb_loads
from shapely.geometry import Point
import binascii
import unittest
class Dummy(unittest.TestCase):
def nop():
pass
_t = Dummy('nop')
assert_almost_equal = _t.assertAlmostEqual
# tmpdir = tempfile.mkdtemp()
# def cleanup_tmpdir():
# shutil.rmtree(tmpdir)
# atexit.register(cleanup_tmpdir)
tmpdir = '/tmp/testtest'
db_conf = {
'database': 'olt',
'user': 'olt',
'password': 'olt',
'host': 'localhost',
}
def merc_point(lon, lat):
pole = 6378137 * math.pi # 20037508.342789244
x = lon * pole / 180.0
y = math.log(math.tan((90.0+lat)*math.pi/360.0)) / math.pi * pole
return Point(x, y)
def pg_db_url(db_conf):
return 'postgis://%(user)s:%(password)s@%(host)s/%(database)s' % db_conf
def create_geom_in_row(rowdict):
if rowdict:
rowdict['geometry'] = wkb_loads(binascii.unhexlify(rowdict['geometry']))
return rowdict
def query_row(db_conf, table, osmid):
conn = psycopg2.connect(**db_conf)
cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute('select * from import.%s where osm_id = %%s' % table, [osmid])
row = cur.fetchone()
create_geom_in_row(row)
return row
def goposm_import(db_conf, pbf):
conn = pg_db_url(db_conf)
try:
print subprocess.check_output(
"../goposm import -connection %s -read %s"
" -write"
" -cachedir %s"
" -diff"
" -overwritecache"
" -mapping test_mapping.json " % (
conn, pbf, tmpdir,
), shell=True)
except subprocess.CalledProcessError, ex:
print ex.output
raise
def goposm_update(db_conf, osc):
conn = pg_db_url(db_conf)
try:
print subprocess.check_output(
"../goposm diff -connection %s"
" -cachedir %s"
" -mapping test_mapping.json %s" % (
conn, tmpdir, osc,
), shell=True)
except subprocess.CalledProcessError, ex:
print ex.output
raise
def cache_query(nodes='', ways='', relations=''):
if nodes:
nodes = '-node ' + ','.join(map(str, nodes))
if ways:
ways = '-way ' + ','.join(map(str, ways))
if relations:
relations = '-rel' + ','.join(map(str, relations))
out = subprocess.check_output(
"../goposm query-cache -cachedir %s %s %s %s" % (tmpdir, nodes, ways, relations),
shell=True)
print out
return json.loads(out)
def table_exists(table):
conn = psycopg2.connect(**db_conf)
cur = conn.cursor()
cur.execute("SELECT EXISTS(SELECT * FROM information_schema.tables WHERE table_name='%s' AND table_schema='%s')"
% (table, 'import'))
return cur.fetchone()[0]
def assert_missing_node(id):
data = cache_query(nodes=[id])
if data['nodes'][str(id)]:
raise AssertionError('node %d found' % id)
def assert_cached_node(id, (lon, lat)=(None, None)):
data = cache_query(nodes=[id])
node = data['nodes'][str(id)]
if not node:
raise AssertionError('node %d not found' % id)
if lon and lat:
assert_almost_equal(lon, node['lon'], 6)
assert_almost_equal(lat, node['lat'], 6)
def assert_cached_way(id):
data = cache_query(ways=[id])
if not data['ways'][str(id)]:
raise AssertionError('way %d not found' % id)
def drop_import_schema():
conn = psycopg2.connect(**db_conf)
cur = conn.cursor()
cur.execute("DROP SCHEMA IF EXISTS import CASCADE")
conn.commit()
#######################################################################
def test_import():
"""Import succeeds"""
drop_import_schema()
assert not table_exists('osm_roads')
goposm_import(db_conf, './test.pbf')
assert table_exists('osm_roads')
#######################################################################
def test_imported_landusage():
"""Multipolygon relation is inserted"""
assert_cached_node(1001, (13, 47.5))
landusage_1001 = query_row(db_conf, 'osm_landusages', 1001)
# point in polygon
assert landusage_1001['geometry'].intersects(merc_point(13.4, 47.5))
# hole in multipolygon relation
assert not landusage_1001['geometry'].intersects(merc_point(14.75, 47.75))
def test_missing_nodes():
"""Cache does not contain nodes from previous imports"""
assert_missing_node(10001)
assert_missing_node(10002)
place_10000 = query_row(db_conf, 'osm_places', 10000)
assert place_10000['name'] == 'Foo', place_10000
def test_landusage_to_waterarea_1():
"""Parks inserted into landusages"""
assert_cached_way(11001)
assert_cached_way(12001)
assert_cached_way(13001)
assert not query_row(db_conf, 'osm_waterareas', 11001)
assert not query_row(db_conf, 'osm_waterareas', 12001)
assert not query_row(db_conf, 'osm_waterareas', 13001)
assert query_row(db_conf, 'osm_landusages', 11001)['type'] == 'park'
assert query_row(db_conf, 'osm_landusages', 12001)['type'] == 'park'
assert query_row(db_conf, 'osm_landusages', 13001)['type'] == 'park'
def test_changed_hole_tags_1():
"""Multipolygon relation with untagged hole"""
assert_cached_way(14001)
assert_cached_way(14011)
assert not query_row(db_conf, 'osm_waterareas', 14011)
assert query_row(db_conf, 'osm_landusages', 14001)['type'] == 'park'
#######################################################################
def test_update():
"""Diff import applies"""
goposm_update(db_conf, './test.osc.gz')
#######################################################################
def test_updated_landusage():
"""Multipolygon relation was modified"""
assert_cached_node(1001, (13.5, 47.5))
landusage_1001 = query_row(db_conf, 'osm_landusages', 1001)
# point not in polygon after update
assert not landusage_1001['geometry'].intersects(merc_point(13.4, 47.5))
def test_partial_delete():
"""Deleted relation but nodes are still cached"""
assert_cached_node(2001)
assert_cached_way(2001)
assert_cached_way(2002)
assert not query_row(db_conf, 'osm_landusages', 2001)
def test_updated_nodes():
"""Nodes were added, modified or deleted"""
assert_missing_node(10000)
assert_cached_node(10001, (10.0, 40.0))
assert_cached_node(10002, (10.1, 40.0))
place_10001 = query_row(db_conf, 'osm_places', 10001)
assert place_10001['name'] == 'Bar', place_10001
place_10001 = query_row(db_conf, 'osm_places', 10002)
assert place_10001['name'] == 'Baz', place_10001
def test_landusage_to_waterarea_2():
"""Parks converted to water moved from landusages to waterareas"""
assert_cached_way(11001)
assert_cached_way(12001)
assert_cached_way(13001)
assert not query_row(db_conf, 'osm_landusages', 11001)
assert not query_row(db_conf, 'osm_landusages', 12001)
assert not query_row(db_conf, 'osm_landusages', 13001)
assert query_row(db_conf, 'osm_waterareas', 11001)['type'] == 'water'
assert query_row(db_conf, 'osm_waterareas', 12001)['type'] == 'water'
assert query_row(db_conf, 'osm_waterareas', 13001)['type'] == 'water'
def test_changed_hole_tags_2():
"""Newly tagged hole is inserted"""
assert_cached_way(14001)
assert_cached_way(14011)
assert query_row(db_conf, 'osm_waterareas', 14011)['type'] == 'water'
assert query_row(db_conf, 'osm_landusages', 14001)['type'] == 'park'
assert_almost_equal(query_row(db_conf, 'osm_landusages', 14001)['geometry'].area, 10373600000, -6)
assert_almost_equal(query_row(db_conf, 'osm_waterareas', 14011)['geometry'].area, 26672000000, -6)

7
test/update_test_env.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -x
pushd ..
go build
popd
osmosis --read-xml ./test.osm --write-pbf ./test.pbf omitmetadata=true
gzip --stdout ./test.osc > ./test.osc.gz