Skip to content

Commit e8db650

Browse files
iscai-msftCopilot
andcommitted
test(emitter): cover model-only generation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent f6cedca commit e8db650

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
import { listServices } from "@typespec/compiler";
21
import { expectDiagnostics, t } from "@typespec/compiler/testing";
3-
import { it } from "vitest";
4-
import { reportDiagnostic } from "../src/lib.js";
5-
import { Tester } from "./test-host.js";
2+
import { expect } from "vitest";
3+
import { EmitterTester } from "./test-host.js";
64

75
it("targets the service namespace when no SDK clients are found", async () => {
8-
const { program } = await Tester.compile(t.code`
6+
const [, diagnostics] = await EmitterTester.compileAndDiagnose(t.code`
97
#suppress "@typespec/http-client-python/no-sdk-clients" "This service intentionally has no client."
108
@service namespace ${t.namespace("Service")} {}
119
`);
1210

13-
reportDiagnostic(program, {
14-
code: "no-sdk-clients",
15-
target: listServices(program)[0]?.type ?? program.getGlobalNamespaceType(),
16-
});
17-
expectDiagnostics(program.diagnostics, []);
11+
expectDiagnostics(diagnostics, []);
1812
});
1913

20-
it("allows suppressing the warning when no service exists", async () => {
21-
const { program } = await Tester.compile(`
14+
it("generates models when no service exists", async () => {
15+
const [result, diagnostics] = await EmitterTester.compileAndDiagnose(`
2216
#suppress "@typespec/http-client-python/no-sdk-clients" "This model-only package intentionally has no client."
23-
model Widget {}
17+
namespace Models {
18+
model Widget {}
19+
}
2420
`);
2521

26-
reportDiagnostic(program, {
27-
code: "no-sdk-clients",
28-
target: listServices(program)[0]?.type ?? program.getGlobalNamespaceType(),
29-
});
30-
expectDiagnostics(program.diagnostics, []);
22+
expectDiagnostics(diagnostics, []);
23+
expect(
24+
Object.entries(result.outputs).some(
25+
([path, content]) => path.endsWith("models/_models.py") && content.includes("class Widget"),
26+
),
27+
).toBe(true);
3128
});

packages/http-client-python/emitter/test/test-host.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ import { createTester } from "@typespec/compiler/testing";
44
const PythonTester = createTester(resolvePath(import.meta.dirname, "../.."), { libraries: [] });
55

66
export const Tester = PythonTester;
7+
export const EmitterTester = PythonTester.emit("@typespec/http-client-python", {
8+
"generate-packaging-files": false,
9+
"use-pyodide": true,
10+
});

0 commit comments

Comments
 (0)