forked from osm-fr/osmose-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Construction2.py
73 lines (58 loc) · 4.19 KB
/
Construction2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#-*- coding: utf-8 -*-
from __future__ import unicode_literals
import modules.mapcss_lib as mapcss
import regex as re
from plugins.Plugin import Plugin, with_options
class Construction2(Plugin):
def init(self, logger):
Plugin.init(self, logger)
tags = capture_tags = {}
self.errors[40701] = {'item': 4070, 'level': 1, 'tag': mapcss.list_(u'tag', u'highway', u'fix:survey'), 'desc': mapcss.tr(u'Inconsistent tagging of {0}', mapcss._tag_uncapture(capture_tags, u'{1.key}'))}
def way(self, data, tags, nds):
capture_tags = {}
keys = tags.keys()
err = []
# way[highway][construction][highway!=construction][construction!=minor]
# way[highway][proposed][highway!=proposed]
# way[railway][construction][railway!=construction][construction!=minor]
# way[railway][proposed][railway!=proposed]
if (u'construction' in keys and u'highway' in keys) or (u'construction' in keys and u'railway' in keys) or (u'highway' in keys and u'proposed' in keys) or (u'proposed' in keys and u'railway' in keys):
match = False
if not match:
capture_tags = {}
try: match = (mapcss._tag_capture(capture_tags, 0, tags, u'highway') and mapcss._tag_capture(capture_tags, 1, tags, u'construction') and mapcss._tag_capture(capture_tags, 2, tags, u'highway') != mapcss._value_const_capture(capture_tags, 2, u'construction', u'construction') and mapcss._tag_capture(capture_tags, 3, tags, u'construction') != mapcss._value_const_capture(capture_tags, 3, u'minor', u'minor'))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = (mapcss._tag_capture(capture_tags, 0, tags, u'highway') and mapcss._tag_capture(capture_tags, 1, tags, u'proposed') and mapcss._tag_capture(capture_tags, 2, tags, u'highway') != mapcss._value_const_capture(capture_tags, 2, u'proposed', u'proposed'))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = (mapcss._tag_capture(capture_tags, 0, tags, u'railway') and mapcss._tag_capture(capture_tags, 1, tags, u'construction') and mapcss._tag_capture(capture_tags, 2, tags, u'railway') != mapcss._value_const_capture(capture_tags, 2, u'construction', u'construction') and mapcss._tag_capture(capture_tags, 3, tags, u'construction') != mapcss._value_const_capture(capture_tags, 3, u'minor', u'minor'))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = (mapcss._tag_capture(capture_tags, 0, tags, u'railway') and mapcss._tag_capture(capture_tags, 1, tags, u'proposed') and mapcss._tag_capture(capture_tags, 2, tags, u'railway') != mapcss._value_const_capture(capture_tags, 2, u'proposed', u'proposed'))
except mapcss.RuleAbort: pass
if match:
# -osmoseItemClassLevel:"4070/40701/1"
# throwError:tr("Inconsistent tagging of {0}","{1.key}")
# assertNoMatch:"way highway=construction construction=primary"
# assertNoMatch:"way highway=primary construction=minor"
# assertMatch:"way highway=primary construction=primary"
err.append({'class': 40701, 'subclass': 0, 'text': mapcss.tr(u'Inconsistent tagging of {0}', mapcss._tag_uncapture(capture_tags, u'{1.key}'))})
return err
from plugins.Plugin import TestPluginCommon
class Test(TestPluginCommon):
def test(self):
n = Construction2(None)
class _config:
options = {"country": None, "language": None}
class father:
config = _config()
n.father = father()
n.init(None)
data = {'id': 0, 'lat': 0, 'lon': 0}
self.check_not_err(n.way(data, {u'construction': u'primary', u'highway': u'construction'}, [0]), expected={'class': 40701, 'subclass': 0})
self.check_not_err(n.way(data, {u'construction': u'minor', u'highway': u'primary'}, [0]), expected={'class': 40701, 'subclass': 0})
self.check_err(n.way(data, {u'construction': u'primary', u'highway': u'primary'}, [0]), expected={'class': 40701, 'subclass': 0})