Ejemplo n.º 1
0
    def testTests(self):
        suite = unittest.TestSuite()
        suffixes = reflect.prefixedMethodNames(TestTests.Tests, "test")
        for suffix in suffixes:
            method = "test" + suffix
            testCase = self.Tests()

            # if one of these test cases fails, switch to TextReporter to
            # see what happened

            rep = reporter.Reporter()
            #reporter = reporter.TextReporter()
            #print "running '%s'" % method

            rep.start(1)

            result = unittest.Tester(testCase.__class__, testCase,
                                     getattr(testCase, method),
                                     lambda x: x()).run()
            rep.reportResults(testCase.__class__, getattr(self.Tests, method),
                              *result)
            # TODO: verify that case.setUp == 1 and case.tearDown == 1
            try:
                self.checkResults(rep, method)
            except unittest.FailTest:
                # with TextReporter, this will show the traceback
                print
                print "problem in method '%s'" % method
                reporter.stop()
                raise
Ejemplo n.º 2
0
 def setupOptParameters(self):
     params = []
     if hasattr(self.options, 'optParameters'):
         params.extend(self.options.optParameters)
     d = {}
     soFar = {}
     for meth in reflect.prefixedMethodNames(self.options.__class__, 'opt_'):
         full = 'opt_' + meth
         func = getattr(self.options, full)
         if usage.flagFunction(func) or soFar.has_key(func):
             continue
         soFar[func] = 1
         existing = d.setdefault(func, meth)
         if existing != meth:
             if len(existing) < len(meth):
                 d[func] = meth
     for (func, name) in d.items():
         params.append((name, None, None, func.__doc__))
     if len(params):
         self.paramFrame = Tkinter.Frame(self)
         self.paramLines = []
         for (flag, _, default, desc) in params:
             try:
                 default = self.options[flag]
             except KeyError:
                 pass
             self.makeField(flag, default, desc)
         self.paramFrame.grid(row=1, column=2)
Ejemplo n.º 3
0
 def __init__(self, textView):
     self.textView=textView
     self.rkeymap = {}
     self.history = History()
     for name in prefixedMethodNames(self.__class__, "key_"):
         keysymName = name.split("_")[-1]
         self.rkeymap[getattr(gtk.keysyms, keysymName)] = keysymName
Ejemplo n.º 4
0
    def _get_provider_names(self):
        """
        Find the names of all supported "providers" (eg Vagrant, Rackspace).

        :return: A ``list`` of ``str`` giving all such names.
        """
        return prefixedMethodNames(self.__class__, "_runner_")
Ejemplo n.º 5
0
 def __init__(self, textView):
     self.textView = textView
     self.rkeymap = {}
     self.history = History()
     for name in prefixedMethodNames(self.__class__, "key_"):
         keysymName = name.split("_")[-1]
         self.rkeymap[getattr(gtk.keysyms, keysymName)] = keysymName
Ejemplo n.º 6
0
 def setupOptFlags(self):
     self.optFlags = []
     flags = []
     if hasattr(self.options, 'optFlags'):
         flags.extend(self.options.optFlags)
     d = {}
     soFar = {}
     for meth in reflect.prefixedMethodNames(self.options.__class__, 'opt_'):
         full = 'opt_' + meth
         func = getattr(self.options, full)
         if not usage.flagFunction(func) or meth in ('help', 'version'):
             continue
         if soFar.has_key(func):
             continue
         soFar[func] = 1
         existing = d.setdefault(func, meth)
         if existing != meth:
             if len(existing) < len(meth):
                 d[func] = meth
         for (func, name) in d.items():
             flags.append((name, None, func.__doc__))
         if len(flags):
             self.optFrame = f = Tkinter.Frame(self)
             for (flag, _, desc) in flags:
                 b = Tkinter.BooleanVar()
                 c = Tkinter.Checkbutton(f, text=desc, variable=b, wraplen=200)
                 c.pack(anchor=Tkinter.W)
                 self.optFlags.append((flag, b))
             f.grid(row=1, column=1)
