@alloy-js/python 0.5.0-dev.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/dev/src/components/CallSignature.js +2 -2
  3. package/dist/dev/src/components/CallSignature.js.map +1 -1
  4. package/dist/dev/src/components/ConstructorDeclaration.js +1 -1
  5. package/dist/dev/src/components/ConstructorDeclaration.js.map +1 -1
  6. package/dist/dev/src/components/DataclassDeclaration.js +5 -5
  7. package/dist/dev/src/components/DataclassDeclaration.js.map +1 -1
  8. package/dist/dev/src/components/FunctionBase.js +9 -9
  9. package/dist/dev/src/components/FunctionBase.js.map +1 -1
  10. package/dist/dev/src/components/PropertyDeclaration.js +8 -8
  11. package/dist/dev/src/components/PropertyDeclaration.js.map +1 -1
  12. package/dist/dev/src/components/PyDoc.js +64 -64
  13. package/dist/dev/src/components/PyDoc.js.map +1 -1
  14. package/dist/dev/src/components/PydanticClassDeclaration.js +5 -5
  15. package/dist/dev/src/components/PydanticClassDeclaration.js.map +1 -1
  16. package/dist/dev/src/components/SourceFile.js +44 -32
  17. package/dist/dev/src/components/SourceFile.js.map +1 -1
  18. package/dist/dev/src/symbols/python-output-symbol.js.map +1 -1
  19. package/dist/dev/test/callsignatures.test.js +471 -297
  20. package/dist/dev/test/callsignatures.test.js.map +1 -1
  21. package/dist/dev/test/class-method-declaration.test.js +21 -10
  22. package/dist/dev/test/class-method-declaration.test.js.map +1 -1
  23. package/dist/dev/test/classdeclarations.test.js +459 -393
  24. package/dist/dev/test/classdeclarations.test.js.map +1 -1
  25. package/dist/dev/test/classinstantiations.test.js +201 -168
  26. package/dist/dev/test/classinstantiations.test.js.map +1 -1
  27. package/dist/dev/test/constructordeclaration.test.js +22 -11
  28. package/dist/dev/test/constructordeclaration.test.js.map +1 -1
  29. package/dist/dev/test/dataclassdeclarations.test.js +322 -368
  30. package/dist/dev/test/dataclassdeclarations.test.js.map +1 -1
  31. package/dist/dev/test/decoratorlist.test.js +96 -49
  32. package/dist/dev/test/decoratorlist.test.js.map +1 -1
  33. package/dist/dev/test/dundermethoddeclaration.test.js +22 -11
  34. package/dist/dev/test/dundermethoddeclaration.test.js.map +1 -1
  35. package/dist/dev/test/enums.test.js +218 -184
  36. package/dist/dev/test/enums.test.js.map +1 -1
  37. package/dist/dev/test/externals.test.js +57 -45
  38. package/dist/dev/test/externals.test.js.map +1 -1
  39. package/dist/dev/test/factories.test.js +124 -50
  40. package/dist/dev/test/factories.test.js.map +1 -1
  41. package/dist/dev/test/functioncallexpressions.test.js +199 -164
  42. package/dist/dev/test/functioncallexpressions.test.js.map +1 -1
  43. package/dist/dev/test/functiondeclaration.test.js +439 -272
  44. package/dist/dev/test/functiondeclaration.test.js.map +1 -1
  45. package/dist/dev/test/imports.test.js +273 -221
  46. package/dist/dev/test/imports.test.js.map +1 -1
  47. package/dist/dev/test/memberexpressions.test.js +1237 -972
  48. package/dist/dev/test/memberexpressions.test.js.map +1 -1
  49. package/dist/dev/test/methoddeclaration.test.js +142 -78
  50. package/dist/dev/test/methoddeclaration.test.js.map +1 -1
  51. package/dist/dev/test/namepolicies.test.js +130 -94
  52. package/dist/dev/test/namepolicies.test.js.map +1 -1
  53. package/dist/dev/test/propertydeclaration.test.js +88 -59
  54. package/dist/dev/test/propertydeclaration.test.js.map +1 -1
  55. package/dist/dev/test/pydanticclassdeclarations.test.js +299 -347
  56. package/dist/dev/test/pydanticclassdeclarations.test.js.map +1 -1
  57. package/dist/dev/test/pydocs.test.js +888 -715
  58. package/dist/dev/test/pydocs.test.js.map +1 -1
  59. package/dist/dev/test/references.test.js +42 -35
  60. package/dist/dev/test/references.test.js.map +1 -1
  61. package/dist/dev/test/sourcefiles.test.js +1109 -841
  62. package/dist/dev/test/sourcefiles.test.js.map +1 -1
  63. package/dist/dev/test/staticmethoddeclaration.test.js +21 -10
  64. package/dist/dev/test/staticmethoddeclaration.test.js.map +1 -1
  65. package/dist/dev/test/type-checking-imports.test.js +408 -359
  66. package/dist/dev/test/type-checking-imports.test.js.map +1 -1
  67. package/dist/dev/test/typereference.test.js +55 -40
  68. package/dist/dev/test/typereference.test.js.map +1 -1
  69. package/dist/dev/test/uniontypeexpression.test.js +222 -146
  70. package/dist/dev/test/uniontypeexpression.test.js.map +1 -1
  71. package/dist/dev/test/utils.js +39 -77
  72. package/dist/dev/test/utils.js.map +1 -1
  73. package/dist/dev/test/values.test.js +237 -101
  74. package/dist/dev/test/values.test.js.map +1 -1
  75. package/dist/dev/test/variables.test.js +321 -203
  76. package/dist/dev/test/variables.test.js.map +1 -1
  77. package/dist/dev/test/vitest.setup.js +2 -0
  78. package/dist/dev/test/vitest.setup.js.map +1 -0
  79. package/dist/src/components/CallSignature.d.ts.map +1 -1
  80. package/dist/src/components/CallSignature.js.map +1 -1
  81. package/dist/src/components/ConstructorDeclaration.d.ts.map +1 -1
  82. package/dist/src/components/ConstructorDeclaration.js.map +1 -1
  83. package/dist/src/components/DataclassDeclaration.d.ts.map +1 -1
  84. package/dist/src/components/DataclassDeclaration.js.map +1 -1
  85. package/dist/src/components/FunctionBase.d.ts.map +1 -1
  86. package/dist/src/components/FunctionBase.js.map +1 -1
  87. package/dist/src/components/PropertyDeclaration.d.ts.map +1 -1
  88. package/dist/src/components/PropertyDeclaration.js.map +1 -1
  89. package/dist/src/components/PyDoc.d.ts.map +1 -1
  90. package/dist/src/components/PyDoc.js.map +1 -1
  91. package/dist/src/components/PydanticClassDeclaration.d.ts.map +1 -1
  92. package/dist/src/components/PydanticClassDeclaration.js.map +1 -1
  93. package/dist/src/components/SourceFile.d.ts +2 -2
  94. package/dist/src/components/SourceFile.d.ts.map +1 -1
  95. package/dist/src/components/SourceFile.js +12 -0
  96. package/dist/src/components/SourceFile.js.map +1 -1
  97. package/dist/src/symbols/python-output-symbol.d.ts.map +1 -1
  98. package/dist/src/symbols/python-output-symbol.js.map +1 -1
  99. package/dist/test/callsignatures.test.js +346 -272
  100. package/dist/test/callsignatures.test.js.map +1 -1
  101. package/dist/test/class-method-declaration.test.js +7 -4
  102. package/dist/test/class-method-declaration.test.js.map +1 -1
  103. package/dist/test/classdeclarations.test.js +302 -288
  104. package/dist/test/classdeclarations.test.js.map +1 -1
  105. package/dist/test/classinstantiations.test.js +112 -103
  106. package/dist/test/classinstantiations.test.js.map +1 -1
  107. package/dist/test/constructordeclaration.test.js +7 -4
  108. package/dist/test/constructordeclaration.test.js.map +1 -1
  109. package/dist/test/dataclassdeclarations.test.js +134 -184
  110. package/dist/test/dataclassdeclarations.test.js.map +1 -1
  111. package/dist/test/decoratorlist.test.js +59 -36
  112. package/dist/test/decoratorlist.test.js.map +1 -1
  113. package/dist/test/dundermethoddeclaration.test.js +7 -4
  114. package/dist/test/dundermethoddeclaration.test.js.map +1 -1
  115. package/dist/test/enums.test.js +161 -159
  116. package/dist/test/enums.test.js.map +1 -1
  117. package/dist/test/externals.test.js +24 -24
  118. package/dist/test/externals.test.js.map +1 -1
  119. package/dist/test/factories.test.js +75 -33
  120. package/dist/test/factories.test.js.map +1 -1
  121. package/dist/test/functioncallexpressions.test.js +117 -106
  122. package/dist/test/functioncallexpressions.test.js.map +1 -1
  123. package/dist/test/functiondeclaration.test.js +247 -180
  124. package/dist/test/functiondeclaration.test.js.map +1 -1
  125. package/dist/test/imports.test.js +171 -143
  126. package/dist/test/imports.test.js.map +1 -1
  127. package/dist/test/memberexpressions.test.js +582 -453
  128. package/dist/test/memberexpressions.test.js.map +1 -1
  129. package/dist/test/methoddeclaration.test.js +66 -46
  130. package/dist/test/methoddeclaration.test.js.map +1 -1
  131. package/dist/test/namepolicies.test.js +90 -78
  132. package/dist/test/namepolicies.test.js.map +1 -1
  133. package/dist/test/propertydeclaration.test.js +25 -20
  134. package/dist/test/propertydeclaration.test.js.map +1 -1
  135. package/dist/test/pydanticclassdeclarations.test.js +134 -190
  136. package/dist/test/pydanticclassdeclarations.test.js.map +1 -1
  137. package/dist/test/pydocs.test.js +573 -532
  138. package/dist/test/pydocs.test.js.map +1 -1
  139. package/dist/test/references.test.js +31 -28
  140. package/dist/test/references.test.js.map +1 -1
  141. package/dist/test/sourcefiles.test.js +700 -580
  142. package/dist/test/sourcefiles.test.js.map +1 -1
  143. package/dist/test/staticmethoddeclaration.test.js +7 -4
  144. package/dist/test/staticmethoddeclaration.test.js.map +1 -1
  145. package/dist/test/type-checking-imports.test.js +297 -284
  146. package/dist/test/type-checking-imports.test.js.map +1 -1
  147. package/dist/test/typereference.test.js +29 -22
  148. package/dist/test/typereference.test.js.map +1 -1
  149. package/dist/test/uniontypeexpression.test.js +124 -88
  150. package/dist/test/uniontypeexpression.test.js.map +1 -1
  151. package/dist/test/utils.d.ts +10 -17
  152. package/dist/test/utils.d.ts.map +1 -1
  153. package/dist/test/utils.js +32 -74
  154. package/dist/test/utils.js.map +1 -1
  155. package/dist/test/values.test.js +135 -67
  156. package/dist/test/values.test.js.map +1 -1
  157. package/dist/test/variables.test.js +201 -151
  158. package/dist/test/variables.test.js.map +1 -1
  159. package/dist/test/vitest.setup.d.ts +2 -0
  160. package/dist/test/vitest.setup.d.ts.map +1 -0
  161. package/dist/test/vitest.setup.js +2 -0
  162. package/dist/test/vitest.setup.js.map +1 -0
  163. package/dist/tsconfig.tsbuildinfo +1 -1
  164. package/docs/api/components/FunctionalEnumDeclaration.md +3 -6
  165. package/docs/api/components/MemberExpression.md +1 -5
  166. package/docs/api/components/SourceFile.md +20 -8
  167. package/docs/api/components/index.md +0 -2
  168. package/docs/api/functions/isTypeRefContext.md +1 -1
  169. package/docs/api/index.md +2 -2
  170. package/docs/api/types/ReferenceProps.md +7 -0
  171. package/docs/api/types/TypeRefContextProps.md +7 -0
  172. package/docs/api/types/index.md +2 -0
  173. package/package.json +11 -10
  174. package/src/components/CallSignature.tsx +4 -2
  175. package/src/components/ConstructorDeclaration.tsx +4 -2
  176. package/src/components/DataclassDeclaration.tsx +1 -2
  177. package/src/components/FunctionBase.tsx +1 -2
  178. package/src/components/PropertyDeclaration.tsx +8 -4
  179. package/src/components/PyDoc.tsx +12 -6
  180. package/src/components/PydanticClassDeclaration.tsx +1 -2
  181. package/src/components/SourceFile.tsx +6 -1
  182. package/src/symbols/python-output-symbol.ts +1 -2
  183. package/temp/api.json +107 -61
  184. package/test/callsignatures.test.tsx +309 -283
  185. package/test/class-method-declaration.test.tsx +3 -4
  186. package/test/classdeclarations.test.tsx +263 -248
  187. package/test/classinstantiations.test.tsx +115 -109
  188. package/test/constructordeclaration.test.tsx +9 -6
  189. package/test/dataclassdeclarations.test.tsx +243 -361
  190. package/test/decoratorlist.test.tsx +78 -59
  191. package/test/dundermethoddeclaration.test.tsx +3 -4
  192. package/test/enums.test.tsx +65 -81
  193. package/test/externals.test.tsx +25 -25
  194. package/test/factories.test.tsx +64 -22
  195. package/test/functioncallexpressions.test.tsx +123 -109
  196. package/test/functiondeclaration.test.tsx +209 -148
  197. package/test/imports.test.tsx +119 -91
  198. package/test/memberexpressions.test.tsx +265 -207
  199. package/test/methoddeclaration.test.tsx +84 -63
  200. package/test/namepolicies.test.tsx +69 -69
  201. package/test/propertydeclaration.test.tsx +7 -8
  202. package/test/pydanticclassdeclarations.test.tsx +355 -487
  203. package/test/pydocs.test.tsx +531 -579
  204. package/test/references.test.tsx +24 -23
  205. package/test/sourcefiles.test.tsx +527 -492
  206. package/test/staticmethoddeclaration.test.tsx +3 -4
  207. package/test/type-checking-imports.test.tsx +206 -218
  208. package/test/typereference.test.tsx +15 -12
  209. package/test/uniontypeexpression.test.tsx +74 -61
  210. package/test/utils.tsx +26 -110
  211. package/test/values.test.tsx +82 -32
  212. package/test/variables.test.tsx +162 -142
  213. package/test/vitest.setup.ts +1 -0
  214. package/tsdoc-metadata.json +1 -1
  215. package/vitest.config.ts +4 -0
  216. package/docs/api/components/Reference.md +0 -31
  217. package/docs/api/components/TypeRefContext.md +0 -41
