from nose2.plugins import attrib
from nose2 import session
from nose2.tests._common import TestCase


class TestAttribPlugin(TestCase):
    tags = ['unit']

    def setUp(self):
        class TC_1(TestCase):
            tags = ['a', 'b']
            def test_a(self):
                pass
            test_a.a = 1
            test_a.c = 0

            def test_b(self):
                pass
            test_b.b = 1
        self.TC_1 = TC_1
        self.plugin = attrib.AttributeSelector(session=session.Session())
        self.plugin.register()

    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')]])


@@ -1,16 +1,33 @@
+import unittest%0A%0A
 from nose2.plugi
@@ -60,16 +60,24 @@
 2 import
+ events,
  session
@@ -459,16 +459,57 @@
  = TC_1%0A
+        self.session = session.Session()%0A
         
@@ -557,31 +557,26 @@
 ssion=se
-ssion.S
+lf.s
 ession
-()
 )%0A      
@@ -2031,12 +2031,463 @@
 ', 'c')%5D%5D)%0A%0A
+    def test_start_test_run_filters_suite(self):%0A        self.plugin.attribs = %5B'a'%5D%0A        suite = unittest.TestSuite()%0A        suite.addTest(self.TC_1('test_a'))%0A        suite.addTest(self.TC_1('test_b'))%0A        event = events.StartTestRunEvent(None, suite, None, 1, None)%0A        self.session.hooks.startTestRun(event)%0A        self.assertEqual(len(event.suite._tests), 1)%0A        self.assertEqual(event.suite._tests%5B0%5D._testMethodName, 'test_a')%0A

Add unit test for startTestRun