|
1 |
| -#!/usr/bin/env python |
| 1 | +#!/usr/bin/env python3 |
2 | 2 |
|
3 | 3 | """Script for running the remote server tests using different interpreters.
|
4 | 4 |
|
5 |
| -Usage: run.py interpreter [arguments] |
| 5 | +Usage: run.py [interpreter] [arguments] |
6 | 6 |
|
7 |
| -`interpreter` is the only required argument and specifies Python interpreter |
8 |
| -to run the remote server with. The interpreter must be found from PATH or |
9 |
| -given as an absolute path. |
| 7 | +`interpreter` is name or path of the Python interpreter to run the remote |
| 8 | +server with. The interpreter must be found from PATH or given as an absolute |
| 9 | +path. If not given, `python` will be used by default. |
10 | 10 |
|
11 | 11 | `arguments` are normal Robot Framework options and arguments. Test case files
|
12 |
| -are under `atest` directory. |
| 12 | +are under the `atest` directory. |
13 | 13 |
|
14 |
| -If only the interpreter are given, all acceptance tests under `atest` directory |
| 14 | +If no arguments are given, all acceptance tests under the `atest` directory |
15 | 15 | as well as unit tests under `utest` are executed. Unit tests are run first
|
16 |
| -and acceptance tests skipped if they fail. To run only unit tests, use |
17 |
| -`utest/run.py` instead. |
| 16 | +and acceptance tests skipped if they fail. |
18 | 17 |
|
19 |
| -Examples: |
| 18 | +If arguments are given, unit tests are not run. To run only unit tests, use |
| 19 | +`test/utest/run.py` instead. |
| 20 | +
|
| 21 | +This script must be run using Python 3. |
20 | 22 |
|
21 |
| - run.py python # All unit and acceptance tests with Python |
| 23 | +Examples: |
| 24 | + run.py # All unit and acceptance tests with Python |
22 | 25 | run.py "py -3" atest/kwargs.robot # One suite with Python 3 on Windows
|
23 | 26 | run.py ipy --test NoMessage atest # Specific test using IronPython
|
24 | 27 | """
|
25 | 28 |
|
26 |
| -from __future__ import print_function |
27 |
| - |
28 | 29 | from os.path import abspath, dirname, exists, join
|
29 | 30 | import os
|
30 | 31 | import shutil
|
|
36 | 37 | import robotstatuschecker
|
37 | 38 |
|
38 | 39 |
|
39 |
| -if len(sys.argv) == 1 or '-h' in sys.argv or '--help' in sys.argv: |
| 40 | +if '-h' in sys.argv or '--help' in sys.argv: |
40 | 41 | sys.exit(__doc__)
|
41 | 42 |
|
42 | 43 | curdir = dirname(abspath(__file__))
|
43 | 44 | results = join(curdir, 'results')
|
44 | 45 | output = join(results, 'output.xml')
|
45 |
| -interpreter = sys.argv[1] |
| 46 | +interpreter = sys.argv[1] if len(sys.argv) > 1 else 'python' |
| 47 | +version = subprocess.check_output([interpreter, '-V'], encoding='UTF-8', |
| 48 | + stderr=subprocess.STDOUT) |
| 49 | +py2 = version.split()[1][:3] == '2.7' |
46 | 50 | arguments = sys.argv[2:]
|
47 | 51 |
|
48 | 52 | if exists(results):
|
49 | 53 | shutil.rmtree(results)
|
50 | 54 | os.mkdir(results)
|
51 | 55 |
|
52 | 56 | if not arguments:
|
53 |
| - print('Running unit tests with "%s".' % interpreter) |
| 57 | + print(f'Running unit tests with "{interpreter}".') |
54 | 58 | command = shlex.split(interpreter) + [join(curdir, 'utest', 'run.py')]
|
55 | 59 | rc = subprocess.call(command)
|
56 | 60 | print()
|
57 | 61 | if rc != 0:
|
58 |
| - print('%d unit test%s failed.' % (rc, 's' if rc != 1 else '')) |
| 62 | + tests = 'tests' if rc != 1 else 'test' |
| 63 | + print(f'{rc} unit {tests} failed.') |
59 | 64 | sys.exit(rc)
|
60 | 65 | arguments = [join(curdir, 'atest')]
|
61 | 66 |
|
|
66 | 71 | excludes.extend(['--exclude', 'no-ipy'])
|
67 | 72 | command = [
|
68 | 73 | 'python', '-m', 'robot.run',
|
69 |
| - '--variable', 'INTERPRETER:%s' % interpreter, |
70 |
| - '--doc', 'Remote server tests on "%s"' % interpreter, |
71 |
| - '--metadata', 'Server_Interpreter:%s' % interpreter, |
| 74 | + '--variable', f'INTERPRETER:{interpreter}', |
| 75 | + '--variable', f'PY2:{py2}', |
| 76 | + '--doc', f"Remote server tests using '{interpreter}'.", |
| 77 | + '--metadata', f'Interpreter Version:{version}', |
72 | 78 | '--output', output, '--log', 'NONE', '--report', 'NONE'
|
73 | 79 | ] + excludes + arguments
|
74 |
| -print('Running acceptance tests with command:\n%s' % ' '.join(command)) |
| 80 | +print('Running acceptance tests with command:\n' + ' '.join(command)) |
75 | 81 | rc = subprocess.call(command)
|
76 | 82 | print()
|
77 | 83 | if rc > 250:
|
|
80 | 86 |
|
81 | 87 | print('Verifying results.')
|
82 | 88 | robotstatuschecker.process_output(output)
|
83 |
| -rc = robot.rebot(output, outputdir=results, noncritical='skip') |
| 89 | +rc = robot.rebot(output, outputdir=results) |
84 | 90 | print()
|
85 | 91 | if rc == 0:
|
86 | 92 | print('All tests passed.')
|
87 | 93 | else:
|
88 |
| - print('%d acceptance test%s failed.' % (rc, 's' if rc != 1 else '')) |
| 94 | + tests = 'tests' if rc != 1 else 'test' |
| 95 | + print(f'{rc} acceptance {tests} failed.') |
89 | 96 | sys.exit(rc)
|
0 commit comments