def test_eval_attr(self): if not compat_24: warn("No support for eval attributes in python versions older" " than 2.4") return def f(): pass f.monkey = 2 def g(): pass g.monkey = 6 def h(): pass h.monkey = 5 cnf = Config() opt = Bucket() opt.eval_attr = "monkey > 5" plug = AttributeSelector() plug.configure(opt, cnf) assert not plug.wantFunction(f) assert plug.wantFunction(g) is not False assert not plug.wantFunction(h)
def run_test(): nose.main(addplugins=[ AutotestClientTestRunner(), AttributeSelector(), Xunit(), Coverage() ])
def test_add_options(self): plug = AttributeSelector() parser = MockOptParser() plug.add_options(parser) expect = [(('-a', '--attr'), { 'dest': 'attr', 'action': 'append', 'default': None, 'metavar': 'ATTR', 'help': 'Run only tests that have attributes ' 'specified by ATTR [NOSE_ATTR]' })] if compat_24: expect.append((('-A', '--eval-attr'), { 'dest': 'eval_attr', 'action': 'append', 'default': None, 'metavar': 'EXPR', 'help': 'Run only tests for whose attributes the ' 'Python expression EXPR evaluates to True ' '[NOSE_EVAL_ATTR]' })) self.assertEqual(parser.opts, expect) opt = Bucket() opt.attr = ['!slow'] plug.configure(opt, Config()) assert plug.enabled self.assertEqual(plug.attribs, [[('slow', False)]]) opt.attr = ['fast,quick', 'weird=66'] plug.configure(opt, Config()) self.assertEqual(plug.attribs, [[('fast', True), ('quick', True)], [('weird', '66')]]) # don't die on trailing , opt.attr = ['something,'] plug.configure(opt, Config()) self.assertEqual(plug.attribs, [[('something', True)]]) if compat_24: opt.attr = None opt.eval_attr = ['weird >= 66'] plug.configure(opt, Config()) self.assertEqual(plug.attribs[0][0][0], 'weird >= 66') assert isinstance(plug.attribs[0][0][1], collections.Callable)
def __init__(self): """Initialise the helper plugin.""" # Nose has attrib plugin which works as expected but isn't passed the # tests generated from features. Create a local copy which will be used # to veto the tests. super().__init__() self.attrib_plugin = AttributeSelector()
def test_basic_attr(self): def f(): pass f.a = 1 def g(): pass plug = AttributeSelector() plug.attribs = [[('a', True)]] assert plug.wantFunction(f) is not False assert not plug.wantFunction(g)
def test_class_attr(self): class TestP: foo = True def h(): pass def i(): pass plug = AttributeSelector() plug.attribs = [[('foo', True)]] assert plug.wantMethod(unbound_method(TestP, TestP.h)) is not False assert plug.wantFunction(i) is False
def configure(self, options, noseconfig): super(ITE, self).configure(options, noseconfig) if not self.enabled: return self.curdir = os.getcwd() noseconfig.testMatch = re.compile('$^') self.attr_plugin = AttributeSelector() self.attr_plugin.configure(noseconfig.options, noseconfig) if os.getuid() == 0: os.setegid(self.options.gid) os.seteuid(self.options.uid)
def test_attr_a_b(self): def f1(): pass f1.tags = ['a', 'b'] def f2(): pass f2.tags = ['a', 'c'] def f3(): pass f3.tags = ['b', 'c'] def f4(): pass f4.tags = ['c', 'd'] cnf = Config() parser = OptionParser() plug = AttributeSelector() plug.add_options(parser) # OR opt, args = parser.parse_args(['test', '-a', 'tags=a', '-a', 'tags=b']) print opt plug.configure(opt, cnf) assert plug.wantFunction(f1) is None assert plug.wantFunction(f2) is None assert plug.wantFunction(f3) is None assert not plug.wantFunction(f4) # AND opt, args = parser.parse_args(['test', '-a', 'tags=a,tags=b']) print opt plug.configure(opt, cnf) assert plug.wantFunction(f1) is None assert not plug.wantFunction(f2) assert not plug.wantFunction(f3) assert not plug.wantFunction(f4)
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 TestAttributeArrayAnd(PluginTester, unittest.TestCase): activate = "-a d=1,d=2" args = ['-v'] plugins = [AttributeSelector()] suitepath = os.path.join(support, 'att') def runTest(self): print '*' * 70 print str(self.output) print '*' * 70 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
def selector(self): if self._selector is None: self._selector = AttributeSelector() return self._selector