Andrew Lamb | 8e70ad0 | 2020-03-23 08:40:44 -0600 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | # |
| 3 | # Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | # |
| 7 | # Runs python unittests in a venv. |
| 8 | |
Sean McAllister | 6e2a419 | 2021-01-28 14:56:47 -0700 | [diff] [blame] | 9 | readonly bin_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")"/bin |
| 10 | |
Andrew Lamb | 8e70ad0 | 2020-03-23 08:40:44 -0600 | [diff] [blame] | 11 | # Move to this script's directory. |
| 12 | cd "$(dirname "$0")" |
| 13 | |
| 14 | # Generate protos |
| 15 | echo "Generating proto bindings..." |
| 16 | ./generate.sh |
| 17 | |
| 18 | # Create and activate venv. |
| 19 | echo "Creating and activating venv..." |
Sean McAllister | 6e2a419 | 2021-01-28 14:56:47 -0700 | [diff] [blame] | 20 | source "${bin_dir}/common.sh" |
| 21 | create_venv |
Andrew Lamb | 8e70ad0 | 2020-03-23 08:40:44 -0600 | [diff] [blame] | 22 | |
| 23 | # Discover and run unittests in payload_utils. |
| 24 | echo "Running unittests..." |
| 25 | python3 -m unittest discover -s payload_utils -p "*test.py" |
| 26 | |
Andrew Lamb | 0ed1b90 | 2020-06-08 17:03:47 -0600 | [diff] [blame] | 27 | echo "Running pylint..." |
| 28 | PYTHONPATH=payload_utils pylint "$(pwd)/payload_utils" \ |
| 29 | --rcfile=payload_utils/pylintrc |
| 30 | |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 31 | echo "Checking Python files formatted with yapf..." |
| 32 | if ! yapf --style .style.yapf --diff -r payload_utils ; then |
| 33 | echo "Python files require reformatting. Please run 'yapf --style .style.yapf --in-place -r payload_utils'." |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
Andrew Lamb | 8e70ad0 | 2020-03-23 08:40:44 -0600 | [diff] [blame] | 37 | # Deactivate venv. |
David Burger | f2b424b | 2020-06-12 10:49:28 -0600 | [diff] [blame] | 38 | deactivate |