1 # 2 # Copyright (C) 2015 The Android Open Source Project 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 # 16 import unittest 17 18 from filters import TestFilter 19 20 21 class FilterTest(unittest.TestCase): 22 def test_filters(self): 23 filters = TestFilter.from_string('foo,ba*') 24 self.assertTrue(filters.filter('foo')) 25 self.assertTrue(filters.filter('bar')) 26 self.assertTrue(filters.filter('baz')) 27 self.assertFalse(filters.filter('qux')) 28 29 filters.add_filter('woodly.*') 30 filters.add_filter('doodly.b*') 31 filters.add_filter('qu*.b*') 32 33 self.assertTrue(filters.filter('foo')) 34 self.assertTrue(filters.filter('foo.bar')) 35 36 self.assertTrue(filters.filter('woodly.bar')) 37 self.assertFalse(filters.filter('woo.bar')) 38 39 self.assertTrue(filters.filter('doodly')) 40 self.assertTrue(filters.filter('doodly.baz')) 41 self.assertFalse(filters.filter('doodly.qux')) 42 43 self.assertTrue(filters.filter('qux')) 44 self.assertTrue(filters.filter('quux')) 45 self.assertTrue(filters.filter('qux.bar')) 46 self.assertTrue(filters.filter('quux.bar')) 47 self.assertFalse(filters.filter('qux.foo')) 48 self.assertFalse(filters.filter('qx.bar')) 49 50 def test_empty_filters(self): 51 filters = TestFilter.from_string('') 52 self.assertTrue(filters.filter('foo')) 53 self.assertTrue(filters.filter('foo.bar')) 54