Skip to content

Commit 502fa95

Browse files
Clean up fixtures
1 parent d9685f7 commit 502fa95

31 files changed

Lines changed: 489 additions & 255 deletions

src/test/analyzer.test.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const getWasmPaths = () => {
1212
}
1313
}
1414

15-
// Fixtures are in src/test/fixtures/python
15+
// Fixtures are in src/test/fixtures
1616
const getFixturesPath = () => {
17-
return path.join(__dirname, "..", "..", "src", "test", "fixtures", "python")
17+
return path.join(__dirname, "..", "..", "src", "test", "fixtures")
1818
}
1919

2020
suite("analyzer", () => {
@@ -130,7 +130,8 @@ import os
130130

131131
suite("analyzeFile", () => {
132132
test("analyzes main.py fixture", () => {
133-
const mainPyPath = path.join(fixturesPath, "main.py")
133+
const standardPath = path.join(fixturesPath, "standard")
134+
const mainPyPath = path.join(standardPath, "app", "main.py")
134135
const result = analyzeFile(mainPyPath, parser)
135136

136137
assert.ok(result)
@@ -141,7 +142,7 @@ import os
141142
assert.ok(fastApiRouter)
142143
assert.strictEqual(fastApiRouter.variableName, "app")
143144

144-
// Should find include_router call
145+
// Should find include_router calls
145146
assert.ok(result.includeRouters.length > 0)
146147

147148
// Should find health check route
@@ -151,13 +152,8 @@ import os
151152
})
152153

153154
test("analyzes users.py fixture", () => {
154-
const usersPath = path.join(
155-
fixturesPath,
156-
"app",
157-
"api",
158-
"routes",
159-
"users.py",
160-
)
155+
const standardPath = path.join(fixturesPath, "standard")
156+
const usersPath = path.join(standardPath, "app", "routes", "users.py")
161157
const result = analyzeFile(usersPath, parser)
162158

163159
assert.ok(result)
@@ -166,15 +162,13 @@ import os
166162
const apiRouter = result.routers.find((r) => r.type === "APIRouter")
167163
assert.ok(apiRouter)
168164

169-
// Should find multiple routes
170-
assert.ok(result.routes.length >= 5)
165+
// Should find routes (users.py has 3 routes: list, get, create)
166+
assert.ok(result.routes.length >= 3)
171167

172-
// Check specific routes
168+
// Check specific routes exist
173169
const methods = result.routes.map((r) => r.method)
174170
assert.ok(methods.includes("get"))
175171
assert.ok(methods.includes("post"))
176-
assert.ok(methods.includes("put"))
177-
assert.ok(methods.includes("delete"))
178172
})
179173

180174
test("returns null for non-existent file", () => {

src/test/fixtures/flat/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from fastapi import FastAPI
2+
3+
from routes import router
4+
5+
app = FastAPI(title="Flat Layout")
6+
7+
app.include_router(router)
8+
9+
10+
@app.get("/")
11+
def root():
12+
return {"message": "Hello from flat layout"}

src/test/fixtures/flat/routes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from fastapi import APIRouter
2+
3+
router = APIRouter(prefix="/api", tags=["api"])
4+
5+
6+
@router.get("/users")
7+
def list_users():
8+
return [{"id": 1, "name": "Alice"}]
9+
10+
11+
@router.get("/items")
12+
def list_items():
13+
return [{"id": 1, "name": "Widget"}]

src/test/fixtures/namespace/app/__init__.py

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from fastapi import FastAPI
2+
3+
# Import from namespace package (no __init__.py in namespace_routes)
4+
from .namespace_routes import items, users
5+
6+
app = FastAPI(title="Namespace Package Layout")
7+
8+
app.include_router(users.router)
9+
app.include_router(items.router)
10+
11+
12+
@app.get("/")
13+
def root():
14+
return {"message": "Hello from namespace package layout"}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Note: namespace_routes has NO __init__.py (namespace package)
2+
from fastapi import APIRouter
3+
4+
router = APIRouter(prefix="/items", tags=["items"])
5+
6+
7+
@router.get("/")
8+
def list_items():
9+
return [{"id": 1, "name": "Widget"}]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Note: namespace_routes has NO __init__.py (namespace package)
2+
from fastapi import APIRouter
3+
4+
router = APIRouter(prefix="/users", tags=["users"])
5+
6+
7+
@router.get("/")
8+
def list_users():
9+
return [{"id": 1, "name": "Alice"}]
10+
11+
12+
@router.get("/{user_id}")
13+
def get_user(user_id: int):
14+
return {"id": user_id, "name": "Alice"}

src/test/fixtures/python/app/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/test/fixtures/python/app/api/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/test/fixtures/python/app/api/main.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)