Skip to content

Commit cd28072

Browse files
committed
fix release ci, move test_messages_documented to separate file
1 parent 7956e2e commit cd28072

File tree

2 files changed

+80
-70
lines changed

2 files changed

+80
-70
lines changed

tests/test_changelog_and_version.py

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@
55

66
import re
77
import sys
8-
import unittest
98
from pathlib import Path
109
from typing import TYPE_CHECKING, NamedTuple, TypeVar
1110

12-
import flake8_trio
13-
14-
from .test_flake8_trio import ERROR_CODES
15-
1611
if TYPE_CHECKING:
1712
from collections.abc import Iterable
1813

1914
ROOT_PATH = Path(__file__).parent.parent
2015
CHANGELOG = ROOT_PATH / "CHANGELOG.md"
21-
README = CHANGELOG.parent / "README.md"
16+
README = ROOT_PATH / "README.md"
17+
INIT_FILE = ROOT_PATH / "flake8_trio" / "__init__.py"
2218

2319
T = TypeVar("T", bound="Version")
2420

@@ -36,7 +32,10 @@ def __str__(self) -> str:
3632
return ".".join(map(str, self))
3733

3834

39-
VERSION = Version.from_string(flake8_trio.__version__)
35+
for line in INIT_FILE.read_text().splitlines():
36+
if m := re.match(r'__version__ = "(\d*\.\d*\.\d*)"', line):
37+
VERSION = Version.from_string(m.groups()[0])
38+
break
4039

4140

4241
def get_releases() -> Iterable[Version]:
@@ -73,7 +72,7 @@ def ensure_tagged() -> None:
7372

7473
last_version = next(iter(get_releases()))
7574
repo = Repo(ROOT_PATH)
76-
if last_version not in repo.tags:
75+
if str(last_version) not in iter(map(str, repo.tags)):
7776
# create_tag is partially unknown in pyright, which kinda looks like
7877
# https://github.com/gitpython-developers/GitPython/issues/1473
7978
# which should be resolved?
@@ -105,65 +104,3 @@ def update_version() -> None:
105104
update_version()
106105
if "--ensure-tag" in sys.argv:
107106
ensure_tagged()
108-
109-
110-
# I wanted to move this test to a separate file, but that'd lead to merge conflicts,
111-
# so will have to wait with that
112-
IGNORED_CODES_REGEX = r"TRIO107|TRIO108|TRIO\d\d\d_.*"
113-
114-
115-
class test_messages_documented(unittest.TestCase):
116-
def runTest(self):
117-
documented_errors: dict[str, set[str]] = {}
118-
for path in (CHANGELOG, README):
119-
with open(path, encoding="utf-8") as f:
120-
lines = f.readlines()
121-
filename = path.name
122-
documented_errors[filename] = set()
123-
for line in lines:
124-
for error_msg in re.findall(r"TRIO\d\d\d", line):
125-
documented_errors[filename].add(error_msg)
126-
127-
documented_errors["flake8_trio.py"] = set(ERROR_CODES)
128-
# check files for @error_class
129-
130-
# get tested error codes from file names and from `INCLUDE` lines
131-
documented_errors["eval_files"] = set()
132-
p = Path(__file__).parent / "eval_files"
133-
for file_path in p.iterdir():
134-
if not file_path.is_file():
135-
continue
136-
137-
if m := re.search(r"trio\d\d\d", str(file_path)):
138-
documented_errors["eval_files"].add(m.group().upper())
139-
140-
with open(file_path) as file:
141-
for line in file:
142-
if line.startswith("# ARG --enable"):
143-
for m in re.findall(r"trio\d\d\d", line, re.IGNORECASE):
144-
# pyright types m as `Any` (as it is in typeshed)
145-
# mypy types it as Optional[Match[str]]
146-
# but afaict it should be something like str|Tuple[str,...]
147-
# depending on whether there's a group in the pattern or not.
148-
# (or bytes, if both inputs are bytes)
149-
documented_errors["eval_files"].add(m) # type: ignore
150-
break
151-
152-
for errset in documented_errors.values():
153-
errset.difference_update(
154-
[c for c in errset if re.fullmatch(IGNORED_CODES_REGEX, c)]
155-
)
156-
157-
unique_errors: dict[str, set[str]] = {}
158-
missing_errors: dict[str, set[str]] = {}
159-
for key, codes in documented_errors.items():
160-
unique_errors[key] = codes.copy()
161-
missing_errors[key] = set()
162-
163-
for other_key, other_codes in documented_errors.items():
164-
if key == other_key:
165-
continue
166-
unique_errors[key].difference_update(other_codes)
167-
missing_errors[key].update(other_codes - codes)
168-
169-
assert unique_errors == missing_errors

