Skip to content

Commit fe93ed2

Browse files
committed
Reverted decorators_trial.py and added command line docs.
* Reverted :mod:`IPython.testing.decorators_trial.py` and everything that uses it. * Updated the command line usage information for ipcluster.
1 parent 70d2729 commit fe93ed2

4 files changed

Lines changed: 188 additions & 24 deletions

File tree

‎IPython/kernel/core/tests/test_redirectors.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222

2323
from twisted.trial import unittest
2424

25+
from IPython.testing import decorators_trial as dec
26+
2527
#-----------------------------------------------------------------------------
2628
# Tests
2729
#-----------------------------------------------------------------------------
2830

2931
class TestRedirector(unittest.TestCase):
3032

31-
if sys.platform == 'win32':
32-
skip = True
33-
33+
@dec.skip_win32
3434
def test_redirector(self):
3535
"""Checks that the redirector can be used to do synchronous capture.
3636
"""
@@ -51,6 +51,7 @@ def test_redirector(self):
5151
result2 = "".join("%ic\n%i\n" %(i, i) for i in range(10))
5252
self.assertEquals(result1, result2)
5353

54+
@dec.skip_win32
5455
def test_redirector_output_trap(self):
5556
"""Check the greedy trapping behavior of the traps.
5657

‎IPython/kernel/ipclusterapp.py‎

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
This command automates the startup of these processes using a wide
5050
range of startup methods (SSH, local processes, PBS, mpiexec,
5151
Windows HPC Server 2008). To start a cluster with 4 engines on your
52-
local host simply do "ipcluster start -n 4". For more complex usage
53-
you will typically do "ipcluster create -p mycluster", then edit
54-
configuration files, followed by "ipcluster start -p mycluster -n 4".
52+
local host simply do 'ipcluster start -n 4'. For more complex usage
53+
you will typically do 'ipcluster create -p mycluster', then edit
54+
configuration files, followed by 'ipcluster start -p mycluster -n 4'.
5555
"""
5656

5757

