def test_parse_matchers__without_provider(self): unit = TestPlanUnit({}, provider=None) self.assertEqual( list(unit.parse_matchers("foo")), [(0, 'id', OperatorMatcher(operator.eq, 'foo'), None)]) self.assertEqual( list(unit.parse_matchers("other::bar")), [(0, 'id', OperatorMatcher(operator.eq, "other::bar"), None)]) self.assertEqual(list(unit.parse_matchers("sd[a-z]")), [(0, 'id', PatternMatcher("^sd[a-z]$"), None)]) self.assertEqual(list(unit.parse_matchers("sd[a-z]$")), [(0, 'id', PatternMatcher("^sd[a-z]$"), None)]) self.assertEqual(list(unit.parse_matchers("^sd[a-z]")), [(0, 'id', PatternMatcher("^sd[a-z]$"), None)]) self.assertEqual(list(unit.parse_matchers("^sd[a-z]$")), [(0, 'id', PatternMatcher("^sd[a-z]$"), None)])
def visit_IncludeStmt_node(self, node: IncludeStmt): if isinstance(node.pattern, ReErr): matcher = None error = node.pattern.exc elif isinstance(node.pattern, ReFixed): target_id = outer_self.qualify_id(node.pattern.text) matcher = OperatorMatcher(operator.eq, target_id) error = None elif isinstance(node.pattern, RePattern): text = node.pattern.text # Ensure that pattern is surrounded by ^ and $ if text.startswith('^') and text.endswith('$'): target_id_pattern = '^{}$'.format( outer_self.qualify_id(text[1:-1])) elif text.startswith('^'): target_id_pattern = '^{}$'.format( outer_self.qualify_id(text[1:])) elif text.endswith('$'): target_id_pattern = '^{}$'.format( outer_self.qualify_id(text[:-1])) else: target_id_pattern = '^{}$'.format( outer_self.qualify_id(text)) matcher = PatternMatcher(target_id_pattern) error = None result = (node.lineno, 'id', matcher, error) self.results.append(result)
def visit_IncludeStmt_node(self, node: IncludeStmt): if isinstance(node.pattern, ReFixed): target_id = testplan.qualify_id(node.pattern.text) matcher = OperatorMatcher(operator.eq, target_id) elif isinstance(node.pattern, RePattern): pattern = testplan.qualify_pattern(node.pattern.text) matcher = PatternMatcher(pattern) result = (node.lineno, 'id', matcher) results.append(result)
def test_repr(self): self.assertEqual(repr(PatternMatcher("text")), "PatternMatcher('text')")
def test_match(self): matcher = PatternMatcher("foo.*") self.assertTrue(matcher.match("foobar")) self.assertFalse(matcher.match("fo"))