+ Fundacul
[osm-ro-tools.git] / test / conftest.py
blob26ed44c7083cf63ceac03b4b73d46e85cac545ec
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 '''
4 Created on 27.10.2012
6 @author: eddy
7 '''
9 import pytest
10 import sys
11 sys.path.append('.')
13 emptymap = []
14 notagswaymap = [{u'type': u'way', u'data': {u'id': 1, u'tag': {}}}]
15 notagsnodemap = [{u'type': u'node', u'data': {u'id': 1, u'tag': {}}}]
17 simplemaps = [emptymap, notagsnodemap, notagswaymap]
20 # mostly for do_correct_names
21 nametagwaymap = [{u'type': u'way', u'data': {u'id': 1, u'tag': {u'name':u'Alea Prunului'}}}]
22 rentagwaymap = {
23 u'way': [
24 {u'id': 1, u'tag': {u'name':u'Aleea Prunului'}}
28 # TODO: check why unicodes don't work properly
29 #sametagwaymap = [{u'type': u'way', u'data': {u'id': 1, u'tag': {u'name': u'Fundătura Prunului'}}}]
30 sametagwaymap = [{u'type': u'way', u'data': {u'id': 1, u'tag': {u'name': u'Fundacul Prunului'}}}]
33 strtagwaymap = [{u'type': u'way', u'data': {u'id': 1, u'tag': {u'name':u'St. Prunului'}}}]
34 rstrtagwaymap = {
35 u'way': [
36 {u'id': 1, u'tag': {u'name':u'Strada Prunului'}}
41 # mostly for do_eref2int
42 oneerefinrefmap = [
43 {u'type': u'way',
44 u'data': {u'id': 1, u'tag': {u'ref':u'e 80'}}
47 oneerefinrefch = [
48 {u'type': u'way',
49 u'data': {u'id': 1, u'tag': {u'int_ref':u'E80'}},
50 'oldrecs': {u'ref': u'e 80', u'int_ref': u''},
51 'newrecs': {u'ref': u'' , u'int_ref': u'E80'}
55 duperefinrefmap = [
56 {u'type': u'way',
57 u'data': {u'id': 2, u'tag': {u'ref': u'e 80', u'int_ref':u'E80'}}
60 duperefinrefch = [
61 {u'type': u'way',
62 u'data': {u'id': 2, u'tag': {u'int_ref':u'E80'}},
63 'oldrecs': {u'ref': u'e 80', u'int_ref': u'E80'},
64 'newrecs': {u'ref': u'' , u'int_ref': u'E80'}
69 # for do_stdrefs and do_norefsinname
70 samerefinrefmap = [
71 {u'type': u'way',
72 u'data': {u'id': 1, u'tag': {u'ref':u'DN6', u'name': 'DN6'}}
75 samenameinrefch = [
76 {u'type' : u'way',
77 u'data' : {u'id': 1, u'tag': {u'ref': u'DN6'}},
78 'oldrecs': {u'ref': u'DN6', u'name': u'DN6'},
79 'newrecs': {u'ref': u'DN6' }
84 # for do_stdrefs
85 natrefinrefmap = [
86 {u'type': u'way',
87 u'data': {u'id': 1, u'tag': {u'ref':u'Dn 6', u'name': 'Dn6'}}
90 natrefinrefch = [
91 {u'type' : u'way',
92 u'data' : {u'id': 1, u'tag': {u'ref': u'DN6', u'name': 'Dn6'}},
93 'oldrecs': {u'ref': u'Dn 6'},
94 'newrecs': {u'ref': u'DN6' }
98 mixrefinrefmap = [
99 {u'type': u'way',
100 u'data': {u'id': 1, u'tag': {u'ref':u'Dn 6; e70', u'name': 'Dn6'}}
103 mixrefinrefch = [
104 {u'type': u'way',
105 u'data': {u'id': 1, u'tag': {u'ref': u'DN6;E70', u'name': 'Dn6'}},
106 'oldrecs': {u'ref': u'Dn 6; e70'},
107 'newrecs': {u'ref': u'DN6;E70' }
111 # mostly for get_shiftedpat
112 shiftpat = [{'in':['One ', 1, u' two ', 2], 'shift':0, 'out': u'One \\1 two \\2'}]
114 #@pytest.fixture(scope="module")
115 #def apiprovider():
116 # from OsmUtils import OsmApiExt()
118 #@pytest.fixture(params=simplemaps)
119 #def pytest_funcarg__mapprovider(pos):
120 # return simplemaps[pos]
123 class fakeApi():
124 def __init__(self, exupds, eltype):
125 self.eltype = eltype
126 self.upds = {eltype: []}
127 self.nonempty = False
128 self.exupds = exupds
129 self.cursors = {u'way': 0, u'node': 0, u'relation': 0}
130 if ((len(self.exupds.get(u'way', [])) > 0) or
131 (len(self.exupds.get(u'node', [])) > 0) or
132 (len(self.exupds.get(u'relation', [])) > 0)
134 self.nonempty = True
136 def __del__(self):
137 self.allExpectedChanges()
139 def noChanges(self):
140 assert len(self.upds.get(u'way', [])) == 0
141 assert len(self.upds.get(u'node', [])) == 0
142 assert len(self.upds.get(u'relation', [])) == 0
143 return True
145 def allExpectedChanges(self):
146 if self.nonempty:
147 assert self.exupds == self.upds
148 else:
149 self.noChanges()
151 def __elUpdate(self, updatedel, extype):
152 assert self.eltype == extype
153 ulist = self.upds[self.eltype]
154 cexpect = self.exupds[self.eltype][self.cursors[extype]]
155 exid = cexpect[u'id']
156 id = updatedel[u'id']
157 if (id != exid):
158 raise TypeError, u"Expected element with id=%d , but found something else" % exid
159 self.cursors[extype] += 1;
160 ulist.append(updatedel)
161 assert len(ulist) == self.cursors[extype]
163 def WayUpdate(self, updatednode):
164 self.__elUpdate(updatednode, u'way')
166 def NodeUpdate(self, updatednode):
167 self.__elUpdate(updatednode, u'node')