1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
import os
import sys
import unittest
from nose.plugins.attrib import AttributeSelector
from nose.plugins import PluginTester
support = os.path.join(os.path.dirname(__file__), 'support')
compat_24 = sys.version_info >= (2, 4)
class AttributePluginTester(PluginTester, unittest.TestCase):
plugins = [AttributeSelector()]
suitepath = os.path.join(support, 'att')
# Some cases need -a to activate and others need -A, so
# let's treat -v as the activate argument and let individual
# cases specify their -a arguments as part of args
activate = '-v'
def runTest(self):
print '*' * 70
print str(self.output)
print '*' * 70
self.verify()
def verify(self):
raise NotImplementedError()
class TestSimpleAttribute(AttributePluginTester):
args = ["-a", "a"]
def verify(self):
assert 'test_attr.test_one ... ok' in self.output
assert 'test_attr.test_two ... ok' in self.output
assert 'TestClass.test_class_one ... ok' in self.output
assert 'TestClass.test_class_two ... ok' in self.output
assert 'TestClass.test_class_three ... ok' in self.output
assert 'test_three' not in self.output
assert 'test_case_two' not in self.output
assert 'test_case_one' not in self.output
assert 'test_case_three' not in self.output
assert 'TestAttrClass.test_one ... ok' in self.output
assert 'TestAttrClass.test_two ... ok' in self.output
assert 'TestAttrClass.ends_with_test ... ok' in self.output
class TestNotSimpleAttribute(AttributePluginTester):
args = ["-a", "!a"]
def verify(self):
assert 'test_attr.test_one ... ok' not in self.output
assert 'test_attr.test_two ... ok' not in self.output
assert 'TestClass.test_class_one ... ok' not in self.output
assert 'TestClass.test_class_two ... ok' not in self.output
assert 'TestClass.test_class_three ... ok' not in self.output
assert 'test_three' in self.output
assert 'test_case_two' in self.output
assert 'test_case_one' in self.output
assert 'test_case_three' in self.output
class TestAttributeValue(AttributePluginTester):
args = ["-a", "b=2"]
def verify(self):
assert 'test_attr.test_one ... ok' not in self.output
assert 'test_attr.test_two ... ok' not in self.output
assert 'test_attr.test_three ... ok' not in self.output
assert 'TestClass.test_class_one ... ok' not in self.output
assert 'TestClass.test_class_two ... ok' in self.output
assert 'TestClass.test_class_three ... ok' not in self.output
assert 'test_case_two' in self.output
assert 'test_case_one' in self.output
assert 'test_case_three' in self.output
class TestAttributeArray(AttributePluginTester):
args = ["-a", "d=2"]
def verify(self):
assert 'test_attr.test_one ... ok' in self.output
assert 'test_attr.test_two ... ok' in self.output
assert 'test_attr.test_three ... ok' not in self.output
assert 'TestClass.test_class_one ... ok' not in self.output
assert 'TestClass.test_class_two ... ok' not in self.output
assert 'TestClass.test_class_three ... ok' not in self.output
assert 'test_case_two' not in self.output
assert 'test_case_one' not in self.output
assert 'test_case_three' not in self.output
class TestAttributeArrayAnd(AttributePluginTester):
args = ["-a", "d=1,d=2"]
def verify(self):
assert 'test_attr.test_one ... ok' in self.output
assert 'test_attr.test_two ... ok' not in self.output
assert 'test_attr.test_three ... ok' not in self.output
assert 'TestClass.test_class_one ... ok' not in self.output
assert 'TestClass.test_class_two ... ok' not in self.output
assert 'TestClass.test_class_three ... ok' not in self.output
assert 'test_case_two' not in self.output
assert 'test_case_one' not in self.output
assert 'test_case_three' not in self.output
class TestAttributeArrayOr(AttributePluginTester):
args = ["-a", "d=1", "-a", "d=2"]
def verify(self):
assert 'test_attr.test_one ... ok' in self.output
assert 'test_attr.test_two ... ok' in self.output
assert 'test_attr.test_three ... ok' in self.output
assert 'TestClass.test_class_one ... ok' not in self.output
assert 'TestClass.test_class_two ... ok' not in self.output
assert 'TestClass.test_class_three ... ok' not in self.output
assert 'test_case_two' not in self.output
assert 'test_case_one' not in self.output
assert 'test_case_three' not in self.output
class TestInheritance(AttributePluginTester):
# Issue #412
args = ["-a", "from_super"]
def verify(self):
assert 'TestSubclass.test_method ... ok' in self.output
assert 'TestAttrSubClass.test_sub_three ... ok' in self.output
assert 'TestAttrSubClass.test_one ... ok' in self.output
assert 'TestAttrSubClass.added_later_test ... ok' in self.output
assert 'test_two' not in self.output
assert 'test_case_one' not in self.output
assert 'test_case_three' not in self.output
class TestStatic(AttributePluginTester):
# Issue #411
args = ["-a", "with_static"]
suitepath = os.path.join(support, 'att', 'test_attr.py:Static')
def verify(self):
assert 'Static.test_with_static ... ok' in self.output
assert 'test_case_two' not in self.output
assert 'test_case_one' not in self.output
assert 'test_case_three' not in self.output
class TestClassAndMethodAttrs(AttributePluginTester):
# Issue #324
args = ["-a", "meth_attr=method,cls_attr=class"]
def verify(self):
assert '(test_attr.TestClassAndMethodAttrs' in self.output
assert 'test_case_two' not in self.output
assert 'test_case_one' not in self.output
assert 'test_case_three' not in self.output
# Issue #771
class TestTopLevelNotSelected(AttributePluginTester):
suitepath = os.path.join(support, 'issue771')
args = ["-a", "!a"]
def verify(self):
# Note: a failure here may mean that the test case selection is broken
# rather than the attribute plugin, but the issue more easily manifests
# itself when using attributes.
assert 'test.test_b ... ok' in self.output
assert 'test_a (test.TestBase' in self.output
assert 'TestDerived' not in self.output
# Issue #728
class TestStaticMethod(AttributePluginTester):
suitepath = os.path.join(support, 'attrib-static')
args = ["-a", "!slow"]
def verify(self):
assert 'test.TestAttrib.test_static ... ok' in self.output
assert 'Ran 1 test' in self.output
if compat_24:
class TestAttributeEval(AttributePluginTester):
args = ["-A", "c>20"]
def verify(self):
assert 'test_attr.test_one ... ok' not in self.output
assert 'test_attr.test_two ... ok' not in self.output
assert 'test_attr.test_three ... ok' not in self.output
assert 'TestClass.test_class_one ... ok' not in self.output
assert 'TestClass.test_class_two ... ok' not in self.output
assert 'TestClass.test_class_three ... ok' not in self.output
assert 'test_case_two' in self.output
assert 'test_case_one' not in self.output
assert 'test_case_three' not in self.output
# Avoid trying to run base class as tests
del AttributePluginTester
if __name__ == '__main__':
#import logging
#logging.basicConfig(level=logging.DEBUG)
unittest.main()
|