You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: use an opinionated project structure for the testing code (#172)
* add Makefile and switch to pyproject.toml
* exclude package info in .gitignore
* add 'clean' target
* format the testing code
* fix type error in conftest.py
* remove requirements.txt
* switch CI to use new structure (no uv)
* add missing working dir
* add initial HACKING.md
* pytest keyword can just be the rule number
* improve robustness of Makefile
* update intro guidance and cross-links
* Add small section to README
* add guidance for code maintainers
* adjust HACKING.md
* bump action versions in pytest workflow
* add workflow to run the linter
* exclude more cache dirs in .gitignore
* reformat updated code after merging from upstream
* change duplicate function name in testing code
-[Guidance for maintainers of the rules](#guidance-for-maintainers-of-the-rules)
4
+
-[Add test cases for a rule](#add-test-cases-for-a-rule)
5
+
-[Run all test cases](#run-the-test-cases)
6
+
-[Run selected test cases](#run-selected-test-cases)
7
+
-[Guidance for maintainers of the testing code](#guidance-for-maintainers-of-the-testing-code)
8
+
9
+
# Guidance for maintainers of the rules
10
+
11
+
See first: [Introduction to Vale rule development](getting-started.md)
12
+
13
+
## Add test cases for a rule
14
+
15
+
Make sure that the rule has suitable test cases in [tests/data/manifest.yml](tests/data/manifest.yml).
16
+
17
+
## Run all test cases
18
+
19
+
We recommend that you first install [uv](https://docs.astral.sh/uv/). To install uv on Ubuntu:
20
+
21
+
```
22
+
sudo snap install astral-uv --classic
23
+
```
24
+
25
+
To run the test cases for every rule:
26
+
27
+
-**If uv is installed**
28
+
29
+
```text
30
+
make -C tests run
31
+
```
32
+
33
+
- **If uv is not installed**
34
+
35
+
```text
36
+
cd tests
37
+
python3 -m venv .venv
38
+
. .venv/bin/activate
39
+
pip install -e .
40
+
make run
41
+
```
42
+
43
+
## Run selected test cases
44
+
45
+
Behind the scenes, we're using [pytest](https://docs.pytest.org/en/stable/) to run each test case.
46
+
47
+
To run the test cases for a particular rule, such as `003-Ubuntu-names-versions`:
48
+
49
+
- **If uv is installed**
50
+
51
+
```text
52
+
uv run --directory tests pytest -vv -k 003
53
+
```
54
+
55
+
- **If uv is not installed**
56
+
57
+
```text
58
+
# (Provided the working dir is 'tests' and the virtual environment is active)
59
+
pytest -vv -k 003
60
+
```
61
+
62
+
# Guidance for maintainers of the testing code
63
+
64
+
The code in the `tests` directory uses Python with [pytest](https://docs.pytest.org/en/stable/). We require the code to be well-formatted and pass static checks.
65
+
66
+
Our tools of choice are:
67
+
68
+
- [ruff](https://docs.astral.sh/ruff/) for formatting and checking code conventions
69
+
- [pyright](https://microsoft.github.io/pyright/) for checking types
70
+
71
+
If you've already installed ruff, you should be able to use it in the `tests` directory with no trouble. pyright is less straightforward, as it needs to be run in a virtual environment that contains the testing code's dependencies.
72
+
73
+
Instead of manually running these tools, we strongly recommend that you install [uv](https://docs.astral.sh/uv/) and use `make` in the `tests` directory.
Copy file name to clipboardExpand all lines: README.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,11 @@ Anyone is welcome to submit a PR to add additional rules. However, no additions
34
34
35
35
For a reference on rule syntax, see the Vale [documentation on Styles][Vale styles].
36
36
37
-
If you are completely new to developing Vale rules, see this [introductory guide](https://github.com/canonical/documentation-style-guide/blob/8c7fee862b2258c692439ef430198e393bdc30c4/getting-started.md).
37
+
If you are completely new to developing Vale rules, see this [introductory guide](getting-started.md).
38
+
39
+
### Testing the rules
40
+
41
+
This repo includes automated tests of the rules, which you can run locally, and which run in CI. See [Guidance for maintainers of the rules](HACKING.md).
@@ -67,6 +70,10 @@ There are several other extensions, each with a particular set of keys to fine-t
67
70
68
71
You can now use the [documentation](https://vale.sh/docs/topics/styles/#extension-points) to find the extension point that best suits your rule, and see what parameters it requires.
69
72
73
+
### Add test cases
74
+
75
+
This repo includes automated tests of the rules, which you can run locally, and which run in CI. As you develop your rule, you should add test cases that exercise your rule. See [Guidance for maintainers of the rules](HACKING.md).
76
+
70
77
### Resources
71
78
72
79
* Rule examples:
@@ -96,9 +103,12 @@ The single quotes indicate the beginning and end of the regex, and the `.*?` qua
96
103
- [Regex editor](https://regex101.com/): Online tool that helps you compose and test your expressions. I like how it highlights capture groups in different colors.
97
104
- Before composing a complicated regex, remember to check for [existing rules](#resources) that might have done this already.
98
105
99
-
## Test rules
106
+
## Manually test the rules
107
+
108
+
> [!NOTE]
109
+
> This repo includes automated tests of the rules, which you can run locally, and which run in CI. See [Guidance for maintainers of the rules](HACKING.md).
100
110
101
-
Create a file in the root directory of the repository and fill it with text that you expect your rule to catch. It can be in any text format (`.txt`, `.md`, `.rst`...)
111
+
To manually test your rule, create a file in the root directory of the repository and fill it with text that you expect your rule to catch. It can be in any text format (`.txt`, `.md`, `.rst`...)
102
112
103
113
Besides the text file, the `vale` command needs a `vale.ini` config file. This file already exists in the root folder `documentation-style-guide/`. Vale will automatically find the `vale.ini` if you run the command in the same directory.
0 commit comments