~landscape/landscape-client/landscape-client-12.04-0ubuntu0.12.04.0

« back to all changes in this revision

Viewing changes to landscape/conftest.py

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Hasenack
  • Date: 2010-09-08 15:34:09 UTC
  • mfrom: (1.1.19 upstream)
  • Revision ID: james.westby@ubuntu.com-20100908153409-q9omqf75uv7n3s1w
Tags: 1.5.5-0ubuntu0.10.10.0
* New upstream version (LP: #633468)

  - The --help command line option can now be used without being
    root (LP: #613256).

  - The client Unix sockets and symlinks are now cleaned up at shutdown.
    Without this cleaning, the client could refuse to start because of a PID
    collision (LP: #607747).

  - The network traffic plugin didn't use to take into account integer
    overflows. This would cause the plugin to send negative values
    sometimes (LP: #615371).

  - If a payload had many user activities in it, only the last one would be
    carried out (LP: #617624).

  - The Eucalyptus plugin was not enabled by default, which means the Cloud
    Topology feature of Landscape was not available (LP: #614493).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Machinery to make py.test interpret standard unittest.TestCase classes."""
2
 
 
3
 
from unittest import TestCase, TestResult
4
 
import doctest
5
 
 
6
 
import py.test
7
 
 
8
 
 
9
 
class PyTestResult(TestResult):
10
 
 
11
 
    def addFailure(self, test, exc_info):
12
 
        traceback = exc_info[2]
13
 
        while traceback.tb_next:
14
 
            traceback = traceback.tb_next
15
 
        locals = traceback.tb_frame.f_locals
16
 
        if "msg" in locals or "excClass" in locals:
17
 
            locals["__tracebackhide__"] = True
18
 
        msg = str(exc_info[1])
19
 
        if not msg:
20
 
            if "expr" in locals and "msg" in locals:
21
 
                msg = repr(locals["expr"])
22
 
            else:
23
 
                msg = "!?"
24
 
        raise py.test.Item.Failed, py.test.Item.Failed(msg=msg), exc_info[2]
25
 
 
26
 
    addError = addFailure
27
 
 
28
 
 
29
 
class PyTestCase(TestCase):
30
 
 
31
 
    def __init__(self, methodName="setUp"):
32
 
        super(PyTestCase, self).__init__(methodName)
33
 
 
34
 
    class Function(py.test.Function):
35
 
 
36
 
        def execute(self, target, *args):
37
 
            __tracebackhide__ = True
38
 
            self = target.im_self
39
 
            self.__init__(target.__name__)
40
 
            self.run(PyTestResult())
41
 
 
42
 
 
43
 
class PyDocTest(py.test.collect.Module):
44
 
 
45
 
    def __init__(self, fspath, parent=None):
46
 
        super(PyDocTest, self).__init__(fspath.basename, parent)
47
 
        self.fspath = fspath
48
 
        self._obj = None
49
 
 
50
 
    def run(self):
51
 
        return [self.name]
52
 
 
53
 
    def join(self, name):
54
 
        return self.Function(name, parent=self, obj=self.fspath)
55
 
 
56
 
    class Function(py.test.Function):
57
 
 
58
 
        def getpathlineno(self):
59
 
            code = py.code.Code(self.failed)
60
 
            return code.path, code.firstlineno
61
 
 
62
 
        def failed(self, msg):
63
 
            raise self.Failed(msg)
64
 
 
65
 
        def execute(self, fspath):
66
 
            failures, total = doctest.testfile(str(fspath),
67
 
                                               module_relative=False,
68
 
                                               optionflags=doctest.ELLIPSIS)
69
 
            if failures:
70
 
                __tracebackhide__ = True
71
 
                self.failed("%d doctest cases" % failures)
72
 
 
73
 
 
74
 
class UnitTestModule(py.test.collect.Module):
75
 
 
76
 
    def buildname2items(self):
77
 
        d = {}
78
 
        for name in dir(self.obj):
79
 
            testclass = None
80
 
            obj = getattr(self.obj, name)
81
 
 
82
 
            try:
83
 
                if (obj is not TestCase and
84
 
                    issubclass(obj, (TestCase, PyTestCase))):
85
 
                    testclass = obj
86
 
            except TypeError:
87
 
                pass
88
 
 
89
 
            if testclass:
90
 
                d[name] = self.Class(name, parent=self)
91
 
                if not issubclass(testclass, PyTestCase):
92
 
                    queue = [testclass]
93
 
                    while queue:
94
 
                        testclass = queue.pop(0)
95
 
                        if TestCase in testclass.__bases__:
96
 
                            bases = list(testclass.__bases__)
97
 
                            bases[bases.index(TestCase)] = PyTestCase
98
 
                            testclass.__bases__ = tuple(bases)
99
 
                            break
100
 
                        queue.extend(testclass.__bases__)
101
 
        return d
102
 
 
103
 
 
104
 
class UnitTestDirectory(py.test.collect.Directory):
105
 
 
106
 
    def __init__(self, *args, **kwargs):
107
 
        if getattr(self.__class__, "__first_run__", True):
108
 
            self.__class__.__first_run__ = False
109
 
        super(UnitTestDirectory, self).__init__(*args, **kwargs)
110
 
 
111
 
    def filefilter(self, path):
112
 
        return path.check(fnmatch="*.py") and path.basename != "conftest.py"
113
 
 
114
 
    def makeitem(self, basename, filefilter=None, recfilter=None):
115
 
        path = self.fspath.join(basename)
116
 
        if path.check(fnmatch="*.txt"):
117
 
            return PyDocTest(path, parent=self)
118
 
        return super(UnitTestDirectory, self).makeitem(basename,
119
 
                                                       filefilter, recfilter)
120
 
 
121
 
 
122
 
Module = UnitTestModule
123
 
Directory = UnitTestDirectory