1
# -*- coding: utf-8 -*-
3
# debian/tests/smoke_test.py
5
# Copyright © 2016 Ben Finney <bignose@debian.org>
6
# This is free software: you may copy, modify, and/or distribute this work
7
# under the terms of the GNU General Public License as published by the
8
# Free Software Foundation; version 3 of that license or any later version.
9
# No warranty expressed or implied.
11
""" Post-install Python smoke test for use in Debian autopkgtest.
13
Written for both Python 2 and Python 3, to test all installed
14
versions of a package.
16
Smoke test the distribution::
17
--distribution=DISTRIBUTION
19
Smoke test one or more modules::
20
--module=MODULE_FOO --module=MODULE_BAR --module=MODULE_BAZ
30
def emit_implementation():
31
""" Emit the details of the current Python implementation.
37
"Interpreter: {command}\n{version}\n".format(
38
command=sys.executable, version=sys.version))
41
def emit_distribution(name):
42
""" Get the distribution `name` and emit its representation.
44
:param name: Name of the distribution to retrieve.
48
distribution = pkg_resources.get_distribution(name)
50
"Distribution ‘{name}’:\n\t{distribution!r}\n".format(
51
name=name, distribution=distribution))
54
def emit_module(name):
55
""" Import the module `name` and emit the module representation.
57
:param name: Full name of the module to import.
61
module = importlib.import_module(name)
63
"Package ‘{name}’:\n\t{module!r}\n".format(
64
name=name, module=module))
68
""" Run the full suite of tests.
70
:param args: Namespace of arguments parsed from `ArgumentParser`.
76
if args.distribution_name:
77
emit_distribution(args.distribution_name)
79
for module_name in args.module_names:
80
emit_module(module_name)
83
class SmokeTestArgumentParser(argparse.ArgumentParser):
84
""" Command-line argument parser for this program. """
86
def __init__(self, *args, **kwargs):
87
super(SmokeTestArgumentParser, self).__init__(*args, **kwargs)
91
dest='distribution_name', type=str,
92
metavar="DISTRIBUTION", help=(
93
"Test the Python distribution named DISTRIBUTION."))
96
dest='module_names', type=str, nargs='+',
97
metavar="MODULE", help=(
98
"Test the Python module named MODULE."))
102
""" Mainline code for this module.
104
:param argv: Sequence of all command line arguments.
105
(Default: `sys.argv`)
106
:return: The exit status (integer) for exit from the process.
115
program_name = argv[0]
116
parser = SmokeTestArgumentParser(prog=program_name)
117
args = parser.parse_args(argv[1:])
121
except SystemExit as exc:
122
exit_status = exc.code
127
if __name__ == "__main__":
128
exit_status = main(sys.argv)
129
sys.exit(exit_status)
136
# vim: fileencoding=utf-8 filetype=python :