Ejemplo n.º 7
0
Archivo: irc.py Proyecto: lhl/songclub
    def ctcpQuery_CLIENTINFO(self, user, channel, data):
        """A master index of what CTCP tags this client knows.

        If no arguments are provided, respond with a list of known tags.
        If an argument is provided, provide human-readable help on
        the usage of that tag.
        """

        nick = string.split(user,"!")[0]
        if not data:
            # XXX: prefixedMethodNames gets methods from my *class*,
            # but it's entirely possible that this *instance* has more
            # methods.
            names = reflect.prefixedMethodNames(self.__class__,
                                                'ctcpQuery_')

            self.ctcpMakeReply(nick, [('CLIENTINFO',
                                       string.join(names, ' '))])
        else:
            args = string.split(data)
            method = getattr(self, 'ctcpQuery_%s' % (args[0],), None)
            if not method:
                self.ctcpMakeReply(nick, [('ERRMSG',
                                           "CLIENTINFO %s :"
                                           "Unknown query '%s'"
                                           % (data, args[0]))])
                return
            doc = getattr(method, '__doc__', '')
            self.ctcpMakeReply(nick, [('CLIENTINFO', doc)])
Ejemplo n.º 8
0
    def _get_provider_names(self):
        """
        Find the names of all supported "providers" (eg Vagrant, Rackspace).

        :return: A ``list`` of ``str`` giving all such names.
        """
        return prefixedMethodNames(self.__class__, "_runner_")
Ejemplo n.º 9
0
    def listProcedures(self):
        """
        Return a list of the names of all xmlrpc procedures.

        @since: 11.1
        """
        return reflect.prefixedMethodNames(self.__class__, 'xmlrpc_')
Ejemplo n.º 10
0
    def ctcpQuery_CLIENTINFO(self, user, channel, data):
        """A master index of what CTCP tags this client knows.

        If no arguments are provided, respond with a list of known tags.
        If an argument is provided, provide human-readable help on
        the usage of that tag.
        """

        nick = string.split(user, "!")[0]
        if not data:
            # XXX: prefixedMethodNames gets methods from my *class*,
            # but it's entirely possible that this *instance* has more
            # methods.
            names = reflect.prefixedMethodNames(self.__class__, 'ctcpQuery_')

            self.ctcpMakeReply(nick, [('CLIENTINFO', string.join(names, ' '))])
        else:
            args = string.split(data)
            method = getattr(self, 'ctcpQuery_%s' % (args[0], ), None)
            if not method:
                self.ctcpMakeReply(nick,
                                   [('ERRMSG', "CLIENTINFO %s :"
                                     "Unknown query '%s'" % (data, args[0]))])
                return
            doc = getattr(method, '__doc__', '')
            self.ctcpMakeReply(nick, [('CLIENTINFO', doc)])
Ejemplo n.º 11
0
    def listProcedures(self):
        """
        Return a list of the names of all xmlrpc procedures.

        @since: 11.1
        """
        return reflect.prefixedMethodNames(self.__class__, "xmlrpc_")
Ejemplo n.º 12
0
    def setupOptParameters(self):
        params = []
        if hasattr(self.options, 'optParameters'):
            params.extend(self.options.optParameters)

        d = {}
        soFar = {}
        for meth in reflect.prefixedMethodNames(self.options.__class__,
                                                'opt_'):
            full = 'opt_' + meth
            func = getattr(self.options, full)

            if usage.flagFunction(func) or soFar.has_key(func):
                continue

            soFar[func] = 1

            existing = d.setdefault(func, meth)
            if existing != meth:
                if len(existing) < len(meth):
                    d[func] = meth
        for (func, name) in d.items():
            params.append((name, None, None, func.__doc__))

        if len(params):
            self.paramFrame = Tkinter.Frame(self)
            self.paramLines = []
            for (flag, _, default, desc) in params:
                try:
                    default = self.options[flag]
                except KeyError:
                    pass
                self.makeField(flag, default, desc)
            self.paramFrame.grid(row=1, column=2)
