55
66import re
77import sys
8- import unittest
98from pathlib import Path
109from typing import TYPE_CHECKING , NamedTuple , TypeVar
1110
12- import flake8_trio
13-
14- from .test_flake8_trio import ERROR_CODES
15-
1611if TYPE_CHECKING :
1712 from collections .abc import Iterable
1813
1914ROOT_PATH = Path (__file__ ).parent .parent
2015CHANGELOG = 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
2319T = 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
4241def 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
0 commit comments