~ubuntu-branches/debian/sid/pyrlp/sid

« back to all changes in this revision

Viewing changes to debian/tests/smoke_test.py

  • Committer: Package Import Robot
  • Author(s): Ben Finney
  • Date: 2017-07-15 05:25:42 UTC
  • Revision ID: package-import@ubuntu.com-20170715052542-wvm6yh0gaf0k33u3
Tags: 0.5.1-1
* The “Zuhair Kutbi” release.
* Initial release.
  Closes: bug#866168.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# debian/tests/smoke_test.py
 
4
#
 
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.
 
10
 
 
11
""" Post-install Python smoke test for use in Debian autopkgtest.
 
12
 
 
13
    Written for both Python 2 and Python 3, to test all installed
 
14
    versions of a package.
 
15
 
 
16
    Smoke test the distribution::
 
17
        --distribution=DISTRIBUTION
 
18
 
 
19
    Smoke test one or more modules::
 
20
        --module=MODULE_FOO --module=MODULE_BAR --module=MODULE_BAZ
 
21
 
 
22
    """
 
23
 
 
24
import sys
 
25
import argparse
 
26
import importlib
 
27
import pkg_resources
 
28
 
 
29
 
 
30
def emit_implementation():
 
31
    """ Emit the details of the current Python implementation.
 
32
 
 
33
        :return: ``None``.
 
34
 
 
35
        """
 
36
    sys.stdout.write(
 
37
            "Interpreter: {command}\n{version}\n".format(
 
38
                command=sys.executable, version=sys.version))
 
39
 
 
40
 
 
41
def emit_distribution(name):
 
42
    """ Get the distribution `name` and emit its representation.
 
43
 
 
44
        :param name: Name of the distribution to retrieve.
 
45
        :return: ``None``.
 
46
 
 
47
        """
 
48
    distribution = pkg_resources.get_distribution(name)
 
49
    sys.stdout.write(
 
50
            "Distribution ‘{name}’:\n\t{distribution!r}\n".format(
 
51
                name=name, distribution=distribution))
 
52
 
 
53
 
 
54
def emit_module(name):
 
55
    """ Import the module `name` and emit the module representation.
 
56
 
 
57
        :param name: Full name of the module to import.
 
58
        :return: ``None``.
 
59
 
 
60
        """
 
61
    module = importlib.import_module(name)
 
62
    sys.stdout.write(
 
63
            "Package ‘{name}’:\n\t{module!r}\n".format(
 
64
                name=name, module=module))
 
65
 
 
66
 
 
67
def suite(args):
 
68
    """ Run the full suite of tests.
 
69
 
 
70
        :param args: Namespace of arguments parsed from `ArgumentParser`.
 
71
        :return: ``None``.
 
72
 
 
73
        """
 
74
    emit_implementation()
 
75
 
 
76
    if args.distribution_name:
 
77
        emit_distribution(args.distribution_name)
 
78
 
 
79
    for module_name in args.module_names:
 
80
        emit_module(module_name)
 
81
 
 
82
 
 
83
class SmokeTestArgumentParser(argparse.ArgumentParser):
 
84
    """ Command-line argument parser for this program. """
 
85
 
 
86
    def __init__(self, *args, **kwargs):
 
87
        super(SmokeTestArgumentParser, self).__init__(*args, **kwargs)
 
88
 
 
89
        self.add_argument(
 
90
                '--distribution',
 
91
                dest='distribution_name', type=str,
 
92
                metavar="DISTRIBUTION", help=(
 
93
                    "Test the Python distribution named DISTRIBUTION."))
 
94
        self.add_argument(
 
95
                '--module',
 
96
                dest='module_names', type=str, nargs='+',
 
97
                metavar="MODULE", help=(
 
98
                    "Test the Python module named MODULE."))
 
99
 
 
100
 
 
101
def main(argv=None):
 
102
    """ Mainline code for this module.
 
103
 
 
104
        :param argv: Sequence of all command line arguments.
 
105
            (Default: `sys.argv`)
 
106
        :return: The exit status (integer) for exit from the process.
 
107
 
 
108
        """
 
109
    exit_status = 0
 
110
 
 
111
    if argv is None:
 
112
        argv = sys.argv
 
113
 
 
114
    try:
 
115
        program_name = argv[0]
 
116
        parser = SmokeTestArgumentParser(prog=program_name)
 
117
        args = parser.parse_args(argv[1:])
 
118
 
 
119
        suite(args)
 
120
 
 
121
    except SystemExit as exc:
 
122
        exit_status = exc.code
 
123
 
 
124
    return exit_status
 
125
 
 
126
 
 
127
if __name__ == "__main__":
 
128
    exit_status = main(sys.argv)
 
129
    sys.exit(exit_status)
 
130
 
 
131
 
 
132
# Local variables:
 
133
# coding: utf-8
 
134
# mode: python
 
135
# End:
 
136
# vim: fileencoding=utf-8 filetype=python :