|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | +# |
| 20 | +# list_tests.py - lists all the tests in a Python test script |
| 21 | +# |
| 22 | + |
| 23 | +'''usage: python list_tests.py <prog ...> |
| 24 | +
|
| 25 | +This script will print out all the tests in the `TESTPATH#TESTNUM` |
| 26 | +format for each of these tests. |
| 27 | +''' |
| 28 | + |
| 29 | +import os, sys |
| 30 | +import traceback |
| 31 | + |
| 32 | +if sys.version_info < (3, 5): |
| 33 | + import imp |
| 34 | +else: |
| 35 | + # The imp module is deprecated since Python 3.4; the replacement we use, |
| 36 | + # module_from_spec(), is available since Python 3.5. |
| 37 | + import importlib.util |
| 38 | + |
| 39 | +# Placeholder for the svntest module |
| 40 | +svntest = None |
| 41 | + |
| 42 | +tests = sys.argv[1:] |
| 43 | + |
| 44 | +def _load_py_test_module(progabs, modname): |
| 45 | + 'Run a python test, passing parameters as needed.' |
| 46 | + try: |
| 47 | + if sys.version_info < (3, 0): |
| 48 | + prog_mod = imp.load_module(modname, open(progabs, 'r'), progabs, |
| 49 | + ('.py', 'U', imp.PY_SOURCE)) |
| 50 | + elif sys.version_info < (3, 5): |
| 51 | + prog_mod = imp.load_module(modname, |
| 52 | + open(progabs, 'r', encoding="utf-8"), |
| 53 | + progabs, ('.py', 'U', imp.PY_SOURCE)) |
| 54 | + else: |
| 55 | + spec = importlib.util.spec_from_file_location(modname, progabs) |
| 56 | + prog_mod = importlib.util.module_from_spec(spec) |
| 57 | + sys.modules[modname] = prog_mod |
| 58 | + spec.loader.exec_module(prog_mod) |
| 59 | + except: |
| 60 | + print("\nError loading test (details in following traceback): " + modname) |
| 61 | + traceback.print_exc() |
| 62 | + sys.exit(1) |
| 63 | + |
| 64 | + return prog_mod |
| 65 | + |
| 66 | +basedir = os.path.join("subversion/tests/cmdline") |
| 67 | + |
| 68 | +# The svntest module is very pedantic about the current working directory |
| 69 | +old_cwd = os.getcwd() |
| 70 | +try: |
| 71 | + sys.path.insert(0, os.path.abspath(basedir)) |
| 72 | + |
| 73 | + os.chdir(basedir) |
| 74 | + |
| 75 | + __import__('svntest') |
| 76 | + __import__('svntest.main') |
| 77 | + __import__('svntest.testcase') |
| 78 | + svntest = sys.modules['svntest'] |
| 79 | + svntest.main = sys.modules['svntest.main'] |
| 80 | + svntest.testcase = sys.modules['svntest.testcase'] |
| 81 | + |
| 82 | +finally: |
| 83 | + os.chdir(old_cwd) |
| 84 | + |
| 85 | +for progabs in tests: |
| 86 | + modname = os.path.basename(progabs)[:-3] |
| 87 | + |
| 88 | + testlist = _load_py_test_module(progabs, modname).test_list |
| 89 | + for testnum in range(1, len(testlist)): |
| 90 | + print(progabs + "#" + str(testnum)) |
0 commit comments