]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
ignore ruff for generated sync tests
authorKar Petrosyan <kar.petrosyanpy@gmail.com>
Thu, 27 Feb 2025 16:56:49 +0000 (20:56 +0400)
committerKar Petrosyan <kar.petrosyanpy@gmail.com>
Thu, 27 Feb 2025 16:56:49 +0000 (20:56 +0400)
pyproject.toml
scripts/unasync.py

index 675d2ad4c675cd6cc1669d66ce71f8af514a75b0..196149c774d2e486b22d0cbc13d3593577d73020 100644 (file)
@@ -96,6 +96,9 @@ text = "\n---\n\n[Full changelog](https://github.com/encode/httpx/blob/master/CH
 pattern = 'src="(docs/img/.*?)"'
 replacement = 'src="https://raw.githubusercontent.com/encode/httpx/master/\1"'
 
+[tool.ruff]
+exclude = ["tests/client/sync"]
+
 [tool.ruff.lint]
 select = ["E", "F", "I", "B", "PIE"]
 ignore = ["B904", "B028"]
@@ -129,5 +132,5 @@ markers = [
 ]
 
 [tool.coverage.run]
-omit = ["venv/*"]
+omit = ["venv/*", "tests/client/sync*"]
 include = ["httpx/*", "tests/*"]
index 6d1276389c0d5d33499e3b6b5b1433a19c9669c8..dbd30b80c0f8ad69c8d4dc4a6e372495a541621f 100755 (executable)
@@ -6,31 +6,31 @@ from pprint import pprint
 
 SUBS = [
     # httpx specific
-    ('AsyncByteStream', 'SyncByteStream'),
-    ('async_auth_flow', 'sync_auth_flow'),
-    ('handle_async_request', 'handle_request'),
+    ("AsyncByteStream", "SyncByteStream"),
+    ("async_auth_flow", "sync_auth_flow"),
+    ("handle_async_request", "handle_request"),
     # general
-    ('AsyncIterator', 'Iterator'),
-    ('from anyio import Lock', 'from threading import Lock'),
-    ('Async([A-Z][A-Za-z0-9_]*)', r'\2'),
-    ('async def', 'def'),
-    ('async with', 'with'),
-    ('async for', 'for'),
-    ('await ', ''),
-    ('aclose', 'close'),
-    ('aread', 'read'),
-    ('__aenter__', '__enter__'),
-    ('__aexit__', '__exit__'),
-    ('__aiter__', '__iter__'),
-    ('@pytest.mark.anyio', ''),
+    ("AsyncIterator", "Iterator"),
+    ("from anyio import Lock", "from threading import Lock"),
+    ("Async([A-Z][A-Za-z0-9_]*)", r"\2"),
+    ("async def", "def"),
+    ("async with", "with"),
+    ("async for", "for"),
+    ("await ", ""),
+    ("aclose", "close"),
+    ("aread", "read"),
+    ("__aenter__", "__enter__"),
+    ("__aexit__", "__exit__"),
+    ("__aiter__", "__iter__"),
+    ("@pytest.mark.anyio", ""),
 ]
 COMPILED_SUBS = [
-    (re.compile(r'(^|\b)' + regex + r'($|\b)'), repl)
-    for regex, repl in SUBS
+    (re.compile(r"(^|\b)" + regex + r"($|\b)"), repl) for regex, repl in SUBS
 ]
 
 USED_SUBS = set()
 
+
 def unasync_line(line):
     for index, (regex, repl) in enumerate(COMPILED_SUBS):
         old_line = line
@@ -54,22 +54,22 @@ def unasync_file_check(in_path, out_path):
             for in_line, out_line in zip(in_file.readlines(), out_file.readlines()):
                 expected = unasync_line(in_line)
                 if out_line != expected:
-                    print(f'unasync mismatch between {in_path!r} and {out_path!r}')
-                    print(f'Async code:         {in_line!r}')
-                    print(f'Expected sync code: {expected!r}')
-                    print(f'Actual sync code:   {out_line!r}')
+                    print(f"unasync mismatch between {in_path!r} and {out_path!r}")
+                    print(f"Async code:         {in_line!r}")
+                    print(f"Expected sync code: {expected!r}")
+                    print(f"Actual sync code:   {out_line!r}")
                     sys.exit(1)
 
 
 def unasync_dir(in_dir, out_dir, check_only=False):
     for dirpath, dirnames, filenames in os.walk(in_dir):
         for filename in filenames:
-            if not filename.endswith('.py'):
+            if not filename.endswith(".py"):
                 continue
             rel_dir = os.path.relpath(dirpath, in_dir)
             in_path = os.path.normpath(os.path.join(in_dir, rel_dir, filename))
             out_path = os.path.normpath(os.path.join(out_dir, rel_dir, filename))
-            print(in_path, '->', out_path)
+            print(in_path, "->", out_path)
             if check_only:
                 unasync_file_check(in_path, out_path)
             else:
@@ -77,7 +77,7 @@ def unasync_dir(in_dir, out_dir, check_only=False):
 
 
 def main():
-    check_only = '--check' in sys.argv
+    check_only = "--check" in sys.argv
     unasync_dir("tests/client/async", "tests/client/sync", check_only=check_only)
 
     if len(USED_SUBS) != len(SUBS):
@@ -85,8 +85,8 @@ def main():
 
         print("These patterns were not used:")
         pprint(unused_subs)
-        exit(1)   
-        
+        exit(1)
+
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     main()