~launchpad-pqm/launchpad/devel

11300.2.26 by Stuart Bishop
Test unhandled exception handling by LaunchpadScript
1
Launchpad Scripts
2
=================
3
4
Launchpad scripts are built using the LaunchpadScript class in
5
lp.services.scripts.base. This, along with the LaunchpadCronScript
6
specialization, implement common behavior for all Launchpad command
7
line scripts.
8
9
    >>> from lp.services.scripts.base import (
10
    ...     LaunchpadScript, LaunchpadCronScript)
11
12
13
Scripts report their executution using the standard Python logging
14
module, with command line arguments and logging setup provided by
15
LaunchpadScript. Unhandled exceptions from scripts are automatically
11300.2.27 by Stuart Bishop
Fix log level bug and test WARN and above generate OOPS reports
16
sent to the Python logging system. Cronscripts (scripts using
17
LaunchpadCronScript) also log warnings and and errors as OOPS reports.
11300.2.26 by Stuart Bishop
Test unhandled exception handling by LaunchpadScript
18
19
    >>> import os.path, subprocess, sys
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
20
    >>> from lp.services.config import config
11300.2.26 by Stuart Bishop
Test unhandled exception handling by LaunchpadScript
21
    >>> cronscript_crash_path = os.path.join(
22
    ...     config.root, 'lib', 'lp', 'services', 'scripts', 'tests',
23
    ...     'cronscript-crash.py')
24
    >>> p = subprocess.Popen(
11300.2.27 by Stuart Bishop
Fix log level bug and test WARN and above generate OOPS reports
25
    ...     [sys.executable, cronscript_crash_path, '-vq'],
11300.2.26 by Stuart Bishop
Test unhandled exception handling by LaunchpadScript
26
    ...     stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
27
    ...     stdin=subprocess.PIPE)
28
    >>> print p.communicate()[0]
11300.2.27 by Stuart Bishop
Fix log level bug and test WARN and above generate OOPS reports
29
    INFO    Creating lockfile: ...
11300.2.26 by Stuart Bishop
Test unhandled exception handling by LaunchpadScript
30
    WARNING This is a warning
11300.2.27 by Stuart Bishop
Fix log level bug and test WARN and above generate OOPS reports
31
    INFO    New OOPS detected
32
    CRITICAL This is critical
33
    INFO    New OOPS detected
11300.2.26 by Stuart Bishop
Test unhandled exception handling by LaunchpadScript
34
    ERROR   Unhandled exception
35
    ...
36
    NotImplementedError: Whoops
37
    >>> p.returncode
11300.2.31 by Stuart Bishop
Unhandled exception handling should ignore SystemExit and KeyboardInterrupt, and return error code expected by test suite
38
    1
11300.2.26 by Stuart Bishop
Test unhandled exception handling by LaunchpadScript
39