Ejemplo n.º 13
0
 def test_inheritedMethod(self):
     """
     L{prefixedMethodNames} returns a list included methods with the given
     prefix defined on base classes of the class passed to it.
     """
     class Child(Separate):
         pass
     self.assertEqual(["method"], prefixedMethodNames(Child, "good_"))
Ejemplo n.º 14
0
 def test_inheritedMethod(self):
     """
     L{prefixedMethodNames} returns a list included methods with the given
     prefix defined on base classes of the class passed to it.
     """
     class Child(Separate):
         pass
     self.assertEqual(["method"], prefixedMethodNames(Child, "good_"))
Ejemplo n.º 15
0
 def __init__(self, testClass):
     self.testClass = testClass
     self.methodNames = []
     for prefix in self.methodPrefixes:
         self.methodNames.extend([ "%s%s" % (prefix, name) for name in
                                   reflect.prefixedMethodNames(testClass, prefix)])
     # N.B.: --random will shuffle testClasses but not our methodNames[]
     self.methodNames.sort()
Ejemplo n.º 16
0
def _computeAllowedMethods(resource):
    """
    Compute the allowed methods on a C{Resource} based on defined render_FOO
    methods. Used when raising C{UnsupportedMethod} but C{Resource} does
    not define C{allowedMethods} attribute.
    """
    allowedMethods = []
    for name in prefixedMethodNames(resource.__class__, "render_"):
        allowedMethods.append(name)
    return allowedMethods
Ejemplo n.º 17
0
 def test_reverseKeymap(self):
     """
     Verify that a L{ConsoleInput} has a reverse mapping of the keysym names
     it needs for event handling to their corresponding keysym.
     """
     ci = ConsoleInput(None)
     for eventName in prefixedMethodNames(ConsoleInput, 'key_'):
         keysymName = eventName.split("_")[-1]
         keysymValue = getattr(gtk.keysyms, keysymName)
         self.assertEqual(ci.rkeymap[keysymValue], keysymName)
Ejemplo n.º 18
0
 def getButtonList(self, prefix='button_', container=None):
     result = []
     buttons = self.barButtons or \
               reflect.prefixedMethodNames(self.__class__, prefix)
     for b in buttons:
         bName = string.replace(b, '_', ' ')
         result.append(cbutton(bName, getattr(self,prefix+b)))
     if container:
         map(container.add, result)
     return result
Ejemplo n.º 19
0
def _computeAllowedMethods(resource):
    """
    Compute the allowed methods on a C{Resource} based on defined render_FOO
    methods. Used when raising C{UnsupportedMethod} but C{Resource} does
    not define C{allowedMethods} attribute.
    """
    allowedMethods = []
    for name in prefixedMethodNames(resource.__class__, "render_"):
        allowedMethods.append(name)
    return allowedMethods
Ejemplo n.º 20
0
 def getButtonList(self, prefix='button_', container=None):
     result = []
     buttons = self.barButtons or \
               reflect.prefixedMethodNames(self.__class__, prefix)
     for b in buttons:
         bName = string.replace(b, '_', ' ')
         result.append(cbutton(bName, getattr(self, prefix + b)))
     if container:
         map(container.add, result)
     return result
Ejemplo n.º 21
0
 def test_reverseKeymap(self):
     """
     Verify that a L{ConsoleInput} has a reverse mapping of the keysym names
     it needs for event handling to their corresponding keysym.
     """
     ci = ConsoleInput(None)
     for eventName in prefixedMethodNames(ConsoleInput, 'key_'):
         keysymName = eventName.split("_")[-1]
         keysymValue = getattr(gtk.keysyms, keysymName)
         self.assertEqual(ci.rkeymap[keysymValue], keysymName)
