diff --git a/tests/unit/test_detectors.py b/tests/unit/test_detectors.py index b472aa0..2127987 100644 --- a/tests/unit/test_detectors.py +++ b/tests/unit/test_detectors.py @@ -1,9 +1,7 @@ -"""Tests for endpoint detectors.""" - -import pytest -import tempfile import os +import tempfile from pathlib import Path + from docgen.models import HTTPMethod @@ -32,13 +30,13 @@ async def get_items(): with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f: f.write(code) f.flush() - + from docgen.detectors import PythonDetector detector = PythonDetector() endpoints = detector.detect_endpoints(Path(f.name)) - + os.unlink(f.name) - + assert len(endpoints) >= 3 methods = [e.method for e in endpoints] assert HTTPMethod.GET in methods @@ -63,13 +61,13 @@ def create_item(): with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f: f.write(code) f.flush() - + from docgen.detectors import PythonDetector detector = PythonDetector() endpoints = detector.detect_endpoints(Path(f.name)) - + os.unlink(f.name) - + assert len(endpoints) >= 2 def test_django_detection(self): @@ -86,13 +84,13 @@ urlpatterns = [ with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f: f.write(code) f.flush() - + from docgen.detectors import PythonDetector detector = PythonDetector() endpoints = detector.detect_endpoints(Path(f.name)) - + os.unlink(f.name) - + assert len(endpoints) == 2 assert endpoints[0].path == "users/" assert endpoints[1].path == "users//" @@ -118,13 +116,13 @@ router.post("/users", (req, res) => { with tempfile.NamedTemporaryFile(mode='w', suffix='.js', delete=False) as f: f.write(code) f.flush() - + from docgen.detectors import JavaScriptDetector detector = JavaScriptDetector() endpoints = detector.detect_endpoints(Path(f.name)) - + os.unlink(f.name) - + assert len(endpoints) >= 2 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: f.write(code) f.flush() - + from docgen.detectors import JavaScriptDetector detector = JavaScriptDetector() endpoints = detector.detect_endpoints(Path(f.name)) - + os.unlink(f.name) - + assert len(endpoints) >= 2 @@ -178,13 +176,13 @@ func main() { with tempfile.NamedTemporaryFile(mode='w', suffix='.go', delete=False) as f: f.write(code) f.flush() - + from docgen.detectors import GoDetector detector = GoDetector() endpoints = detector.detect_endpoints(Path(f.name)) - + os.unlink(f.name) - + assert len(endpoints) >= 2 def test_chi_detection(self): @@ -209,13 +207,13 @@ func main() { with tempfile.NamedTemporaryFile(mode='w', suffix='.go', delete=False) as f: f.write(code) f.flush() - + from docgen.detectors import GoDetector detector = GoDetector() endpoints = detector.detect_endpoints(Path(f.name)) - + os.unlink(f.name) - + assert len(endpoints) >= 2 @@ -240,13 +238,13 @@ async fn create_user() -> HttpResponse { with tempfile.NamedTemporaryFile(mode='w', suffix='.rs', delete=False) as f: f.write(code) f.flush() - + from docgen.detectors import RustDetector detector = RustDetector() endpoints = detector.detect_endpoints(Path(f.name)) - + os.unlink(f.name) - + assert len(endpoints) >= 0 @@ -255,11 +253,11 @@ class TestBaseDetector: def test_can_detect(self): """Test file extension detection.""" - from docgen.detectors import PythonDetector, JavaScriptDetector - + from docgen.detectors import JavaScriptDetector, PythonDetector + py_detector = PythonDetector() js_detector = JavaScriptDetector() - + assert py_detector.can_detect(Path("test.py")) is True assert py_detector.can_detect(Path("test.js")) is False assert js_detector.can_detect(Path("test.ts")) is True