blob: 2dedb8c69716c3b69c7f0bdc7f87392fd0c8b8a2 [file] [log] [blame]
Andrew Lamb8e70ad02020-03-23 08:40:44 -06001#!/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.
10cd "$(dirname "$0")"
11
12# Generate protos
13echo "Generating proto bindings..."
14./generate.sh
15
16# Create and activate venv.
17echo "Creating and activating venv..."
18/usr/bin/python3 -m venv .venv
19source .venv/bin/activate
20
21# Install requirements.
22echo "Installing required packages..."
Andrew Lamb0ed1b902020-06-08 17:03:47 -060023pip install wheel -q
Andrew Lamb8e70ad02020-03-23 08:40:44 -060024pip install -r requirements.txt -q
25
26# Discover and run unittests in payload_utils.
27echo "Running unittests..."
28python3 -m unittest discover -s payload_utils -p "*test.py"
29
Andrew Lamb0ed1b902020-06-08 17:03:47 -060030echo "Running pylint..."
31PYTHONPATH=payload_utils pylint "$(pwd)/payload_utils" \
32 --rcfile=payload_utils/pylintrc
33
Andrew Lamb2413c982020-05-29 12:15:36 -060034echo "Checking Python files formatted with yapf..."
35if ! 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
38fi
39
Andrew Lamb8e70ad02020-03-23 08:40:44 -060040# Deactivate venv.
41deactivate