15e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) 25e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# 35e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# Redistribution and use in source and binary forms, with or without 45e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# modification, are permitted provided that the following conditions 55e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# are met: 65e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# 1. Redistributions of source code must retain the above copyright 75e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# notice, this list of conditions and the following disclaimer. 85e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# 2. Redistributions in binary form must reproduce the above copyright 95e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# notice, this list of conditions and the following disclaimer in the 105e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# documentation and/or other materials provided with the distribution. 115e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# 125e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 135e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 145e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 155e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 165e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 175e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 185e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 195e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 205e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 215e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 225e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 235e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block"""Unit tests for filter.py.""" 245e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 255e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockimport unittest 265e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 278a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Blockfrom filter import _CategoryFilter as CategoryFilter 288a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Blockfrom filter import validate_filter_rules 298a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Blockfrom filter import FilterConfiguration 308a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 318a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# On Testing __eq__() and __ne__(): 328a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# 338a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# In the tests below, we deliberately do not use assertEquals() or 348a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# assertNotEquals() to test __eq__() or __ne__(). We do this to be 358a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# very explicit about what we are testing, especially in the case 368a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# of assertNotEquals(). 378a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# 388a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# Part of the reason is that it is not immediately clear what 398a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# expression the unittest module uses to assert "not equals" -- the 408a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# negation of __eq__() or __ne__(), which are not necessarily 418a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# equivalent expresions in Python. For example, from Python's "Data 428a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# Model" documentation-- 438a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# 448a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# "There are no implied relationships among the comparison 458a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# operators. The truth of x==y does not imply that x!=y is 468a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# false. Accordingly, when defining __eq__(), one should 478a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# also define __ne__() so that the operators will behave as 488a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# expected." 498a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# 508a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block# (from http://docs.python.org/reference/datamodel.html#object.__ne__ ) 518a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 528a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Blockclass ValidateFilterRulesTest(unittest.TestCase): 538a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 548a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block """Tests validate_filter_rules() function.""" 558a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 568a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block def test_validate_filter_rules(self): 578a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block all_categories = ["tabs", "whitespace", "build/include"] 588a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 598a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block bad_rules = [ 608a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block "tabs", 618a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block "*tabs", 628a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block " tabs", 638a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block " +tabs", 648a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block "+whitespace/newline", 658a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block "+xxx", 668a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block ] 678a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 688a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block good_rules = [ 698a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block "+tabs", 708a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block "-tabs", 718a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block "+build" 728a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block ] 738a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 748a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block for rule in bad_rules: 758a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertRaises(ValueError, validate_filter_rules, 768a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block [rule], all_categories) 778a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 788a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block for rule in good_rules: 798a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # This works: no error. 808a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block validate_filter_rules([rule], all_categories) 815e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 825e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 835e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Blockclass CategoryFilterTest(unittest.TestCase): 845e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 855e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block """Tests CategoryFilter class.""" 865e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 875e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block def test_init(self): 888a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block """Test __init__ method.""" 898a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # Test that the attributes are getting set correctly. 908a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block filter = CategoryFilter(["+"]) 918a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertEquals(["+"], filter._filter_rules) 928a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 938a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block def test_init_default_arguments(self): 948a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block """Test __init__ method default arguments.""" 958a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block filter = CategoryFilter() 968a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertEquals([], filter._filter_rules) 975e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 985e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block def test_str(self): 995e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block """Test __str__ "to string" operator.""" 1005e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block filter = CategoryFilter(["+a", "-b"]) 1015e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block self.assertEquals(str(filter), "+a,-b") 1025e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 1035e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block def test_eq(self): 1045e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block """Test __eq__ equality function.""" 1055e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block filter1 = CategoryFilter(["+a", "+b"]) 1065e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block filter2 = CategoryFilter(["+a", "+b"]) 1075e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block filter3 = CategoryFilter(["+b", "+a"]) 1085e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 1098a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # See the notes at the top of this module about testing 1108a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # __eq__() and __ne__(). 1118a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertTrue(filter1.__eq__(filter2)) 1128a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertFalse(filter1.__eq__(filter3)) 1135e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 1145e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block def test_ne(self): 1155e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block """Test __ne__ inequality function.""" 1165e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block # By default, __ne__ always returns true on different objects. 1175e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block # Thus, just check the distinguishing case to verify that the 1185e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block # code defines __ne__. 1198a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # 1208a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # Also, see the notes at the top of this module about testing 1218a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # __eq__() and __ne__(). 1228a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertFalse(CategoryFilter().__ne__(CategoryFilter())) 1235e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 1245e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block def test_should_check(self): 1255e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block """Test should_check() method.""" 1265e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block filter = CategoryFilter() 1275e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block self.assertTrue(filter.should_check("everything")) 1285e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block # Check a second time to exercise cache. 1295e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block self.assertTrue(filter.should_check("everything")) 1305e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 1315e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block filter = CategoryFilter(["-"]) 1325e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block self.assertFalse(filter.should_check("anything")) 1335e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block # Check a second time to exercise cache. 1345e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block self.assertFalse(filter.should_check("anything")) 1355e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 1365e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block filter = CategoryFilter(["-", "+ab"]) 1375e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block self.assertTrue(filter.should_check("abc")) 1385e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block self.assertFalse(filter.should_check("a")) 1395e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 1405e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block filter = CategoryFilter(["+", "-ab"]) 1415e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block self.assertFalse(filter.should_check("abc")) 1425e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block self.assertTrue(filter.should_check("a")) 1435e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block 1448a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1458a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Blockclass FilterConfigurationTest(unittest.TestCase): 1468a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1478a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block """Tests FilterConfiguration class.""" 1488a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1498a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block def _config(self, base_rules, path_specific, user_rules): 1508a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block """Return a FilterConfiguration instance.""" 1518a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block return FilterConfiguration(base_rules=base_rules, 1528a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block path_specific=path_specific, 1538a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block user_rules=user_rules) 1548a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1558a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block def test_init(self): 1568a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block """Test __init__ method.""" 1578a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # Test that the attributes are getting set correctly. 1588a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # We use parameter values that are different from the defaults. 1598a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block base_rules = ["-"] 160692e5dbf12901edacf14812a6fae25462920af42Steve Block path_specific = [(["path"], ["+a"])] 1618a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block user_rules = ["+"] 1628a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1638a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block config = self._config(base_rules, path_specific, user_rules) 1648a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1658a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertEquals(base_rules, config._base_rules) 1668a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertEquals(path_specific, config._path_specific) 167692e5dbf12901edacf14812a6fae25462920af42Steve Block self.assertEquals(user_rules, config._user_rules) 1688a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1698a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block def test_default_arguments(self): 1708a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # Test that the attributes are getting set correctly to the defaults. 1718a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block config = FilterConfiguration() 1728a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1738a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertEquals([], config._base_rules) 1748a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertEquals([], config._path_specific) 175692e5dbf12901edacf14812a6fae25462920af42Steve Block self.assertEquals([], config._user_rules) 1768a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1778a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block def test_eq(self): 1788a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block """Test __eq__ method.""" 1798a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # See the notes at the top of this module about testing 1808a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # __eq__() and __ne__(). 1818a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertTrue(FilterConfiguration().__eq__(FilterConfiguration())) 1828a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1838a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # Verify that a difference in any argument causes equality to fail. 1848a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block config = FilterConfiguration() 1858a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1868a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # These parameter values are different from the defaults. 1878a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block base_rules = ["-"] 188692e5dbf12901edacf14812a6fae25462920af42Steve Block path_specific = [(["path"], ["+a"])] 1898a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block user_rules = ["+"] 1908a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1918a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertFalse(config.__eq__(FilterConfiguration( 1928a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block base_rules=base_rules))) 1938a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertFalse(config.__eq__(FilterConfiguration( 1948a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block path_specific=path_specific))) 1958a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertFalse(config.__eq__(FilterConfiguration( 1968a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block user_rules=user_rules))) 1978a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 1988a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block def test_ne(self): 1998a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block """Test __ne__ method.""" 2008a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # By default, __ne__ always returns true on different objects. 2018a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # Thus, just check the distinguishing case to verify that the 2028a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # code defines __ne__. 2038a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # 2048a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # Also, see the notes at the top of this module about testing 2058a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # __eq__() and __ne__(). 2068a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertFalse(FilterConfiguration().__ne__(FilterConfiguration())) 2078a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 2088a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block def test_base_rules(self): 2098a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block """Test effect of base_rules on should_check().""" 2108a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block base_rules = ["-b"] 2118a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block path_specific = [] 2128a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block user_rules = [] 2138a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 2148a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block config = self._config(base_rules, path_specific, user_rules) 2158a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 2168a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertTrue(config.should_check("a", "path")) 2178a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertFalse(config.should_check("b", "path")) 2188a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 2198a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block def test_path_specific(self): 2208a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block """Test effect of path_rules_specifier on should_check().""" 2218a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block base_rules = ["-"] 222692e5dbf12901edacf14812a6fae25462920af42Steve Block path_specific = [(["path1"], ["+b"]), 223692e5dbf12901edacf14812a6fae25462920af42Steve Block (["path2"], ["+c"])] 2248a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block user_rules = [] 2258a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 2268a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block config = self._config(base_rules, path_specific, user_rules) 2278a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 2288a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertFalse(config.should_check("c", "path1")) 2298a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertTrue(config.should_check("c", "path2")) 2308a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # Test that first match takes precedence. 2318a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertFalse(config.should_check("c", "path2/path1")) 2328a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 2338a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block def test_path_with_different_case(self): 2348a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block """Test a path that differs only in case.""" 2358a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block base_rules = ["-"] 236692e5dbf12901edacf14812a6fae25462920af42Steve Block path_specific = [(["Foo/"], ["+whitespace"])] 2378a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block user_rules = [] 2388a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 2398a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block config = self._config(base_rules, path_specific, user_rules) 2408a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 2418a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertFalse(config.should_check("whitespace", "Fooo/bar.txt")) 2428a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertTrue(config.should_check("whitespace", "Foo/bar.txt")) 2438a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block # Test different case. 2448a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertTrue(config.should_check("whitespace", "FOO/bar.txt")) 2458a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 2468a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block def test_user_rules(self): 2478a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block """Test effect of user_rules on should_check().""" 2488a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block base_rules = ["-"] 2498a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block path_specific = [] 2508a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block user_rules = ["+b"] 2518a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 2528a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block config = self._config(base_rules, path_specific, user_rules) 2538a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 2548a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertFalse(config.should_check("a", "path")) 2558a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block self.assertTrue(config.should_check("b", "path")) 2568a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block 257