Ejemplo n.º 22
0
 def applyTo(self, item):
     headers = {}
     for hdr in item.impl.getAllHeaders():
         headers.setdefault(hdr.name, []).append(hdr.value)
     matchers = reflect.prefixedMethodNames(self.__class__, 'match_')
     for m in matchers:
         tag = getattr(self, 'match_' + m)(headers)
         if tag is not None:
             self.matchedMessages += 1
             assert type(tag) is unicode, "%r was not unicode, came from %r" % (tag, m)
             return True, True, {"mailingListName": tag}
     return False, True, None
Ejemplo n.º 23
0
def _computeAllowedMethods(resource):
    """
    Compute the allowed methods on a C{Resource} based on defined render_FOO
    methods. Used when raising C{UnsupportedMethod} but C{Resource} does
    not define C{allowedMethods} attribute.
    """
    allowedMethods = []
    for name in prefixedMethodNames(resource.__class__, "render_"):
        # Potentially there should be an API for encode('ascii') in this
        # situation - an API for taking a Python native string (bytes on Python
        # 2, text on Python 3) and returning a socket-compatible string type.
        allowedMethods.append(name.encode('ascii'))
    return allowedMethods
Ejemplo n.º 24
0
def _computeAllowedMethods(resource):
    """
    Compute the allowed methods on a C{Resource} based on defined render_FOO
    methods. Used when raising C{UnsupportedMethod} but C{Resource} does
    not define C{allowedMethods} attribute.
    """
    allowedMethods = []
    for name in prefixedMethodNames(resource.__class__, "render_"):
        # Potentially there should be an API for encode('ascii') in this
        # situation - an API for taking a Python native string (bytes on Python
        # 2, text on Python 3) and returning a socket-compatible string type.
        allowedMethods.append(name.encode("ascii"))
    return allowedMethods
Ejemplo n.º 25
0
 def do_EHLO(self, rest):
     extensions = reflect.prefixedMethodNames(self.__class__, 'ext_')
     peer = self.transport.getPeer()[1]
     self.__helo = (rest, peer)
     self.__from = None
     self.__to = []
     self.sendCode(
         250,
         '%s\n%s Hello %s, nice to meet you' % (
             '\n'.join([
                 '%s %s' % (e, ' '.join(self.extArgs.get(e, []))) for e in extensions
             ]),
             self.host, peer
         )
     )
Ejemplo n.º 26
0
 def _get_test_methods(self, item):
     """
     Look for test_ methods in subclasses of NetTestCase
     """
     test_cases = []
     try:
         assert issubclass(item, NetTestCase)
         methods = reflect.prefixedMethodNames(item, self.method_prefix)
         test_methods = []
         for method in methods:
             test_methods.append(self.method_prefix + method)
         if test_methods:
             test_cases.append((item, test_methods))
     except (TypeError, AssertionError):
         pass
     return test_cases
Ejemplo n.º 27
0
 def _get_test_methods(self, item):
     """
     Look for test_ methods in subclasses of NetTestCase
     """
     test_cases = []
     try:
         assert issubclass(item, NetTestCase)
         methods = reflect.prefixedMethodNames(item, self.method_prefix)
         test_methods = []
         for method in methods:
             test_methods.append(self.method_prefix + method)
         if test_methods:
             test_cases.append((item, test_methods))
     except (TypeError, AssertionError):
         pass
     return test_cases
Ejemplo n.º 28
0
def loadTestsAndOptions(classes, cmd_line_options):
    """
    Takes a list of test classes and returns their testcases and options.
    """
    method_prefix = 'test'
    options = None
    test_cases = []

    for klass in classes:
        tests = reflect.prefixedMethodNames(klass, method_prefix)
        if tests:
            test_cases = makeTestCases(klass, tests, method_prefix)

        test_klass = klass()
        options = test_klass._processOptions(cmd_line_options)

    return test_cases, options
Ejemplo n.º 29
0
def loadTestsAndOptions(classes, cmd_line_options):
    """
    Takes a list of test classes and returns their testcases and options.
    """
    method_prefix = 'test'
    options = None
    test_cases = []

    for klass in classes:
        tests = reflect.prefixedMethodNames(klass, method_prefix)
        if tests:
            test_cases = makeTestCases(klass, tests, method_prefix)

        test_klass = klass()
        options = test_klass._processOptions(cmd_line_options)

    return test_cases, options
