Add support for nosetests multiprocessing plugin.
[sawsim.git] / pysawsim / __init__.py
1 # Copyright (C) 2010  W. Trevor King <wking@drexel.edu>
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
15 #
16 # The author may be contacted at <wking@drexel.edu> on the Internet, or
17 # write to Trevor King, Drexel University, Physics Dept., 3141 Chestnut St.,
18 # Philadelphia PA 19104, USA.
19
20 """Wrap `sawsim` to facilitate more complicated analysis.
21
22 Testing pysawsim
23 ================
24
25 pysawsim's test framework is build using doctest_, unittest_, and nose_.
26 `nosetests` (from the nose_ package) scans through the source tree,
27 searching out the various tests and running them.  If you aren't
28 familiar with nose_, there is excellent documentation on its home
29 page.  We use nose_ because its auto-discovery allows us to avoid
30 collecting all of our assorted tests into
31 :class:`unittest.TestSuite`\s and running them by hand.
32
33 To run the test suite from the sawsim installation directory, just use::
34
35     nosetests --with-doctest --doctest-tests pysawsim/
36
37 .. _doctest: http://docs.python.org/library/doctest.html
38 .. _unittest: http://docs.python.org/library/unittest.html
39 .. _nose: http://somethingaboutorange.com/mrl/projects/nose/0.11.3/
40
41
42 Adding tests to modules
43 -----------------------
44
45 Just go crazy with doctests and unittests; nose_ will find them.
46 """
47
48 import logging
49 import logging.handlers
50 import sys
51
52
53 _multiprocess_shared_ = True
54 """Allow nosetests to share this module between test processes.
55
56 This module cannot be split because _log setup is not re-entrant.
57 """
58
59 __version__ = '0.10'  # match sawsim version
60
61
62 def log():
63     return logging.getLogger('pysawsim')
64
65 _log = log()
66 _log.setLevel(logging.DEBUG)
67 _console = logging.StreamHandler()
68 _formatter = logging.Formatter('%(name)-8s: %(levelname)-6s %(message)s')
69 _console.setFormatter(_formatter)
70 _log.addHandler(_console)
71 del(_log)
72 del(_console)
73 del(_formatter)