@@ -106,24 +106,42 @@ def _add_arguments(self):
106106
title='ipcluster subcommands',
107107
description=
108108
"""ipcluster has a variety of subcommands. The general way of
109-
running ipcluster is 'ipcluster <cmd> [options]'""",
110-
help="For more help, type 'ipcluster <cmd> -h'"
109+
running ipcluster is 'ipcluster <cmd> [options]'. To get help
110+
on a particular subcommand do 'ipcluster <cmd> -h'."""
111+
# help="For more help, type 'ipcluster <cmd> -h'",
111112
)
112113

113114
# The "list" subcommand parser
114115
parser_list = subparsers.add_parser(
115116
'list',
116-
help='List all clusters in cwd and ipython_dir.',
117117
parents=[parent_parser1],
118-
argument_default=SUPPRESS
118+
argument_default=SUPPRESS,
119+
help="List all clusters in cwd and ipython_dir.",
120+
description=
121+
"""List all available clusters, by cluster directory, that can
122+
be found in the current working directly or in the ipython
123+
directory. Cluster directories are named using the convention
124+
'cluster_<profile>'."""
119125
)
120126

121127
# The "create" subcommand parser
122128
parser_create = subparsers.add_parser(
123129
'create',
124-
help='Create a new cluster directory.',
125130
parents=[parent_parser1, parent_parser2],
126-
argument_default=SUPPRESS
131+
argument_default=SUPPRESS,
132+
help="Create a new cluster directory.",
133+
description=
134+
"""Create an ipython cluster directory by its profile name or
135+
cluster directory path. Cluster directories contain
136+
configuration, log and security related files and are named
137+
using the convention 'cluster_<profile>'. By default they are
138+
located in your ipython directory. Once created, you will
139+
probably need to edit the configuration files in the cluster
140+
directory to configure your cluster. Most users will create a
141+
cluster directory by profile name,
142+
'ipcluster create -p mycluster', which will put the directory
143+
in '<ipython_dir>/cluster_mycluster'.
144+
"""
127145
)
128146
paa = parser_create.add_argument
129147
paa('--reset-config',
@@ -135,9 +153,19 @@ def _add_arguments(self):
135153
# The "start" subcommand parser
136154
parser_start = subparsers.add_parser(
137155
'start',
138-
help='Start a cluster.',
139156
parents=[parent_parser1, parent_parser2],
140-
argument_default=SUPPRESS
157+
argument_default=SUPPRESS,
158+
help="Start a cluster.",
159+
description=
160+
"""Start an ipython cluster by its profile name or cluster
161+
directory. Cluster directories contain configuration, log and
162+
security related files and are named using the convention
163+
'cluster_<profile>' and should be creating using the 'start'
164+
subcommand of 'ipcluster'. If your cluster directory is in
165+
the cwd or the ipython directory, you can simply refer to it
166+
using its profile name, 'ipcluster start -n 4 -p <profile>`,
167+
otherwise use the '--cluster-dir' option.
168+
"""
141169
)
142170
paa = parser_start.add_argument
143171
paa('-n', '--number',
@@ -160,9 +188,17 @@ def _add_arguments(self):
160188
# The "stop" subcommand parser
161189
parser_stop = subparsers.add_parser(
162190
'stop',
163-
help='Stop a cluster.',
164191
parents=[parent_parser1, parent_parser2],
165-
argument_default=SUPPRESS
192+
argument_default=SUPPRESS,
193+
help="Stop a running cluster.",
194+
description=
195+
"""Stop a running ipython cluster by its profile name or cluster
196+
directory. Cluster directories are named using the convention
197+
'cluster_<profile>'. If your cluster directory is in
198+
the cwd or the ipython directory, you can simply refer to it
199+
using its profile name, 'ipcluster stop -p <profile>`, otherwise
200+
use the '--cluster-dir' option.
201+
"""
166202
)
167203
paa = parser_stop.add_argument
168204
paa('--signal',
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# encoding: utf-8
2+
"""
3+
Testing related decorators for use with twisted.trial.
4+
5+
The decorators in this files are designed to follow the same API as those
6+
in the decorators module (in this same directory). But they can be used
7+
with twisted.trial
8+
"""
9+
10+
#-----------------------------------------------------------------------------
11+
# Copyright (C) 2008-2009 The IPython Development Team
12+
#
13+
# Distributed under the terms of the BSD License. The full license is in
14+
# the file COPYING, distributed as part of this software.
15+
#-----------------------------------------------------------------------------
16+
17+
#-----------------------------------------------------------------------------
18+
# Imports
19+
#-----------------------------------------------------------------------------
20+
21+
import os
22+
import sys
23+
24+
from IPython.testing.decorators import make_label_dec
25+
26+
#-----------------------------------------------------------------------------
27+
# Testing decorators
28+
#-----------------------------------------------------------------------------
29+
30+
31+
def skipif(skip_condition, msg=None):
32+
"""Create a decorator that marks a test function for skipping.
33+
34+
The is a decorator factory that returns a decorator that will
35+
conditionally skip a test based on the value of skip_condition. The
36+
skip_condition argument can either be a boolean or a callable that returns
37+
a boolean.
38+
39+
Parameters
40+
----------
41+
skip_condition : boolean or callable
42+
If this evaluates to True, the test is skipped.
43+
msg : str
44+
The message to print if the test is skipped.
45+
46+
Returns
47+
-------
48+
decorator : function
49+
The decorator function that can be applied to the test function.
50+
"""
51+
52+
def skip_decorator(f):
53+
54+
# Allow for both boolean or callable skip conditions.
55+
if callable(skip_condition):
56+
skip_val = lambda : skip_condition()
57+
else:
58+
skip_val = lambda : skip_condition
59+
60+
if msg is None:
61+
out = 'Test skipped due to test condition.'
62+
else:
63+
out = msg
64+
final_msg = "Skipping test: %s. %s" % (f.__name__,out)
65+
66+
if skip_val():
67+
f.skip = final_msg
68+
69+
return f
70+
return skip_decorator
71+
72+
73+
def skip(msg=None):
74+
"""Create a decorator that marks a test function for skipping.
75+
76+
This is a decorator factory that returns a decorator that will cause
77+
tests to be skipped.
78+
79+
Parameters
80+
----------
81+
msg : str
82+
Optional message to be added.
83+
84+
Returns
85+
-------
86+
decorator : function
87+
Decorator, which, when applied to a function, sets the skip
88+
attribute of the function causing `twisted.trial` to skip it.
89+
"""
90+
91+
return skipif(True,msg)
92+
93+
94+
def numpy_not_available():
95+
"""Can numpy be imported? Returns true if numpy does NOT import.
96+
97+
This is used to make a decorator to skip tests that require numpy to be
98+
available, but delay the 'import numpy' to test execution time.
99+
"""
100+
try:
101+
import numpy
102+
np_not_avail = False
103+
except ImportError:
104+
np_not_avail = True
105+
106+
return np_not_avail
107+
108+
#-----------------------------------------------------------------------------
109+
# Decorators for public use
110+
#-----------------------------------------------------------------------------
111+
112+
# Decorators to skip certain tests on specific platforms.
113+
skip_win32 = skipif(sys.platform == 'win32',
114+
"This test does not run under Windows")
115+
skip_linux = skipif(sys.platform == 'linux2',
116+
"This test does not run under Linux")
117+
skip_osx = skipif(sys.platform == 'darwin',"This test does not run under OS X")
118+
119+
# Decorators to skip tests if not on specific platforms.
120+
skip_if_not_win32 = skipif(sys.platform != 'win32',
121+
"This test only runs under Windows")
122+
skip_if_not_linux = skipif(sys.platform != 'linux2',
123+
"This test only runs under Linux")
124+
skip_if_not_osx = skipif(sys.platform != 'darwin',
125+
"This test only runs under OSX")
126+
127+
# Other skip decorators
128+
skipif_not_numpy = skipif(numpy_not_available,"This test requires numpy")
129+
130+
skipknownfailure = skip('This test is known to fail')
131+
132+

‎IPython/testing/tests/test_decorators_trial.py‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# encoding: utf-8
22
"""
3-
Tests for decorators.py compatibility with Twisted.trial
3+
Tests for decorators_trial.py
44
"""
55

66
#-----------------------------------------------------------------------------
@@ -14,24 +14,19 @@
1414
# Imports
1515
#-----------------------------------------------------------------------------
1616

17-
# Tell nose to skip this module, since this is for twisted only
17+
# Tell nose to skip this module
1818
__test__ = {}
1919

2020
import os
2121
import sys
2222

2323
from twisted.trial import unittest
24-
import IPython.testing.decorators as dec
24+
import IPython.testing.decorators_trial as dec
2525

2626
#-----------------------------------------------------------------------------
2727
# Tests
2828
#-----------------------------------------------------------------------------
2929

30-
# Note: this code is identical to that in test_decorators, but that one uses
31-
# stdlib unittest, not the one from twisted, which we are using here. While
32-
# somewhat redundant, we want to check both with the stdlib and with twisted,
33-
# so the duplication is OK.
34-
3530
class TestDecoratorsTrial(unittest.TestCase):
3631

3732
@dec.skip()

0 commit comments

Comments
 (0)