2 Tests for test_OsmRoConsistency
11 @pytest.mark
.parametrize('amap', simplemaps
)
12 def test_OsmRoConsistency(amap
):
13 from OsmRoConsistency
import do_stdref
14 newmap
= do_stdref(amap
)
15 assert len(newmap
) == 0
18 @pytest.mark
.parametrize(('istr','sep','olist'),
20 (u
'a;a;;', ';', [u
'a']),
21 (u
'a;a;;', None, [u
'a']),
22 ( 'z;x;y;z;a;b', None, [u
'a', u
'b', u
'x', u
'y', u
'z']),
23 (u
'b; a; a; c; dd; d;b', u
';', [u
'a', u
'b', u
'c', u
'd', u
'dd'])
25 def test_splitstripunique(istr
, sep
, olist
):
26 from OsmRoConsistency
import splitstripunique
28 r
= splitstripunique(istr
,sep
)
30 r
= splitstripunique(istr
)
33 r
= splitstripunique(sr
)
37 @pytest.mark
.parametrize('amap', simplemaps
)
38 def test_eref2intref_empty(amap
):
39 from OsmRoConsistency
import do_eref2int
40 ch
= do_eref2int(amap
)
44 @pytest.mark
.parametrize(('imap','exch', 'prevch'),
46 (duperefinrefmap
, duperefinrefch
, None),
47 #(oneerefinrefmap, oneerefinrefch, oneerefinrefch), #TODO: fix this
48 #(duperefinrefmap, duperefinrefch, duperefinrefch), #TODO: fix this
49 (duperefinrefmap
, duperefinrefch
, []),
50 (oneerefinrefmap
, oneerefinrefch
, None),
51 (oneerefinrefmap
, oneerefinrefch
, []),
53 def test_eref2intrefmove(imap
,exch
, prevch
):
54 from OsmRoConsistency
import do_eref2int
55 from copy
import deepcopy
56 mymap
= deepcopy(imap
)
58 resch
= do_eref2int(mymap
, prevch
)
60 resch
= do_eref2int(mymap
)
64 def test_get_shiftedpatrep():
65 from OsmRoConsistency
import get_shiftedpatrep
70 fout
= get_shiftedpatrep(ilst
, sh
)
73 get_shiftedpatrep([{}, 0], 0)
80 def test_usage(monkeypatch
, capfd
):
81 expected
= 'Test_command'
82 monkeypatch
.setattr(sys
, 'argv', [expected
])
83 from OsmRoConsistency
import usage
, __usage__
85 resout
, reserr
= capfd
.readouterr()
86 assert resout
== str((__usage__
+ u
'\n') % expected
).decode()
89 @pytest.mark
.parametrize(('imap', 'exupds', 'eltype'),
90 zip(simplemaps
, [{u
'way': []}] * len(simplemaps
), [u
'way']* len(simplemaps
)) +
92 (nametagwaymap
, rentagwaymap
, u
'way'),
93 (sametagwaymap
, {u
'way': []}, u
'way'),
94 (strtagwaymap
, rstrtagwaymap
, u
'way')
97 def test_do_correct_names(imap
, exupds
, eltype
):
99 def __init__(self
, exupds
, eltype
):
101 self
.upds
= {eltype
:[]}
102 self
.nonempty
= False
104 self
.cursors
= {u
'way':0, u
'node':0, u
'relation':0}
105 if ( (len(self
.exupds
.get(u
'way', []))>0) or
106 (len(self
.exupds
.get(u
'node', []))>0) or
107 (len(self
.exupds
.get(u
'relation', []))>0)
112 assert len(self
.upds
.get(u
'way', [])) == 0
113 assert len(self
.upds
.get(u
'node', [])) == 0
114 assert len(self
.upds
.get(u
'relation', [])) == 0
117 def allExpectedChanges(self
):
119 assert self
.exupds
== self
.upds
123 def __elUpdate(self
, updatedel
, extype
):
124 assert self
.eltype
== extype
125 ulist
= self
.upds
[self
.eltype
]
126 cexpect
= self
.exupds
[self
.eltype
][self
.cursors
[extype
]]
127 exid
= cexpect
[u
'id']
128 id = updatedel
[u
'id']
130 raise TypeError, u
"Expected element with id=%d , but found something else" % exid
131 self
.cursors
[extype
] += 1;
132 ulist
.append(updatedel
)
133 assert len(ulist
) == self
.cursors
[extype
]
135 def WayUpdate(self
, updatednode
):
136 self
.__elUpdate
(updatednode
, u
'way')
138 def NodeUpdate(self
, updatednode
):
139 self
.__elUpdate
(updatednode
, u
'node')
141 from OsmRoConsistency
import do_correct_names
142 api
= fakeApi(exupds
, eltype
)
143 do_correct_names(imap
, api
, True)
144 api
.allExpectedChanges()