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 | |
| 9 | # Move to this script's directory. |
| 10 | cd "$(dirname "$0")" |
| 11 | |
| 12 | # Generate protos |
| 13 | echo "Generating proto bindings..." |
| 14 | ./generate.sh |
| 15 | |
| 16 | # Create and activate venv. |
| 17 | echo "Creating and activating venv..." |
| 18 | /usr/bin/python3 -m venv .venv |
| 19 | source .venv/bin/activate |
| 20 | |
| 21 | # Install requirements. |
| 22 | echo "Installing required packages..." |
Andrew Lamb | 0ed1b90 | 2020-06-08 17:03:47 -0600 | [diff] [blame] | 23 | pip install wheel -q |
Andrew Lamb | 8e70ad0 | 2020-03-23 08:40:44 -0600 | [diff] [blame] | 24 | pip install -r requirements.txt -q |
| 25 | |
| 26 | # Discover and run unittests in payload_utils. |
| 27 | echo "Running unittests..." |
| 28 | python3 -m unittest discover -s payload_utils -p "*test.py" |
| 29 | |
Andrew Lamb | 0ed1b90 | 2020-06-08 17:03:47 -0600 | [diff] [blame] | 30 | echo "Running pylint..." |
| 31 | PYTHONPATH=payload_utils pylint "$(pwd)/payload_utils" \ |
| 32 | --rcfile=payload_utils/pylintrc |
| 33 | |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 34 | echo "Checking Python files formatted with yapf..." |
| 35 | if ! yapf --style .style.yapf --diff -r payload_utils ; then |
| 36 | echo "Python files require reformatting. Please run 'yapf --style .style.yapf --in-place -r payload_utils'." |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
Andrew Lamb | 8e70ad0 | 2020-03-23 08:40:44 -0600 | [diff] [blame] | 40 | # Deactivate venv. |
| 41 | deactivate |