@@ -1,44 +1,47 @@
1
- import { d } from "@alloy-js/core/testing";
2
1
  import { describe, expect, it } from "vitest";
3
2
  import * as py from "../src/index.js";
4
3
  import { abcModule } from "../src/index.js";
5
- import { toSourceText } from "./utils.js";
4
+ import { TestOutput } from "./utils.js";
6
5
 
7
6
  describe("Method-like Declarations", () => {
8
7
  it("renders decorators above def", () => {
9
- const result = toSourceText([
10
- <py.ClassDeclaration name="MyClass">
11
- <py.MethodDeclaration
12
- name="with_decorator"
13
- decorators={["@some_decorator"]}
14
- >
15
- pass
16
- </py.MethodDeclaration>
17
- </py.ClassDeclaration>,
18
- ]);
19
- expect(result).toRenderTo(d`
8
+ expect(
9
+ <TestOutput>
10
+ <py.ClassDeclaration name="MyClass">
11
+ <py.MethodDeclaration
12
+ name="with_decorator"
13
+ decorators={["@some_decorator"]}
14
+ >
15
+ pass
16
+ </py.MethodDeclaration>
17
+ </py.ClassDeclaration>
18
+ </TestOutput>,
19
+ ).toRenderTo(
20
+ `
20
21
  class MyClass:
21
22
  @some_decorator
22
23
  def with_decorator(self):
23
24
  pass
24
25
 
25
26
 
26
-
27
- `);
27
+ `,
28
+ );
28
29
  });
29
30
 
30
31
  it("renders multiple decorators above def without blank lines", () => {
31
- const result = toSourceText([
32
- <py.ClassDeclaration name="MyClass">
33
- <py.MethodDeclaration
34
- name="with_decorators"
35
- decorators={["@outer", "@middle", "@inner"]}
36
- >
37
- pass
38
- </py.MethodDeclaration>
39
- </py.ClassDeclaration>,
40
- ]);
41
- expect(result).toRenderTo(d`
32
+ expect(
33
+ <TestOutput>
34
+ <py.ClassDeclaration name="MyClass">
35
+ <py.MethodDeclaration
36
+ name="with_decorators"
37
+ decorators={["@outer", "@middle", "@inner"]}
38
+ >
39
+ pass
40
+ </py.MethodDeclaration>
41
+ </py.ClassDeclaration>
42
+ </TestOutput>,
43
+ ).toRenderTo(
44
+ `
42
45
  class MyClass:
43
46
  @outer
44
47
  @middle
@@ -47,22 +50,24 @@ describe("Method-like Declarations", () => {
47
50
  pass
48
51
 
49
52
 
50
-
51
- `);
53
+ `,
54
+ );
52
55
  });
53
56
 
54
57
  it("renders multiple decorators above @classmethod without blank lines", () => {
55
- const result = toSourceText([
56
- <py.ClassDeclaration name="MyClass">
57
- <py.ClassMethodDeclaration
58
- name="with_decorators"
59
- decorators={["@outer", "@inner"]}
60
- >
61
- pass
62
- </py.ClassMethodDeclaration>
63
- </py.ClassDeclaration>,
64
- ]);
65
- expect(result).toRenderTo(d`
58
+ expect(
59
+ <TestOutput>
60
+ <py.ClassDeclaration name="MyClass">
61
+ <py.ClassMethodDeclaration
62
+ name="with_decorators"
63
+ decorators={["@outer", "@inner"]}
64
+ >
65
+ pass
66
+ </py.ClassMethodDeclaration>
67
+ </py.ClassDeclaration>
68
+ </TestOutput>,
69
+ ).toRenderTo(
70
+ `
66
71
  class MyClass:
67
72
  @outer
68
73
  @inner
@@ -71,24 +76,26 @@ describe("Method-like Declarations", () => {
71
76
  pass
72
77
 
73
78
 
74
-
75
- `);
79
+ `,
80
+ );
76
81
  });
77
82
 
78
83
  it("renders an instance function with a body", () => {
79
- const result = toSourceText([
80
- <py.ClassDeclaration name="MyClass">
81
- <py.MethodDeclaration name="bar">print('hi')</py.MethodDeclaration>
82
- </py.ClassDeclaration>,
83
- ]);
84
- expect(result).toRenderTo(d`
84
+ expect(
85
+ <TestOutput>
86
+ <py.ClassDeclaration name="MyClass">
87
+ <py.MethodDeclaration name="bar">print('hi')</py.MethodDeclaration>
88
+ </py.ClassDeclaration>
89
+ </TestOutput>,
90
+ ).toRenderTo(
91
+ `
85
92
  class MyClass:
86
93
  def bar(self):
87
94
  print('hi')
88
95
 
89
96
 
90
-
91
- `);
97
+ `,
98
+ );
92
99
  });
93
100
 
94
101
  it("can be an async method", () => {
@@ -104,13 +111,15 @@ describe("Method-like Declarations", () => {
104
111
  </py.StatementList>
105
112
  );
106
113
 
107
- expect(toSourceText([decl])).toBe(d`
114
+ expect(<TestOutput>{decl}</TestOutput>).toRenderTo(
115
+ `
108
116
  class MyClass:
109
117
  async def my_method(self) -> str:
110
118
  return "async result"
111
119
 
112
120
 
113
- `);
121
+ `,
122
+ );
114
123
  });
115
124
 
116
125
  it("can be an async class method", () => {
@@ -130,14 +139,16 @@ describe("Method-like Declarations", () => {
130
139
  </py.StatementList>
131
140
  );
132
141
 
133
- expect(toSourceText([decl])).toBe(d`
142
+ expect(<TestOutput>{decl}</TestOutput>).toRenderTo(
143
+ `
134
144
  class MyClass:
135
145
  @classmethod
136
146
  async def create_async(cls) -> MyClass:
137
147
  return cls()
138
148
 
139
149
 
140
- `);
150
+ `,
151
+ );
141
152
  });
142
153
 
143
154
  it("can be an async static method", () => {
@@ -153,14 +164,16 @@ describe("Method-like Declarations", () => {
153
164
  </py.StatementList>
154
165
  );
155
166
 
156
- expect(toSourceText([decl])).toBe(d`
167
+ expect(<TestOutput>{decl}</TestOutput>).toRenderTo(
168
+ `
157
169
  class MyClass:
158
170
  @staticmethod
159
171
  async def utility() -> str:
160
172
  return "utility result"
161
173
 
162
174
 
163
- `);
175
+ `,
176
+ );
164
177
  });
165
178
 
166
179
  it("renders method with parameters", () => {
@@ -173,13 +186,15 @@ describe("Method-like Declarations", () => {
173
186
  </py.ClassDeclaration>
174
187
  );
175
188
 
176
- expect(toSourceText([decl])).toBe(d`
189
+ expect(<TestOutput>{decl}</TestOutput>).toRenderTo(
190
+ `
177
191
  class MyClass:
178
192
  def foo(self, x: int):
179
193
  self.attribute = "value"
180
194
 
181
195
 
182
- `);
196
+ `,
197
+ );
183
198
  });
184
199
 
185
200
  it("renders class method with parameters", () => {
@@ -192,14 +207,16 @@ describe("Method-like Declarations", () => {
192
207
  </py.ClassDeclaration>
193
208
  );
194
209
 
195
- expect(toSourceText([decl])).toBe(d`
210
+ expect(<TestOutput>{decl}</TestOutput>).toRenderTo(
211
+ `
196
212
  class MyClass:
197
213
  @classmethod
198
214
  def foo(cls, x: int):
199
215
  self.attribute = "value"
200
216
 
201
217
 
202
- `);
218
+ `,
219
+ );
203
220
  });
204
221
 
205
222
  it("renders static method with parameters", () => {
@@ -212,14 +229,16 @@ describe("Method-like Declarations", () => {
212
229
  </py.ClassDeclaration>
213
230
  );
214
231
 
215
- expect(toSourceText([decl])).toBe(d`
232
+ expect(<TestOutput>{decl}</TestOutput>).toRenderTo(
233
+ `
216
234
  class MyClass:
217
235
  @staticmethod
218
236
  def foo(x: int):
219
237
  attribute = "value"
220
238
 
221
239
 
222
- `);
240
+ `,
241
+ );
223
242
  });
224
243
 
225
244
  it("renders abstract methods", () => {
@@ -248,7 +267,8 @@ describe("Method-like Declarations", () => {
248
267
  </py.StatementList>
249
268
  );
250
269
 
251
- expect(toSourceText([decl], { externals: [abcModule] })).toBe(d`
270
+ expect(<TestOutput externals={[abcModule]}>{decl}</TestOutput>).toRenderTo(
271
+ `
252
272
  from abc import abstractmethod
253
273
 
254
274
 
@@ -268,6 +288,7 @@ describe("Method-like Declarations", () => {
268
288
  pass
269
289
 
270
290
 
271
- `);
291
+ `,
292
+ );
272
293
  });
273
294
  });
@@ -1,25 +1,25 @@
1
- import { d } from "@alloy-js/core/testing";
2
1
  import { expect, it } from "vitest";
3
2
  import { enumModule } from "../src/builtins/python.js";
4
3
  import * as py from "../src/index.js";
5
- import { toSourceText } from "./utils.jsx";
4
+ import { TestOutput } from "./utils.js";
6
5
 
7
6
  it("correct formatting of class name", () => {
8
- const result = toSourceText([
9
- <py.ClassDeclaration name="a-really-WeirdClass-name" />,
10
- ]);
11
- const expected = d`
7
+ expect(
8
+ <TestOutput>
9
+ <py.ClassDeclaration name="a-really-WeirdClass-name" />
10
+ </TestOutput>,
11
+ ).toRenderTo(
12
+ `
12
13
  class AReallyWeirdClassName:
13
14
  pass
14
15
 
15
-
16
- `;
17
- expect(result).toRenderTo(expected);
16
+ `,
17
+ );
18
18
  });
19
19
 
20
20
  it("correct formatting of Enum name and EnumMember names", () => {
21
- const result = toSourceText(
22
- [
21
+ expect(
22
+ <TestOutput externals={[enumModule]}>
23
23
  <py.FunctionalEnumDeclaration
24
24
  name="priority"
25
25
  members={[
@@ -27,83 +27,83 @@ it("correct formatting of Enum name and EnumMember names", () => {
27
27
  { name: "Medium", value: 2 },
28
28
  { name: "lowValue", value: 3 },
29
29
  ]}
30
- />,
31
- ],
32
- { externals: [enumModule] },
33
- );
34
- const expected = d`
30
+ />
31
+ </TestOutput>,
32
+ ).toRenderTo(
33
+ `
35
34
  from enum import Enum
36
35
 
37
36
 
38
37
  Priority = Enum('Priority', {'HIGH' : 1, 'MEDIUM' : 2, 'LOW_VALUE' : 3})
39
- `;
40
- expect(result).toRenderTo(expected);
38
+ `,
39
+ );
41
40
  });
42
41
 
43
42
  it("renders a function with parameters", () => {
44
- const result = toSourceText([
45
- <py.FunctionDeclaration
46
- name="quirklyNamed-Function"
47
- parameters={[{ name: "a-parameter", type: "int" }]}
48
- args={true}
49
- kwargs={true}
50
- >
51
- print(x, y)
52
- </py.FunctionDeclaration>,
53
- ]);
54
- expect(result).toRenderTo(
55
- d`
43
+ expect(
44
+ <TestOutput>
45
+ <py.FunctionDeclaration
46
+ name="quirklyNamed-Function"
47
+ parameters={[{ name: "a-parameter", type: "int" }]}
48
+ args={true}
49
+ kwargs={true}
50
+ >
51
+ print(x, y)
52
+ </py.FunctionDeclaration>
53
+ </TestOutput>,
54
+ ).toRenderTo(
55
+ `
56
56
  def quirkly_named_function(a_parameter: int, *args, **kwargs):
57
57
  print(x, y)
58
58
 
59
-
60
59
  `,
61
60
  );
62
61
  });
63
62
 
64
63
  it("correct formatting of call signature parameters names", () => {
65
- const result = toSourceText([
66
- <py.CallSignatureParameters
67
- parameters={[
68
- { name: "this-is-a-number", type: "int" },
69
- {
70
- name: "andThisIsADict",
71
- type: "dict",
72
- },
73
- ]}
74
- />,
75
- ]);
76
- expect(result).toRenderTo(`this_is_a_number: int, and_this_is_a_dict: dict`);
64
+ expect(
65
+ <TestOutput>
66
+ <py.CallSignatureParameters
67
+ parameters={[
68
+ { name: "this-is-a-number", type: "int" },
69
+ {
70
+ name: "andThisIsADict",
71
+ type: "dict",
72
+ },
73
+ ]}
74
+ />
75
+ </TestOutput>,
76
+ ).toRenderTo(`this_is_a_number: int, and_this_is_a_dict: dict`);
77
77
  });
78
78
 
79
79
  it("correct formatting of call statement vars", () => {
80
- const result = toSourceText([
81
- <py.StatementList>
82
- <py.ClassInstantiation
83
- target={"test"}
84
- args={[
85
- <py.VariableDeclaration
86
- name="this-is-a-long-name"
87
- initializer={<py.Atom jsValue={"A name"} />}
88
- callStatementVar
89
- />,
90
- <py.VariableDeclaration
91
- name="andThisIsANumber"
92
- initializer={<py.Atom jsValue={42} />}
93
- callStatementVar
94
- />,
95
- ]}
96
- />
97
- </py.StatementList>,
98
- ]);
99
- expect(result).toRenderTo(
100
- `test(this_is_a_long_name="A name", and_this_is_a_number=42)`,
101
- );
80
+ expect(
81
+ <TestOutput>
82
+ <py.StatementList>
83
+ <py.ClassInstantiation
84
+ target={"test"}
85
+ args={[
86
+ <py.VariableDeclaration
87
+ name="this-is-a-long-name"
88
+ initializer={<py.Atom jsValue={"A name"} />}
89
+ callStatementVar
90
+ />,
91
+ <py.VariableDeclaration
92
+ name="andThisIsANumber"
93
+ initializer={<py.Atom jsValue={42} />}
94
+ callStatementVar
95
+ />,
96
+ ]}
97
+ />
98
+ </py.StatementList>
99
+ </TestOutput>,
100
+ ).toRenderTo(`test(this_is_a_long_name="A name", and_this_is_a_number=42)`);
102
101
  });
103
102
 
104
103
  it("correct formatting of variable name", () => {
105
- const res = toSourceText([
106
- <py.VariableDeclaration name="myVar" type="int" initializer={42} />,
107
- ]);
108
- expect(res).toBe(`my_var: int = 42`);
104
+ expect(
105
+ <TestOutput>
106
+ <py.VariableDeclaration name="myVar" type="int" initializer={42} />
107
+ </TestOutput>,
108
+ ).toRenderTo("my_var: int = 42");
109
109
  });
@@ -1,9 +1,8 @@
1
1
  import { Prose, code } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
3
2
  import { describe, expect, it } from "vitest";
4
3
  import * as py from "../src/index.js";
5
4
  import { abcModule } from "../src/index.js";
6
- import { toSourceText } from "./utils.js";
5
+ import { TestOutput } from "./utils.js";
7
6
 
8
7
  describe("PropertyDeclaration", () => {
9
8
  it("renders empty property, setter, deleter", () => {
@@ -20,7 +19,7 @@ describe("PropertyDeclaration", () => {
20
19
  </py.StatementList>
21
20
  );
22
21
 
23
- expect(toSourceText([decl], { externals: [abcModule] })).toBe(d`
22
+ expect(<TestOutput externals={[abcModule]}>{decl}</TestOutput>).toRenderTo(`
24
23
  class MyClass:
25
24
  @property
26
25
  def x(self):
@@ -57,7 +56,7 @@ describe("PropertyDeclaration", () => {
57
56
  </py.StatementList>
58
57
  );
59
58
 
60
- expect(toSourceText([decl], { externals: [abcModule] })).toBe(d`
59
+ expect(<TestOutput externals={[abcModule]}>{decl}</TestOutput>).toRenderTo(`
61
60
  class MyClass:
62
61
  @property
63
62
  def x(self) -> int:
@@ -121,7 +120,7 @@ describe("PropertyDeclaration", () => {
121
120
  </py.StatementList>
122
121
  );
123
122
 
124
- expect(toSourceText([decl], { externals: [abcModule] })).toBe(d`
123
+ expect(<TestOutput externals={[abcModule]}>{decl}</TestOutput>).toRenderTo(`
125
124
  class MyClass:
126
125
  @property
127
126
  def x(self) -> int:
@@ -168,7 +167,7 @@ describe("PropertyDeclaration", () => {
168
167
  </py.StatementList>
169
168
  );
170
169
 
171
- expect(toSourceText([decl], { externals: [abcModule] })).toBe(d`
170
+ expect(<TestOutput externals={[abcModule]}>{decl}</TestOutput>).toRenderTo(`
172
171
  class MyClass:
173
172
  @computed_field
174
173
  @deprecated("use width**2")
@@ -198,7 +197,7 @@ describe("PropertyDeclaration", () => {
198
197
  </py.StatementList>
199
198
  );
200
199
 
201
- expect(toSourceText([decl], { externals: [abcModule] })).toBe(d`
200
+ expect(<TestOutput externals={[abcModule]}>{decl}</TestOutput>).toRenderTo(`
202
201
  from abc import abstractmethod
203
202
 
204
203
 
@@ -232,7 +231,7 @@ describe("PropertyDeclaration", () => {
232
231
  </py.StatementList>
233
232
  );
234
233
 
235
- expect(toSourceText([decl], { externals: [abcModule] })).toBe(d`
234
+ expect(<TestOutput externals={[abcModule]}>{decl}</TestOutput>).toRenderTo(`
236
235
  from abc import abstractmethod
237
236
 
238
237