Changeset c216d9f in osmose-backend


Ignore:
Timestamp:
Oct 9, 2014 10:20:43 PM (5 years ago)
Author:
Frédéric Rodrigo <fred.rodrigo@…>
Branches:
master
Children:
2cd5c82
Parents:
72e5689
git-author:
Frédéric Rodrigo <fred.rodrigo@…> (09/10/2014 20:56:37)
git-committer:
Frédéric Rodrigo <fred.rodrigo@…> (09/10/2014 22:20:43)
Message:

Generalise Structural_Restriction plugin to all restriction types github#20

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/Structural_Restriction.py

    r89cb6e2 rc216d9f  
    2525class Structural_Restriction(Plugin): 
    2626 
    27     # Check for no u-turn on same road on countries where is forbidden 
    28     only_for = ["BR"] 
    29  
    3027    def init(self, logger): 
    3128        Plugin.init(self, logger) 
    3229        self.errors[31801] = {"item": 3180, "level": 2, "tag": ["relation", "restriction"], "desc": T_(u"Useless non u-turn restriction, it's forbidden by local law") } 
     30        self.Country = self.father.config.options.get("country") 
    3331 
    3432    def relation(self, data, tags, members): 
    35         if tags.get('type') == 'restriction' and tags.get('restriction') == 'no_u_turn': 
     33        # Check for no u-turn on same road on countries where is forbidden 
     34        if tags.get('type') == 'restriction' and (not tags.get('restriction') in ('no_straight_on', 'only_straight_on', 'no_u_turn') or (self.Country == 'BR' and tags.get('restriction') == 'no_u_turn')): 
    3635            from_ = set() 
    3736            to = set() 
     
    5150    def test(self): 
    5251        a = Structural_Restriction(None) 
     52        class _config: 
     53            options = {} 
     54        class father: 
     55            config = _config() 
     56        a.father = father() 
    5357        a.init(None) 
    5458 
    5559        assert not a.relation(None, {'type': 'restriction', 'restriction': 'no_u_turn'}, [{'role': 'to', 'ref': 229614650, 'type': 'way'}, {'role': 'via', 'ref': 160840160, 'type': 'way'}, {'role': 'from', 'ref': 229614674, 'type': 'way'}]) 
    5660        assert not a.relation(None, {'type': 'restriction', 'restriction': 'no_u_turn'}, [{'role':'from', 'ref': 1}, {'role': 'to', 'ref': 2}]) 
    57         assert not a.relation(None, {'type': 'restriction', 'restriction': 'text'}, [{'role':'from', 'ref': 1}, {'role': 'to', 'ref': 1}]) 
     61        self.check_err(a.relation(None, {'type': 'restriction', 'restriction': 'text'}, [{'role':'from', 'ref': 1}, {'role': 'to', 'ref': 1}])) 
     62        assert not a.relation(None, {'type': 'restriction', 'restriction': 'no_u_turn'}, [{'role':'from', 'ref': 1}, {'role': 'to', 'ref': 1}]) 
    5863 
     64    def test_BR(self): 
     65        a = Structural_Restriction(None) 
     66        class _config: 
     67            options = {"country": "BR"} 
     68        class father: 
     69            config = _config() 
     70        a.father = father() 
     71        a.init(None) 
     72 
     73        assert not a.relation(None, {'type': 'restriction', 'restriction': 'no_u_turn'}, [{'role': 'to', 'ref': 229614650, 'type': 'way'}, {'role': 'via', 'ref': 160840160, 'type': 'way'}, {'role': 'from', 'ref': 229614674, 'type': 'way'}]) 
     74        assert not a.relation(None, {'type': 'restriction', 'restriction': 'no_u_turn'}, [{'role':'from', 'ref': 1}, {'role': 'to', 'ref': 2}]) 
     75        self.check_err(a.relation(None, {'type': 'restriction', 'restriction': 'text'}, [{'role':'from', 'ref': 1}, {'role': 'to', 'ref': 1}])) 
    5976        self.check_err(a.relation(None, {'type': 'restriction', 'restriction': 'no_u_turn'}, [{'role':'from', 'ref': 1}, {'role': 'to', 'ref': 1}])) 
Note: See TracChangeset for help on using the changeset viewer.