Show More
@@ -1,71 +1,76 b'' | |||
|
1 | 1 | """Monkeypatch nose to accept any callable as a method. |
|
2 | 2 | |
|
3 | 3 | By default, nose's ismethod() fails for static methods. |
|
4 | 4 | Once this is fixed in upstream nose we can disable it. |
|
5 | 5 | |
|
6 | Note: merely importing this module causes the monkeypatch to be applied.""" | |
|
6 | Notes: | |
|
7 | ||
|
8 | - As of Nose 1.0.0, the problem persists so this monkeypatch is still | |
|
9 | needed. | |
|
10 | ||
|
11 | - Merely importing this module causes the monkeypatch to be applied.""" | |
|
7 | 12 | |
|
8 | 13 | #----------------------------------------------------------------------------- |
|
9 | 14 | # Copyright (C) 2009-2011 The IPython Development Team |
|
10 | 15 | # |
|
11 | 16 | # Distributed under the terms of the BSD License. The full license is in |
|
12 | 17 | # the file COPYING, distributed as part of this software. |
|
13 | 18 | #----------------------------------------------------------------------------- |
|
14 | 19 | |
|
15 | 20 | #----------------------------------------------------------------------------- |
|
16 | 21 | # Imports |
|
17 | 22 | #----------------------------------------------------------------------------- |
|
18 | 23 | |
|
19 | 24 | import unittest |
|
20 | 25 | import sys |
|
21 | 26 | import nose.loader |
|
22 | 27 | from inspect import ismethod, isfunction |
|
23 | 28 | |
|
24 | 29 | #----------------------------------------------------------------------------- |
|
25 | 30 | # Classes and functions |
|
26 | 31 | #----------------------------------------------------------------------------- |
|
27 | 32 | |
|
28 | 33 | def getTestCaseNames(self, testCaseClass): |
|
29 | 34 | """Override to select with selector, unless |
|
30 | 35 | config.getTestCaseNamesCompat is True |
|
31 | 36 | """ |
|
32 | 37 | if self.config.getTestCaseNamesCompat: |
|
33 | 38 | return unittest.TestLoader.getTestCaseNames(self, testCaseClass) |
|
34 | 39 | |
|
35 | 40 | def wanted(attr, cls=testCaseClass, sel=self.selector): |
|
36 | 41 | item = getattr(cls, attr, None) |
|
37 | 42 | # MONKEYPATCH: replace this: |
|
38 | 43 | #if not ismethod(item): |
|
39 | 44 | # return False |
|
40 | 45 | # return sel.wantMethod(item) |
|
41 | 46 | # With: |
|
42 | 47 | if ismethod(item): |
|
43 | 48 | return sel.wantMethod(item) |
|
44 | 49 | # static method or something. If this is a static method, we |
|
45 | 50 | # can't get the class information, and we have to treat it |
|
46 | 51 | # as a function. Thus, we will miss things like class |
|
47 | 52 | # attributes for test selection |
|
48 | 53 | if isfunction(item): |
|
49 | 54 | return sel.wantFunction(item) |
|
50 | 55 | return False |
|
51 | 56 | # END MONKEYPATCH |
|
52 | 57 | |
|
53 | 58 | cases = filter(wanted, dir(testCaseClass)) |
|
54 | 59 | for base in testCaseClass.__bases__: |
|
55 | 60 | for case in self.getTestCaseNames(base): |
|
56 | 61 | if case not in cases: |
|
57 | 62 | cases.append(case) |
|
58 | 63 | # add runTest if nothing else picked |
|
59 | 64 | if not cases and hasattr(testCaseClass, 'runTest'): |
|
60 | 65 | cases = ['runTest'] |
|
61 | 66 | if self.sortTestMethodsUsing: |
|
62 | 67 | cases.sort(self.sortTestMethodsUsing) |
|
63 | 68 | return cases |
|
64 | 69 | |
|
65 | 70 | |
|
66 | 71 | ########################################################################## |
|
67 | 72 | # Apply monkeypatch here |
|
68 | 73 | # Python 3 must be running with newer version of Nose, so don't touch anything. |
|
69 | 74 | if sys.version_info[0] < 3: |
|
70 | 75 | nose.loader.TestLoader.getTestCaseNames = getTestCaseNames |
|
71 | 76 | ########################################################################## |
@@ -1,21 +1,38 b'' | |||
|
1 |
""" |
|
|
1 | """Decorators marks that a doctest should be skipped, for both python 2 and 3. | |
|
2 | 2 | |
|
3 | 3 | The IPython.testing.decorators module triggers various extra imports, including |
|
4 | 4 | numpy and sympy if they're present. Since this decorator is used in core parts |
|
5 | 5 | of IPython, it's in a separate module so that running IPython doesn't trigger |
|
6 | 6 | those imports.""" |
|
7 | ||
|
8 | #----------------------------------------------------------------------------- | |
|
9 | # Copyright (C) 2009-2011 The IPython Development Team | |
|
10 | # | |
|
11 | # Distributed under the terms of the BSD License. The full license is in | |
|
12 | # the file COPYING, distributed as part of this software. | |
|
13 | #----------------------------------------------------------------------------- | |
|
14 | ||
|
15 | #----------------------------------------------------------------------------- | |
|
16 | # Imports | |
|
17 | #----------------------------------------------------------------------------- | |
|
18 | ||
|
7 | 19 | import sys |
|
8 | 20 | |
|
21 | #----------------------------------------------------------------------------- | |
|
22 | # Decorators | |
|
23 | #----------------------------------------------------------------------------- | |
|
24 | ||
|
9 | 25 | def skip_doctest(f): |
|
10 | 26 | """Decorator - mark a function or method for skipping its doctest. |
|
11 | 27 | |
|
12 | 28 | This decorator allows you to mark a function whose docstring you wish to |
|
13 | 29 | omit from testing, while preserving the docstring for introspection, help, |
|
14 | 30 | etc.""" |
|
15 | 31 | f.skip_doctest = True |
|
16 | 32 | return f |
|
17 | 33 | |
|
34 | ||
|
18 | 35 | def skip_doctest_py3(f): |
|
19 | 36 | """Decorator - skip the doctest under Python 3.""" |
|
20 | 37 | f.skip_doctest = (sys.version_info[0] >= 3) |
|
21 | 38 | return f |
General Comments 0
You need to be logged in to leave comments.
Login now