~raj-abhilash1/mailman/bugfix

« back to all changes in this revision

Viewing changes to src/mailman/testing/nose.py

  • Committer: Barry Warsaw
  • Date: 2013-08-25 18:55:33 UTC
  • mto: This revision was merged to the branch mainline in revision 7216.
  • Revision ID: barry@list.org-20130825185533-zpc5isnbx71zgn37
Switch to virtualenv and nose2 instead of zc.buildout and zope.testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2013 by the Free Software Foundation, Inc.
 
2
#
 
3
# This file is part of GNU Mailman.
 
4
#
 
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
 
6
# the terms of the GNU General Public License as published by the Free
 
7
# Software Foundation, either version 3 of the License, or (at your option)
 
8
# any later version.
 
9
#
 
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
 
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
13
# more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License along with
 
16
# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
"""nose2 test infrastructure."""
 
19
 
 
20
from __future__ import absolute_import, print_function, unicode_literals
 
21
 
 
22
__metaclass__ = type
 
23
__all__ = [
 
24
    'NosePlugin',
 
25
    ]
 
26
 
 
27
 
 
28
import os
 
29
import re
 
30
import mailman
 
31
 
 
32
from mailman.testing.layers import ConfigLayer, MockAndMonkeyLayer
 
33
from nose2.events import Plugin
 
34
 
 
35
 
 
36
TOPDIR = os.path.dirname(mailman.__file__)
 
37
 
 
38
 
 
39
class NosePlugin(Plugin):
 
40
    configSection = 'mailman'
 
41
 
 
42
    def __init__(self):
 
43
        self.patterns = []
 
44
        self.addArgument(self.patterns, 'P', 'pattern',
 
45
                         'Add a test matching pattern')
 
46
 
 
47
    def startTestRun(self, event):
 
48
        MockAndMonkeyLayer.testing_mode = True
 
49
        ConfigLayer.enable_stderr()
 
50
 
 
51
    def getTestCaseNames(self, event):
 
52
        if len(self.patterns) == 0:
 
53
            # No filter patterns, so everything should be tested.
 
54
            return
 
55
        names = filter(event.isTestMethod, dir(event.testCase))
 
56
        for name in names:
 
57
            for pattern in self.patterns:
 
58
                if re.search(pattern, name):
 
59
                    break
 
60
            else:
 
61
                event.excludedNames.append(name)