Anonymous avatar Anonymous committed 98e49b2

Updated attrib plugin, added a few more tests

Comments (0)

Files changed (2)

nose2/plugins/attrib.py

             for key, value in group:
                 obj_value = self.getAttr(test, key)
                 if callable(value):
-                    if not value(key, test_attribs):
+                    if not value(key, test):
                         match = False
                         break
                 elif value is True:

nose2/tests/test_attrib_plugin.py

 
     def setUp(self):
         class TC_1(unittest2.TestCase):
-            tags = ['a, b']
+            tags = ['a', 'b']
             def test_a(self):
                 pass
             test_a.a = 1
+            test_a.c = 0
 
             def test_b(self):
                 pass
         self.TC_1 = TC_1
         self.plugin = attrib.AttributeSelector()
 
-    def test_validate_attribs(self):
+    def test_validate_attribs_with_simple_values(self):
         assert self.plugin.validateAttrib(
             self.TC_1('test_a'), [[('a', '1')]])
+        assert self.plugin.validateAttrib(
+            self.TC_1('test_a'), [[('a', True)]])
+        assert self.plugin.validateAttrib(
+            self.TC_1('test_a'), [[('c', False)]])
+        assert self.plugin.validateAttrib(
+            self.TC_1('test_b'), [[('b', '1')]])
+        assert not self.plugin.validateAttrib(
+            self.TC_1('test_a'), [[('a', False)]])
+        assert not self.plugin.validateAttrib(
+            self.TC_1('test_a'), [[('c', True)]])
+        assert not self.plugin.validateAttrib(
+            self.TC_1('test_a'), [[('a', '2')]])
         assert not self.plugin.validateAttrib(
             self.TC_1('test_a'), [[('b', '1')]])
 
+    def test_validate_attribs_with_callable(self):
+        assert self.plugin.validateAttrib(
+            self.TC_1('test_a'), [[('a', lambda key, test: True)]])
+        assert not self.plugin.validateAttrib(
+            self.TC_1('test_a'), [[('a', lambda key, test: False)]])
+
+    def test_validate_attribs_against_list(self):
+        assert self.plugin.validateAttrib(
+            self.TC_1('test_a'), [[('tags', 'a')]])
+        assert self.plugin.validateAttrib(
+            self.TC_1('test_a'), [[('tags', 'b')]])
+        assert not self.plugin.validateAttrib(
+            self.TC_1('test_a'), [[('tags', 'c')]])
+
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.