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)
Пример #2
0
    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 callable(plug.attribs[0][0][1])
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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 callable(plug.attribs[0][0][1])
Пример #6
0
    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)