aboutsummaryrefslogtreecommitdiff
path: root/TESTING.md
blob: 91fe9cc12a7e7e4207479010ea6c97dedf96a6d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!--
SPDX-FileCopyrightText: Copyright 2020, 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>

SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the License); you may
not use this file except in compliance with the License.
You may obtain a copy of the License at

www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
# Vela Testing

## Tools

Vela's Python codebase is PEP8 compliant with the exception of a 120 character
line length.  The following code formatting and linting tools are run on all the
Python files (excluding the directories `ethosu/vela/tflite/`, `ethosu/vela/tosa/`,
and `ethosu/vela/ethos_u55_regs` because they contain auto-generated code):

* mypy (code linter)
* reorder-python-import (code formatter)
* black (code formatter)
* flake8 (code linter)
* pylint (code linter)

These tools are run using the [pre-commit](https://pre-commit.com/) framework.
This is also used to run the following test and coverage tools:

* pytest (testing framework)
* pytest-cov (code coverage plugin for pytest)

### Installation

To install the development dependencies, use the following command:

``` bash
pip install -e .[dev]
```

This command will install the following tools:

* pytest
* pytest-cov
* pre-commit
* build
* setuptools_scm

The remaining tools will all be installed automatically upon first use of pre-commit.

### Add pre-commit hook (Automatically running the tools)

To support code development all the above tools can be configured to run
automatically on `git commit` (except pytest-cov which is run on `git push`) by
using the command:

```bash
$ pre-commit install
pre-commit installed at .git/hooks/pre-commit
```

When committing (or pushing) if any of the tools result in a failure (meaning an
issue was found) then it will need to be resolved and the git operation
repeated.

### Manually running the tools

All of the tools can be run individually by invoking them using the following
pre-commit framework commands:

```bash
$ pre-commit run mypy --all-files
...
$ pre-commit run reorder-python-imports --all-files
...
$ pre-commit run black --all-files
...
$ pre-commit run flake8 --all-files
...
$ pre-commit run pylint --all-files
...
$ pre-commit run pytest
...
$ pre-commit run pytest-cov --hook-stage push
...
```

Alternatively, all of the commit stage hooks can be run using the command:

```bash
$ pre-commit run --all-files
mypy.....................................................................Passed
Reorder python imports...................................................Passed
black....................................................................Passed
flake8...................................................................Passed
pylint...................................................................Passed
pytest...................................................................Passed
```