def test_absolute(self): # don't allow exclusions in an absolute pattern with self.assertRaises(ValueError): pattern = TagPattern.parse('#foo+a-b!') pattern = TagPattern.parse('#foo+a!') self.assertTrue(pattern.is_absolute) self.assertTrue(pattern.match(Column.parse('#foo+a'))) self.assertFalse(pattern.match(Column.parse('#foo'))) self.assertFalse(pattern.match(Column.parse('#foo+a+b')))
def test_parse(self): pattern = TagPattern.parse('#tag+foo-xxx') self.assertEqual(pattern.tag, '#tag') self.assertTrue('foo' in pattern.include_attributes) pattern = TagPattern.parse('tag+foo-xxx') self.assertEqual(pattern.tag, '#tag') pattern = TagPattern.parse(' tag +foo -xxx ') self.assertEqual(pattern.tag, '#tag') self.assertEqual({'foo'}, pattern.include_attributes) self.assertEqual({'xxx'}, pattern.exclude_attributes)
def test_attributes_wildcard(self): pattern = TagPattern.parse('*+foo') self.assertTrue(pattern.is_wildcard()) self.assertTrue(pattern.match(self.column)) pattern = TagPattern.parse('*-foo') self.assertTrue(pattern.is_wildcard()) self.assertFalse(pattern.match(self.column)) pattern = TagPattern.parse('*+xxx') self.assertTrue(pattern.is_wildcard()) self.assertFalse(pattern.match(self.column))
def test_wildcard_empty_column(self): pattern = TagPattern.parse('*') untagged_column = Column(header="Foo", column_number=1) self.assertFalse(pattern.match(untagged_column))
def test_simple_wildcard(self): pattern = TagPattern.parse('*') self.assertTrue(pattern.is_wildcard()) self.assertTrue(pattern.match(self.column))
def test_caseinsensitive(self): pattern = TagPattern.parse('#Tag') self.assertTrue(pattern.match(self.column)) pattern = TagPattern.parse('#tag+fOO') self.assertTrue(pattern.match(self.column))