1#!/usr/bin/env python3 2 3# Simple subunit testrunner for python 4 5# NOTE: This is deprecated - Using the standard subunit runner is 6# preferred - e.g. "python -m samba.subunit.run YOURMODULE". 7# 8# This wrapper will be removed once all tests can be run 9# without it. At the moment there are various tests which still 10# get e.g. credentials passed via command-line options to this 11# script. 12 13# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2014 14# 15# This program is free software; you can redistribute it and/or modify 16# it under the terms of the GNU General Public License as published by 17# the Free Software Foundation; either version 3 of the License, or 18# (at your option) any later version. 19# 20# This program is distributed in the hope that it will be useful, 21# but WITHOUT ANY WARRANTY; without even the implied warranty of 22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23# GNU General Public License for more details. 24# 25# You should have received a copy of the GNU General Public License 26# along with this program. If not, see <http://www.gnu.org/licenses/>. 27# 28 29import sys 30 31# make sure the script dies immediately when hitting control-C, 32# rather than raising KeyboardInterrupt. As we do all database 33# operations using transactions, this is safe. 34import signal 35signal.signal(signal.SIGINT, signal.SIG_DFL) 36 37# Find right directory when running from source tree 38sys.path.insert(0, "bin/python") 39 40import optparse 41import samba 42from samba.tests.subunitrun import TestProgram, SubunitOptions 43 44import samba.getopt as options 45import samba.tests 46 47 48usage = 'subunitrun [options] <tests>' 49description = ''' 50This runs a Samba python test suite. The tests are typically located in 51python/samba/tests/*.py 52 53To run the tests from one of those modules, specify the test as 54samba.tests.MODULE. For example, to run the tests in common.py: 55 56 subunitrun samba.tests.common 57 58To list the tests in that module, use: 59 60 subunitrun -l samba.tests.common 61 62NOTE: This script is deprecated in favor of "python -m subunit.run". Don't use 63it unless it can be avoided. 64''' 65 66def format_description(formatter): 67 '''hack to prevent textwrap of the description''' 68 return description 69 70parser = optparse.OptionParser(usage=usage, description=description) 71parser.format_description = format_description 72credopts = options.CredentialsOptions(parser) 73sambaopts = options.SambaOptions(parser) 74subunitopts = SubunitOptions(parser) 75parser.add_option_group(credopts) 76parser.add_option_group(sambaopts) 77parser.add_option_group(subunitopts) 78 79opts, args = parser.parse_args() 80 81if not getattr(opts, "listtests", False): 82 lp = sambaopts.get_loadparm() 83 samba.tests.cmdline_credentials = credopts.get_credentials(lp) 84if getattr(opts, 'load_list', None): 85 args.insert(0, "--load-list=%s" % opts.load_list) 86 87TestProgram(module=None, args=args, opts=subunitopts) 88