diff options
Diffstat (limited to 'test/pacman/pactest.py')
-rwxr-xr-x | test/pacman/pactest.py | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/test/pacman/pactest.py b/test/pacman/pactest.py index 69e655a0..62034dc7 100755 --- a/test/pacman/pactest.py +++ b/test/pacman/pactest.py @@ -17,8 +17,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import os, sys, glob +import glob from optparse import OptionParser +import os +import shutil +import sys +import tempfile import pmenv import util @@ -26,10 +30,10 @@ import util __author__ = "Aurelien FORET" __version__ = "0.4" -def resolveBinPath(option, opt_str, value, parser): +def resolve_binary_path(option, opt_str, value, parser): setattr(parser.values, option.dest, os.path.abspath(value)) -def globTests(option, opt_str, value, parser): +def glob_tests(option, opt_str, value, parser): idx = 0 globlist = [] @@ -42,8 +46,7 @@ def globTests(option, opt_str, value, parser): parser.rargs = parser.rargs[idx:] setattr(parser.values, option.dest, globlist) -def createOptParser(): - testcases = [] +def create_parser(): usage = "usage: %prog [options] [[--test <path/to/testfile.py>] ...]" description = "Runs automated tests on the pacman binary. Tests are " \ "described using an easy python syntax, and several can be " \ @@ -57,12 +60,15 @@ def createOptParser(): dest = "debug", default = 0, help = "set debug level for pacman") parser.add_option("-p", "--pacman", action = "callback", - callback = resolveBinPath, type = "string", + callback = resolve_binary_path, type = "string", dest = "bin", default = "pacman", help = "specify location of the pacman binary") parser.add_option("-t", "--test", action = "callback", - callback = globTests, dest = "testcases", + callback = glob_tests, dest = "testcases", help = "specify test case(s)") + parser.add_option("--keep-root", action = "store_true", + dest = "keeproot", default = False, + help = "don't remove the generated pacman root filesystem") parser.add_option("--nolog", action = "store_true", dest = "nolog", default = False, help = "do not log pacman messages") @@ -80,8 +86,9 @@ def createOptParser(): if __name__ == "__main__": # instantiate env and parser objects - env = pmenv.pmenv() - opt_parser = createOptParser() + root_path = tempfile.mkdtemp() + env = pmenv.pmenv(root=root_path) + opt_parser = create_parser() (opts, args) = opt_parser.parse_args() # add parsed options to env object @@ -95,16 +102,22 @@ if __name__ == "__main__": if opts.testcases is None or len(opts.testcases) == 0: print "no tests defined, nothing to do" + os.rmdir(root_path) sys.exit(2) - else: - for i in opts.testcases: - env.addtest(i) - # run tests and print overall results - env.run() - env.results() + for i in opts.testcases: + env.addtest(i) + + # run tests and print overall results + env.run() + env.results() + + if not opts.keeproot: + shutil.rmtree(root_path) + else: + print "pacman testing root saved: %s" % root_path - if env.failed > 0: - sys.exit(1) + if env.failed > 0: + sys.exit(1) # vim: set ts=4 sw=4 et: |