fix: resolve CI linting failures in test files
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
"""Tests for endpoint detectors."""
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
import tempfile
|
|
||||||
import os
|
import os
|
||||||
|
import tempfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from docgen.models import HTTPMethod
|
from docgen.models import HTTPMethod
|
||||||
|
|
||||||
|
|
||||||
@@ -32,13 +30,13 @@ async def get_items():
|
|||||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
|
||||||
f.write(code)
|
f.write(code)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
from docgen.detectors import PythonDetector
|
from docgen.detectors import PythonDetector
|
||||||
detector = PythonDetector()
|
detector = PythonDetector()
|
||||||
endpoints = detector.detect_endpoints(Path(f.name))
|
endpoints = detector.detect_endpoints(Path(f.name))
|
||||||
|
|
||||||
os.unlink(f.name)
|
os.unlink(f.name)
|
||||||
|
|
||||||
assert len(endpoints) >= 3
|
assert len(endpoints) >= 3
|
||||||
methods = [e.method for e in endpoints]
|
methods = [e.method for e in endpoints]
|
||||||
assert HTTPMethod.GET in methods
|
assert HTTPMethod.GET in methods
|
||||||
@@ -63,13 +61,13 @@ def create_item():
|
|||||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
|
||||||
f.write(code)
|
f.write(code)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
from docgen.detectors import PythonDetector
|
from docgen.detectors import PythonDetector
|
||||||
detector = PythonDetector()
|
detector = PythonDetector()
|
||||||
endpoints = detector.detect_endpoints(Path(f.name))
|
endpoints = detector.detect_endpoints(Path(f.name))
|
||||||
|
|
||||||
os.unlink(f.name)
|
os.unlink(f.name)
|
||||||
|
|
||||||
assert len(endpoints) >= 2
|
assert len(endpoints) >= 2
|
||||||
|
|
||||||
def test_django_detection(self):
|
def test_django_detection(self):
|
||||||
@@ -86,13 +84,13 @@ urlpatterns = [
|
|||||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
|
||||||
f.write(code)
|
f.write(code)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
from docgen.detectors import PythonDetector
|
from docgen.detectors import PythonDetector
|
||||||
detector = PythonDetector()
|
detector = PythonDetector()
|
||||||
endpoints = detector.detect_endpoints(Path(f.name))
|
endpoints = detector.detect_endpoints(Path(f.name))
|
||||||
|
|
||||||
os.unlink(f.name)
|
os.unlink(f.name)
|
||||||
|
|
||||||
assert len(endpoints) == 2
|
assert len(endpoints) == 2
|
||||||
assert endpoints[0].path == "users/"
|
assert endpoints[0].path == "users/"
|
||||||
assert endpoints[1].path == "users/<int:pk>/"
|
assert endpoints[1].path == "users/<int:pk>/"
|
||||||
@@ -118,13 +116,13 @@ router.post("/users", (req, res) => {
|
|||||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.js', delete=False) as f:
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.js', delete=False) as f:
|
||||||
f.write(code)
|
f.write(code)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
from docgen.detectors import JavaScriptDetector
|
from docgen.detectors import JavaScriptDetector
|
||||||
detector = JavaScriptDetector()
|
detector = JavaScriptDetector()
|
||||||
endpoints = detector.detect_endpoints(Path(f.name))
|
endpoints = detector.detect_endpoints(Path(f.name))
|
||||||
|
|
||||||
os.unlink(f.name)
|
os.unlink(f.name)
|
||||||
|
|
||||||
assert len(endpoints) >= 2
|
assert len(endpoints) >= 2
|
||||||
|
|
||||||
def test_fastify_detection(self):
|
def test_fastify_detection(self):
|
||||||
@@ -143,13 +141,13 @@ fastify.post("/items", async (request, reply) => {
|
|||||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.js', delete=False) as f:
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.js', delete=False) as f:
|
||||||
f.write(code)
|
f.write(code)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
from docgen.detectors import JavaScriptDetector
|
from docgen.detectors import JavaScriptDetector
|
||||||
detector = JavaScriptDetector()
|
detector = JavaScriptDetector()
|
||||||
endpoints = detector.detect_endpoints(Path(f.name))
|
endpoints = detector.detect_endpoints(Path(f.name))
|
||||||
|
|
||||||
os.unlink(f.name)
|
os.unlink(f.name)
|
||||||
|
|
||||||
assert len(endpoints) >= 2
|
assert len(endpoints) >= 2
|
||||||
|
|
||||||
|
|
||||||
@@ -178,13 +176,13 @@ func main() {
|
|||||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.go', delete=False) as f:
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.go', delete=False) as f:
|
||||||
f.write(code)
|
f.write(code)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
from docgen.detectors import GoDetector
|
from docgen.detectors import GoDetector
|
||||||
detector = GoDetector()
|
detector = GoDetector()
|
||||||
endpoints = detector.detect_endpoints(Path(f.name))
|
endpoints = detector.detect_endpoints(Path(f.name))
|
||||||
|
|
||||||
os.unlink(f.name)
|
os.unlink(f.name)
|
||||||
|
|
||||||
assert len(endpoints) >= 2
|
assert len(endpoints) >= 2
|
||||||
|
|
||||||
def test_chi_detection(self):
|
def test_chi_detection(self):
|
||||||
@@ -209,13 +207,13 @@ func main() {
|
|||||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.go', delete=False) as f:
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.go', delete=False) as f:
|
||||||
f.write(code)
|
f.write(code)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
from docgen.detectors import GoDetector
|
from docgen.detectors import GoDetector
|
||||||
detector = GoDetector()
|
detector = GoDetector()
|
||||||
endpoints = detector.detect_endpoints(Path(f.name))
|
endpoints = detector.detect_endpoints(Path(f.name))
|
||||||
|
|
||||||
os.unlink(f.name)
|
os.unlink(f.name)
|
||||||
|
|
||||||
assert len(endpoints) >= 2
|
assert len(endpoints) >= 2
|
||||||
|
|
||||||
|
|
||||||
@@ -240,13 +238,13 @@ async fn create_user() -> HttpResponse {
|
|||||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.rs', delete=False) as f:
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.rs', delete=False) as f:
|
||||||
f.write(code)
|
f.write(code)
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
from docgen.detectors import RustDetector
|
from docgen.detectors import RustDetector
|
||||||
detector = RustDetector()
|
detector = RustDetector()
|
||||||
endpoints = detector.detect_endpoints(Path(f.name))
|
endpoints = detector.detect_endpoints(Path(f.name))
|
||||||
|
|
||||||
os.unlink(f.name)
|
os.unlink(f.name)
|
||||||
|
|
||||||
assert len(endpoints) >= 0
|
assert len(endpoints) >= 0
|
||||||
|
|
||||||
|
|
||||||
@@ -255,11 +253,11 @@ class TestBaseDetector:
|
|||||||
|
|
||||||
def test_can_detect(self):
|
def test_can_detect(self):
|
||||||
"""Test file extension detection."""
|
"""Test file extension detection."""
|
||||||
from docgen.detectors import PythonDetector, JavaScriptDetector
|
from docgen.detectors import JavaScriptDetector, PythonDetector
|
||||||
|
|
||||||
py_detector = PythonDetector()
|
py_detector = PythonDetector()
|
||||||
js_detector = JavaScriptDetector()
|
js_detector = JavaScriptDetector()
|
||||||
|
|
||||||
assert py_detector.can_detect(Path("test.py")) is True
|
assert py_detector.can_detect(Path("test.py")) is True
|
||||||
assert py_detector.can_detect(Path("test.js")) is False
|
assert py_detector.can_detect(Path("test.js")) is False
|
||||||
assert js_detector.can_detect(Path("test.ts")) is True
|
assert js_detector.can_detect(Path("test.ts")) is True
|
||||||
|
|||||||
Reference in New Issue
Block a user