Skip to content

Commit 705a3d2

Browse files
Test README examples are up-to-date (#484)
1 parent 00c1ae0 commit 705a3d2

File tree

3 files changed

+116
-5
lines changed

3 files changed

+116
-5
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,26 @@ To use Ruff on a fresh project, run:
7777
```console
7878
$ uvx usethis tool ruff
7979
✔ Writing 'pyproject.toml'.
80-
✔ Adding dependency 'ruff' to the 'dev' dependency group.
80+
✔ Adding dependency 'ruff' to the 'dev' group in 'pyproject.toml'.
8181
✔ Adding Ruff config to 'pyproject.toml'.
8282
✔ Enabling Ruff rules 'A', 'C4', 'E4', 'E7', 'E9', 'EM', 'F', 'FURB', 'I', 'PLE', 'PLR', 'RUF', 'SIM', 'UP' in 'pyproject.toml'.
8383
✔ Ignoring Ruff rules 'PLR2004', 'SIM108' in 'pyproject.toml'.
84-
☐ Run 'ruff check --fix' to run the Ruff linter with autofixes.
85-
☐ Run 'ruff format' to run the Ruff formatter.
84+
☐ Run 'uv run ruff check --fix' to run the Ruff linter with autofixes.
85+
☐ Run 'uv run ruff format' to run the Ruff formatter.
8686
```
8787

8888
To use pytest, run:
8989

9090
```console
9191
$ uvx usethis tool pytest
92-
✔ Adding dependency 'pytest' to the 'test' dependency group in 'pyproject.toml'.
92+
✔ Adding dependency 'pytest' to the 'test' group in 'pyproject.toml'.
9393
✔ Adding pytest config to 'pyproject.toml'.
9494
✔ Enabling Ruff rule 'PT' in 'pyproject.toml'.
9595
✔ Creating '/tests'.
9696
✔ Writing '/tests/conftest.py'.
9797
☐ Add test files to the '/tests' directory with the format 'test_*.py'.
9898
☐ Add test functions with the format 'test_*()'.
99-
☐ Run 'pytest' to run the tests.
99+
☐ Run 'uv run pytest' to run the tests.
100100
```
101101

102102
To configure Bitbucket pipelines, run:
@@ -105,6 +105,7 @@ To configure Bitbucket pipelines, run:
105105
$ uvx usethis ci bitbucket
106106
✔ Writing 'bitbucket-pipelines.yml'.
107107
✔ Adding cache 'uv' definition to 'bitbucket-pipelines.yml'.
108+
✔ Adding 'Run Ruff' to default pipeline in 'bitbucket-pipelines.yml'.
108109
✔ Adding 'Test on 3.12' to default pipeline in 'bitbucket-pipelines.yml'.
109110
✔ Adding 'Test on 3.13' to default pipeline in 'bitbucket-pipelines.yml'.
110111
☐ Run your pipeline via the Bitbucket website.

tests/usethis/_interface/test_ci.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from pathlib import Path
2+
3+
from typer.testing import CliRunner
4+
5+
from usethis._interface.ci import app
6+
from usethis._test import change_cwd
7+
8+
9+
class TestBitbucket:
10+
def test_readme_example(self, tmp_path: Path):
11+
"""This example is used the README.md file.
12+
13+
Note carefully! If this test is updated, the README.md file must be
14+
updated too.
15+
"""
16+
# Arrange
17+
# We've already run ruff and pytest...
18+
(tmp_path / "pytest.ini").touch()
19+
(tmp_path / "ruff.toml").touch()
20+
# Consistent versions in the matrix - only two to demonstrate it, 3 is excessive
21+
(tmp_path / "pyproject.toml").write_text(
22+
"""\
23+
[project]
24+
requires-python = ">=3.12"
25+
"""
26+
)
27+
28+
# Act
29+
runner = CliRunner()
30+
with change_cwd(tmp_path):
31+
result = runner.invoke(app, [])
32+
33+
# Assert
34+
assert result.exit_code == 0, result.output
35+
assert (
36+
result.output
37+
== """\
38+
✔ Writing 'bitbucket-pipelines.yml'.
39+
✔ Adding cache 'uv' definition to 'bitbucket-pipelines.yml'.
40+
✔ Adding 'Run Ruff' to default pipeline in 'bitbucket-pipelines.yml'.
41+
✔ Adding 'Test on 3.12' to default pipeline in 'bitbucket-pipelines.yml'.
42+
✔ Adding 'Test on 3.13' to default pipeline in 'bitbucket-pipelines.yml'.
43+
☐ Run your pipeline via the Bitbucket website.
44+
"""
45+
)

tests/usethis/_interface/test_tool.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,33 @@ def test_cli(self, uv_init_dir: Path):
152152
else:
153153
call_subprocess(["usethis", "tool", "ruff", "--offline"])
154154

155+
def test_readme_example(self, tmp_path: Path):
156+
"""This example is used the README.md file.
157+
158+
Note carefully! If this test is updated, the README.md file must be
159+
updated too.
160+
"""
161+
# Act
162+
runner = CliRunner()
163+
with change_cwd(tmp_path):
164+
result = runner.invoke(app, ["ruff"])
165+
166+
# Assert
167+
assert result.exit_code == 0, result.output
168+
assert (
169+
result.output
170+
== """\
171+
✔ Writing 'pyproject.toml'.
172+
✔ Adding dependency 'ruff' to the 'dev' group in 'pyproject.toml'.
173+
✔ Adding Ruff config to 'pyproject.toml'.
174+
✔ Enabling Ruff rules 'A', 'C4', 'E4', 'E7', 'E9', 'EM', 'F', 'FURB', 'I',
175+
'PLE', 'PLR', 'RUF', 'SIM', 'UP' in 'pyproject.toml'.
176+
✔ Ignoring Ruff rules 'PLR2004', 'SIM108' in 'pyproject.toml'.
177+
☐ Run 'uv run ruff check --fix' to run the Ruff linter with autofixes.
178+
☐ Run 'uv run ruff format' to run the Ruff formatter.
179+
"""
180+
)
181+
155182

156183
class TestPytest:
157184
@pytest.mark.usefixtures("_vary_network_conn")
@@ -167,6 +194,44 @@ def test_add(self, tmp_path: Path):
167194
# Assert
168195
assert result.exit_code == 0, result.output
169196

197+
def test_readme_example(self, tmp_path: Path):
198+
"""This example is used the README.md file.
199+
200+
Note carefully! If this test is updated, the README.md file must be
201+
updated too.
202+
"""
203+
# Arrange
204+
# We've already run ruff...
205+
(tmp_path / "pyproject.toml").write_text("""\
206+
[project]
207+
name = "example"
208+
version = "0.1.0"
209+
210+
[tool.ruff]
211+
line-length = 88
212+
""")
213+
214+
# Act
215+
runner = CliRunner()
216+
with change_cwd(tmp_path):
217+
result = runner.invoke(app, ["pytest"])
218+
219+
# Assert
220+
assert result.exit_code == 0, result.output
221+
assert (
222+
result.output
223+
== """\
224+
✔ Adding dependency 'pytest' to the 'test' group in 'pyproject.toml'.
225+
✔ Adding pytest config to 'pyproject.toml'.
226+
✔ Enabling Ruff rule 'PT' in 'pyproject.toml'.
227+
✔ Creating '/tests'.
228+
✔ Writing '/tests/conftest.py'.
229+
☐ Add test files to the '/tests' directory with the format 'test_*.py'.
230+
☐ Add test functions with the format 'test_*()'.
231+
☐ Run 'uv run pytest' to run the tests.
232+
"""
233+
)
234+
170235

171236
@pytest.mark.benchmark
172237
def test_several_tools_add_and_remove(tmp_path: Path):

0 commit comments

Comments
 (0)