Commits

Chris McDonough committed 553221c

add a __hash__ method to ActionPredicate so its phash will compare equal to one with the same action in bfg a12+

Comments (0)

Files changed (2)

pylons/configuration.py

 class ActionPredicate(object):
     action_name = 'action'
     def __init__(self, action):
+        self.action = action
         try:
             self.action_re = re.compile(action + '$')
         except (re.error, TypeError), why:
         if action is None:
             return False
         return bool(self.action_re.match(action))
+
+    def __hash__(self):
+        # allow this predicate's phash to be compared as equal to
+        # others that share the same action name
+        return hash(self.action)
         

tests/test_units/test_configuration.py

         request.matchdict = {'action':'myaction'}
         self.assertEqual(pred(None, request), True)
 
+    def test___hash__(self):
+        pred1 = self._makeOne()
+        pred2 = self._makeOne()
+        pred3 = self._makeOne(action='notthesame')
+        self.assertEqual(hash(pred1), hash(pred2))
+        self.assertNotEqual(hash(pred1), hash(pred3))
+        self.assertNotEqual(hash(pred2), hash(pred3))
+        
+        
+
 class Dummy(object):
     pass
             
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.