Ejemplo n.º 30
0
 def _allowed_methods(self):
     """
     Compute allowable http methods to return in an Allowed-Methods header.
     This is to adhere to the HTTP standard.
     """
     allowed_methods = ['HEAD']  # we always allow head
     fq_name = self.__module__ + '.' + self.__class__.__name__
     name = '?'
     try:
         resource = self
         for n in prefixedMethodNames(resource.__class__, REST_METHOD_PREFIX):
             name = n
             allowed_methods.append(n.encode('ascii'))
     except UnicodeEncodeError:
         log.err('Resource (%s) method (%s) contains non-ascii characters' % (fq_name, name))
     except Exception as e:
         log.err('Resource (%s) error resolving method names (%s)' % (fq_name, e))
     return allowed_methods
Ejemplo n.º 31
0
    def setupOptFlags(self):
        self.optFlags = []
        flags = []
        if hasattr(self.options, 'optFlags'):
            flags.extend(self.options.optFlags)

        d = {}
        soFar = {}
        for meth in reflect.prefixedMethodNames(self.options.__class__,
                                                'opt_'):
            full = 'opt_' + meth
            func = getattr(self.options, full)

            if not usage.flagFunction(func) or meth in ('help', 'version'):
                continue

            if soFar.has_key(func):
                continue
            soFar[func] = 1

            existing = d.setdefault(func, meth)
            if existing != meth:
                if len(existing) < len(meth):
                    d[func] = meth

            for (func, name) in d.items():
                flags.append((name, None, func.__doc__))

            if len(flags):
                self.optFrame = f = Tkinter.Frame(self)
                for (flag, _, desc) in flags:
                    b = Tkinter.BooleanVar()
                    c = Tkinter.Checkbutton(f,
                                            text=desc,
                                            variable=b,
                                            wraplen=200)
                    c.pack(anchor=Tkinter.W)
                    self.optFlags.append((flag, b))
                f.grid(row=1, column=1)
Ejemplo n.º 32
0
    def decorator(test_case):
        test_method_names = [
            test_prefix + name
            for name in prefixedMethodNames(test_case, test_prefix)
        ]
        for test_method_name in test_method_names:
            if test_method_name not in supported_tests:
                test_method = getattr(test_case, test_method_name)
                new_message = []
                existing_message = getattr(test_method, skip_or_todo, None)
                if existing_message is not None:
                    new_message.append(existing_message)
                new_message.append('Not implemented yet')
                new_message = ' '.join(new_message)

                @wraps(test_method)
                def wrapper(*args, **kwargs):
                    return test_method(*args, **kwargs)

                setattr(wrapper, skip_or_todo, new_message)
                setattr(test_case, test_method_name, wrapper)

        return test_case
Ejemplo n.º 33
0
    def decorator(test_case):
        test_method_names = [
            test_prefix + name
            for name
            in prefixedMethodNames(test_case, test_prefix)
        ]
        for test_method_name in test_method_names:
            if test_method_name not in supported_tests:
                test_method = getattr(test_case, test_method_name)
                new_message = []
                existing_message = getattr(test_method, skip_or_todo, None)
                if existing_message is not None:
                    new_message.append(existing_message)
                new_message.append('Not implemented yet')
                new_message = ' '.join(new_message)

                @wraps(test_method)
                def wrapper(*args, **kwargs):
                    return test_method(*args, **kwargs)
                setattr(wrapper, skip_or_todo, new_message)
                setattr(test_case, test_method_name, wrapper)

        return test_case
Ejemplo n.º 34
0
def prefixedMethodClassDict(clazz, prefix):
    return {
        name: getattr(clazz, prefix + name)
        for name in prefixedMethodNames(clazz, prefix)
    }
