1# Copyright 2008-2015 Nokia Networks 2# Copyright 2016- Robot Framework Foundation 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16from robot.utils import py2to3 17 18from .tags import TagPatterns 19 20 21@py2to3 22class Criticality(object): 23 24 def __init__(self, critical_tags=None, non_critical_tags=None): 25 self.critical_tags = self._get_tag_patterns(critical_tags) 26 self.non_critical_tags = self._get_tag_patterns(non_critical_tags) 27 28 def _get_tag_patterns(self, tags): 29 return TagPatterns(tags) if not isinstance(tags, TagPatterns) else tags 30 31 def tag_is_critical(self, tag): 32 return self.critical_tags.match(tag) 33 34 def tag_is_non_critical(self, tag): 35 return self.non_critical_tags.match(tag) 36 37 def test_is_critical(self, test): 38 if self.critical_tags and not self.critical_tags.match(test.tags): 39 return False 40 return not self.non_critical_tags.match(test.tags) 41 42 def __nonzero__(self): 43 return bool(self.critical_tags or self.non_critical_tags) 44