tests/test_messages_documented.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python
2+
"""Tests for flake8-trio package metadata."""
3+
4+
from __future__ import annotations
5+
6+
import re
7+
from pathlib import Path
8+
from typing import cast
9+
10+
from .test_flake8_trio import ERROR_CODES
11+
12+
ROOT_PATH = Path(__file__).parent.parent
13+
CHANGELOG = ROOT_PATH / "CHANGELOG.md"
14+
README = CHANGELOG.parent / "README.md"
15+
16+
# 107 & 108 are removed (but still mentioned in changelog & readme)
17+
# TRIOxxx_* are fake codes to get different error messages for the same code
18+
IGNORED_CODES_REGEX = r"TRIO107|TRIO108|TRIO\d\d\d_.*"
19+
20+
21+
def test_messages_documented():
22+
documented_errors: dict[str, set[str]] = {}
23+
for path in (CHANGELOG, README):
24+
with open(path, encoding="utf-8") as f:
25+
lines = f.readlines()
26+
filename = path.name
27+
documented_errors[filename] = set()
28+
for line in lines:
29+
for error_msg in re.findall(r"TRIO\d\d\d", line):
30+
documented_errors[filename].add(error_msg)
31+
32+
documented_errors["flake8_trio.py"] = set(ERROR_CODES)
33+
34+
# get tested error codes from file names and from `INCLUDE` lines
35+
documented_errors["eval_files"] = set()
36+
p = Path(__file__).parent / "eval_files"
37+
for file_path in p.iterdir():
38+
if not file_path.is_file():
39+
continue
40+
41+
if m := re.search(r"trio\d\d\d", str(file_path)):
42+
documented_errors["eval_files"].add(m.group().upper())
43+
44+
with open(file_path) as file:
45+
for line in file:
46+
if line.startswith("# ARG --enable"):
47+
for m in re.findall(r"trio\d\d\d", line, re.IGNORECASE):
48+
# pyright types m as `Any` (as it is in typeshed)
49+
# mypy types it as Optional[Match[str]]
50+
# but afaict it should be something like str|Tuple[str,...]
51+
# depending on whether there's a group in the pattern or not.
52+
# (or bytes, if both inputs are bytes)
53+
documented_errors["eval_files"].add(cast("str", m))
54+
break
55+
56+
for errset in documented_errors.values():
57+
errset.difference_update(
58+
[c for c in errset if re.fullmatch(IGNORED_CODES_REGEX, c)]
59+
)
60+
61+
unique_errors: dict[str, set[str]] = {}
62+
missing_errors: dict[str, set[str]] = {}
63+
for key, codes in documented_errors.items():
64+
unique_errors[key] = codes.copy()
65+
missing_errors[key] = set()
66+
67+
for other_key, other_codes in documented_errors.items():
68+
if key == other_key:
69+
continue
70+
unique_errors[key].difference_update(other_codes)
71+
missing_errors[key].update(other_codes - codes)
72+
73+
assert unique_errors == missing_errors

0 commit comments

Comments
 (0)