Ejemplo n.º 35
0
 def test_method(self):
     """
     L{prefixedMethodNames} returns a list including methods with the given
     prefix defined on the class passed to it.
     """
     self.assertEqual(["method"], prefixedMethodNames(Separate, "good_"))
Ejemplo n.º 36
0
 def getTestCaseNames(self, klass):
     return reflect.prefixedMethodNames(klass, self.methodPrefix)
Ejemplo n.º 37
0
 def getTestCaseNames(self, klass):
     """
     Given a class that contains C{TestCase}s, return a list of names of
     methods that probably contain tests.
     """
     return reflect.prefixedMethodNames(klass, self.methodPrefix)
Ejemplo n.º 38
0
def prefixedMethodClassDict(clazz, prefix):
    return dict([(name, getattr(clazz, prefix + name)) for name in prefixedMethodNames(clazz, prefix)])
Ejemplo n.º 39
0
def prefixedMethodObjDict(obj, prefix):
    return {
        name: getattr(obj, prefix + name)
        for name in prefixedMethodNames(obj.__class__, prefix)
    }
Ejemplo n.º 40
0
 def _listFunctions(self):
     """Return a list of the names of all ebrpc methods."""
     return reflect.prefixedMethodNames(self.__class__, 'ebrpc_')
Ejemplo n.º 41
0
	def _listFunctions(self):
		return reflect.prefixedMethodNames(self.__class__, 'xmlrpc_')
Ejemplo n.º 42
0
 def _listFunctions(self):
     """
     Return a list of the names of all jsonrpc methods.
     """
     return reflect.prefixedMethodNames(self.__class__, 'jsonrpc_')
Ejemplo n.º 43
0
 def listFunctions(self):
     """
     Return a list of the names of all jsonrpc methods.
     """
     return reflect.prefixedMethodNames(self.__class__, self.prefix)
Ejemplo n.º 44
0
 def test_method(self):
     """
     L{prefixedMethodNames} returns a list including methods with the given
     prefix defined on the class passed to it.
     """
     self.assertEqual(["method"], prefixedMethodNames(Separate, "good_"))
Ejemplo n.º 45
0
 def getTestCaseNames(self, klass):
     return reflect.prefixedMethodNames(klass, self.methodPrefix)
Ejemplo n.º 46
0
def prefixedMethodObjDict(obj, prefix):
    return dict([(name, getattr(obj, prefix + name))
                 for name in prefixedMethodNames(obj.__class__, prefix)])
Ejemplo n.º 47
0
 def listProcedures(self):
     a = set(self._methods)
     b = set(reflect.prefixedMethodNames(self.__class__, 'dumbrpc_'))
     return sorted(a | b)
Ejemplo n.º 48
0
 def connectionMade(self):
     self.resultHarvester = ResultHarvester()
     for fn in reflect.prefixedMethodNames(self.__class__, 'decode_'):
         setattr(self, 'handle_' + fn, self.resultHarvester)
Ejemplo n.º 49
0
 def connectionMade(self):
     self.resultHarvester = ResultHarvester()
     for fn in reflect.prefixedMethodNames(self.__class__, 'decode_'):
         setattr(self, 'handle_' + fn, self.resultHarvester)
Ejemplo n.º 50
0
def prefixedMethodObjDict(obj, prefix):
    return dict([(name, getattr(obj, prefix + name)) for name in prefixedMethodNames(obj.__class__, prefix)])
Ejemplo n.º 51
0
 def getTestCaseNames(self, klass):
     """
     Given a class that contains C{TestCase}s, return a list of names of
     methods that probably contain tests.
     """
     return reflect.prefixedMethodNames(klass, self.methodPrefix)
Ejemplo n.º 52
0
def prefixedMethodClassDict(clazz, prefix):
    return dict([(name, getattr(clazz, prefix + name))
                 for name in prefixedMethodNames(clazz, prefix)])
Ejemplo n.º 53
0
 def listProcedures(self):
     a = set(self._methods)
     b = set(reflect.prefixedMethodNames(self.__class__, 'dumbrpc_'))
     return sorted(a | b)