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

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 (166) hide show
  1. package/dist/dev/src/components/SourceFile.js +44 -32
  2. package/dist/dev/src/components/SourceFile.js.map +1 -1
  3. package/dist/dev/test/callsignatures.test.js +471 -297
  4. package/dist/dev/test/callsignatures.test.js.map +1 -1
  5. package/dist/dev/test/class-method-declaration.test.js +21 -10
  6. package/dist/dev/test/class-method-declaration.test.js.map +1 -1
  7. package/dist/dev/test/classdeclarations.test.js +459 -393
  8. package/dist/dev/test/classdeclarations.test.js.map +1 -1
  9. package/dist/dev/test/classinstantiations.test.js +201 -168
  10. package/dist/dev/test/classinstantiations.test.js.map +1 -1
  11. package/dist/dev/test/constructordeclaration.test.js +22 -11
  12. package/dist/dev/test/constructordeclaration.test.js.map +1 -1
  13. package/dist/dev/test/dataclassdeclarations.test.js +322 -368
  14. package/dist/dev/test/dataclassdeclarations.test.js.map +1 -1
  15. package/dist/dev/test/decoratorlist.test.js +96 -49
  16. package/dist/dev/test/decoratorlist.test.js.map +1 -1
  17. package/dist/dev/test/dundermethoddeclaration.test.js +22 -11
  18. package/dist/dev/test/dundermethoddeclaration.test.js.map +1 -1
  19. package/dist/dev/test/enums.test.js +218 -184
  20. package/dist/dev/test/enums.test.js.map +1 -1
  21. package/dist/dev/test/externals.test.js +57 -45
  22. package/dist/dev/test/externals.test.js.map +1 -1
  23. package/dist/dev/test/factories.test.js +124 -50
  24. package/dist/dev/test/factories.test.js.map +1 -1
  25. package/dist/dev/test/functioncallexpressions.test.js +199 -164
  26. package/dist/dev/test/functioncallexpressions.test.js.map +1 -1
  27. package/dist/dev/test/functiondeclaration.test.js +439 -272
  28. package/dist/dev/test/functiondeclaration.test.js.map +1 -1
  29. package/dist/dev/test/imports.test.js +273 -221
  30. package/dist/dev/test/imports.test.js.map +1 -1
  31. package/dist/dev/test/memberexpressions.test.js +1237 -972
  32. package/dist/dev/test/memberexpressions.test.js.map +1 -1
  33. package/dist/dev/test/methoddeclaration.test.js +142 -78
  34. package/dist/dev/test/methoddeclaration.test.js.map +1 -1
  35. package/dist/dev/test/namepolicies.test.js +130 -94
  36. package/dist/dev/test/namepolicies.test.js.map +1 -1
  37. package/dist/dev/test/propertydeclaration.test.js +88 -59
  38. package/dist/dev/test/propertydeclaration.test.js.map +1 -1
  39. package/dist/dev/test/pydanticclassdeclarations.test.js +299 -347
  40. package/dist/dev/test/pydanticclassdeclarations.test.js.map +1 -1
  41. package/dist/dev/test/pydocs.test.js +888 -715
  42. package/dist/dev/test/pydocs.test.js.map +1 -1
  43. package/dist/dev/test/references.test.js +42 -35
  44. package/dist/dev/test/references.test.js.map +1 -1
  45. package/dist/dev/test/sourcefiles.test.js +1109 -841
  46. package/dist/dev/test/sourcefiles.test.js.map +1 -1
  47. package/dist/dev/test/staticmethoddeclaration.test.js +21 -10
  48. package/dist/dev/test/staticmethoddeclaration.test.js.map +1 -1
  49. package/dist/dev/test/type-checking-imports.test.js +408 -359
  50. package/dist/dev/test/type-checking-imports.test.js.map +1 -1
  51. package/dist/dev/test/typereference.test.js +55 -40
  52. package/dist/dev/test/typereference.test.js.map +1 -1
  53. package/dist/dev/test/uniontypeexpression.test.js +222 -146
  54. package/dist/dev/test/uniontypeexpression.test.js.map +1 -1
  55. package/dist/dev/test/utils.js +39 -77
  56. package/dist/dev/test/utils.js.map +1 -1
  57. package/dist/dev/test/values.test.js +237 -101
  58. package/dist/dev/test/values.test.js.map +1 -1
  59. package/dist/dev/test/variables.test.js +321 -203
  60. package/dist/dev/test/variables.test.js.map +1 -1
  61. package/dist/dev/test/vitest.setup.js +2 -0
  62. package/dist/dev/test/vitest.setup.js.map +1 -0
  63. package/dist/src/components/SourceFile.d.ts +2 -2
  64. package/dist/src/components/SourceFile.d.ts.map +1 -1
  65. package/dist/src/components/SourceFile.js +12 -0
  66. package/dist/src/components/SourceFile.js.map +1 -1
  67. package/dist/test/callsignatures.test.js +346 -272
  68. package/dist/test/callsignatures.test.js.map +1 -1
  69. package/dist/test/class-method-declaration.test.js +7 -4
  70. package/dist/test/class-method-declaration.test.js.map +1 -1
  71. package/dist/test/classdeclarations.test.js +302 -288
  72. package/dist/test/classdeclarations.test.js.map +1 -1
  73. package/dist/test/classinstantiations.test.js +112 -103
  74. package/dist/test/classinstantiations.test.js.map +1 -1
  75. package/dist/test/constructordeclaration.test.js +7 -4
  76. package/dist/test/constructordeclaration.test.js.map +1 -1
  77. package/dist/test/dataclassdeclarations.test.js +134 -184
  78. package/dist/test/dataclassdeclarations.test.js.map +1 -1
  79. package/dist/test/decoratorlist.test.js +59 -36
  80. package/dist/test/decoratorlist.test.js.map +1 -1
  81. package/dist/test/dundermethoddeclaration.test.js +7 -4
  82. package/dist/test/dundermethoddeclaration.test.js.map +1 -1
  83. package/dist/test/enums.test.js +161 -159
  84. package/dist/test/enums.test.js.map +1 -1
  85. package/dist/test/externals.test.js +24 -24
  86. package/dist/test/externals.test.js.map +1 -1
  87. package/dist/test/factories.test.js +75 -33
  88. package/dist/test/factories.test.js.map +1 -1
  89. package/dist/test/functioncallexpressions.test.js +117 -106
  90. package/dist/test/functioncallexpressions.test.js.map +1 -1
  91. package/dist/test/functiondeclaration.test.js +247 -180
  92. package/dist/test/functiondeclaration.test.js.map +1 -1
  93. package/dist/test/imports.test.js +171 -143
  94. package/dist/test/imports.test.js.map +1 -1
  95. package/dist/test/memberexpressions.test.js +582 -453
  96. package/dist/test/memberexpressions.test.js.map +1 -1
  97. package/dist/test/methoddeclaration.test.js +66 -46
  98. package/dist/test/methoddeclaration.test.js.map +1 -1
  99. package/dist/test/namepolicies.test.js +90 -78
  100. package/dist/test/namepolicies.test.js.map +1 -1
  101. package/dist/test/propertydeclaration.test.js +25 -20
  102. package/dist/test/propertydeclaration.test.js.map +1 -1
  103. package/dist/test/pydanticclassdeclarations.test.js +134 -190
  104. package/dist/test/pydanticclassdeclarations.test.js.map +1 -1
  105. package/dist/test/pydocs.test.js +573 -532
  106. package/dist/test/pydocs.test.js.map +1 -1
  107. package/dist/test/references.test.js +31 -28
  108. package/dist/test/references.test.js.map +1 -1
  109. package/dist/test/sourcefiles.test.js +700 -580
  110. package/dist/test/sourcefiles.test.js.map +1 -1
  111. package/dist/test/staticmethoddeclaration.test.js +7 -4
  112. package/dist/test/staticmethoddeclaration.test.js.map +1 -1
  113. package/dist/test/type-checking-imports.test.js +297 -284
  114. package/dist/test/type-checking-imports.test.js.map +1 -1
  115. package/dist/test/typereference.test.js +29 -22
  116. package/dist/test/typereference.test.js.map +1 -1
  117. package/dist/test/uniontypeexpression.test.js +124 -88
  118. package/dist/test/uniontypeexpression.test.js.map +1 -1
  119. package/dist/test/utils.d.ts +10 -17
  120. package/dist/test/utils.d.ts.map +1 -1
  121. package/dist/test/utils.js +32 -74
  122. package/dist/test/utils.js.map +1 -1
  123. package/dist/test/values.test.js +135 -67
  124. package/dist/test/values.test.js.map +1 -1
  125. package/dist/test/variables.test.js +201 -151
  126. package/dist/test/variables.test.js.map +1 -1
  127. package/dist/test/vitest.setup.d.ts +2 -0
  128. package/dist/test/vitest.setup.d.ts.map +1 -0
  129. package/dist/test/vitest.setup.js +2 -0
  130. package/dist/test/vitest.setup.js.map +1 -0
  131. package/dist/tsconfig.tsbuildinfo +1 -1
  132. package/docs/api/components/SourceFile.md +20 -8
  133. package/package.json +2 -2
  134. package/src/components/SourceFile.tsx +6 -1
  135. package/temp/api.json +16 -2
  136. package/test/callsignatures.test.tsx +309 -283
  137. package/test/class-method-declaration.test.tsx +3 -4
  138. package/test/classdeclarations.test.tsx +263 -248
  139. package/test/classinstantiations.test.tsx +115 -109
  140. package/test/constructordeclaration.test.tsx +9 -6
  141. package/test/dataclassdeclarations.test.tsx +243 -361
  142. package/test/decoratorlist.test.tsx +78 -59
  143. package/test/dundermethoddeclaration.test.tsx +3 -4
  144. package/test/enums.test.tsx +65 -81
  145. package/test/externals.test.tsx +25 -25
  146. package/test/factories.test.tsx +64 -22
  147. package/test/functioncallexpressions.test.tsx +123 -109
  148. package/test/functiondeclaration.test.tsx +209 -148
  149. package/test/imports.test.tsx +119 -91
  150. package/test/memberexpressions.test.tsx +265 -207
  151. package/test/methoddeclaration.test.tsx +84 -63
  152. package/test/namepolicies.test.tsx +69 -69
  153. package/test/propertydeclaration.test.tsx +7 -8
  154. package/test/pydanticclassdeclarations.test.tsx +355 -487
  155. package/test/pydocs.test.tsx +531 -579
  156. package/test/references.test.tsx +24 -23
  157. package/test/sourcefiles.test.tsx +527 -492
  158. package/test/staticmethoddeclaration.test.tsx +3 -4
  159. package/test/type-checking-imports.test.tsx +206 -218
  160. package/test/typereference.test.tsx +15 -12
  161. package/test/uniontypeexpression.test.tsx +74 -61
  162. package/test/utils.tsx +26 -110
  163. package/test/values.test.tsx +82 -32
  164. package/test/variables.test.tsx +162 -142
  165. package/test/vitest.setup.ts +1 -0
  166. package/vitest.config.ts +3 -0
@@ -1,14 +1,14 @@
1
1
  import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
- import { Prose, namekey, refkey } from "@alloy-js/core";
3
- import { d } from "@alloy-js/core/testing";
2
+ import { Prose, namekey, refkey, render } from "@alloy-js/core";
4
3
  import { describe, expect, it } from "vitest";
5
4
  import { dataclassesModule } from "../src/builtins/python.js";
6
5
  import * as py from "../src/index.js";
7
- import { assertFileContents, toSourceText, toSourceTextMultiple } from "./utils.js";
6
+ import { TestOutput, TestOutputDirectory } from "./utils.js";
8
7
  describe("DataclassDeclaration", () => {
9
8
  it("stacks user decorators above @dataclass", () => {
10
- const res = toSourceText([_$createComponent(py.SourceFile, {
9
+ expect(_$createComponent(TestOutput, {
11
10
  path: "user.py",
11
+ externals: [dataclassesModule],
12
12
  get children() {
13
13
  return _$createComponent(py.DataclassDeclaration, {
14
14
  name: "User",
@@ -16,10 +16,7 @@ describe("DataclassDeclaration", () => {
16
16
  decorators: ["@final"]
17
17
  });
18
18
  }
19
- })], {
20
- externals: [dataclassesModule]
21
- });
22
- expect(res).toRenderTo(d`
19
+ })).toRenderTo(`
23
20
  from dataclasses import dataclass
24
21
 
25
22
 
@@ -28,7 +25,6 @@ describe("DataclassDeclaration", () => {
28
25
  class User:
29
26
  pass
30
27
 
31
-
32
28
  `);
33
29
  });
34
30
  it("Creates a dataclass with a class doc", () => {
@@ -39,18 +35,16 @@ describe("DataclassDeclaration", () => {
39
35
  })];
40
36
  }
41
37
  });
42
- const res = toSourceText([_$createComponent(py.SourceFile, {
38
+ expect(_$createComponent(TestOutput, {
43
39
  path: "user.py",
40
+ externals: [dataclassesModule],
44
41
  get children() {
45
42
  return _$createComponent(py.DataclassDeclaration, {
46
43
  name: "User",
47
44
  doc: doc
48
45
  });
49
46
  }
50
- })], {
51
- externals: [dataclassesModule]
52
- });
53
- expect(res).toRenderTo(d`
47
+ })).toRenderTo(`
54
48
  from dataclasses import dataclass
55
49
 
56
50
 
@@ -62,12 +56,12 @@ describe("DataclassDeclaration", () => {
62
56
 
63
57
  pass
64
58
 
65
-
66
59
  `);
67
60
  });
68
61
  it("Creates a dataclass with fields and defaults", () => {
69
- const res = toSourceText([_$createComponent(py.SourceFile, {
62
+ expect(_$createComponent(TestOutput, {
70
63
  path: "user.py",
64
+ externals: [dataclassesModule],
71
65
  get children() {
72
66
  return _$createComponent(py.DataclassDeclaration, {
73
67
  name: "User",
@@ -97,10 +91,7 @@ describe("DataclassDeclaration", () => {
97
91
  }
98
92
  });
99
93
  }
100
- })], {
101
- externals: [dataclassesModule]
102
- });
103
- expect(res).toRenderTo(d`
94
+ })).toRenderTo(`
104
95
  from dataclasses import dataclass
105
96
  from typing import TYPE_CHECKING
106
97
 
@@ -114,12 +105,12 @@ describe("DataclassDeclaration", () => {
114
105
  _: KW_ONLY
115
106
  name: str = "Anonymous"
116
107
 
117
-
118
108
  `);
119
109
  });
120
110
  it("Creates a dataclass with keyword arguments", () => {
121
- const res = toSourceText([_$createComponent(py.SourceFile, {
111
+ expect(_$createComponent(TestOutput, {
122
112
  path: "user.py",
113
+ externals: [dataclassesModule],
123
114
  get children() {
124
115
  return _$createComponent(py.DataclassDeclaration, {
125
116
  name: "User",
@@ -136,10 +127,7 @@ describe("DataclassDeclaration", () => {
136
127
  }
137
128
  });
138
129
  }
139
- })], {
140
- externals: [dataclassesModule]
141
- });
142
- expect(res).toRenderTo(d`
130
+ })).toRenderTo(`
143
131
  from dataclasses import dataclass
144
132
 
145
133
 
@@ -147,12 +135,12 @@ describe("DataclassDeclaration", () => {
147
135
  class User:
148
136
  id: int
149
137
 
150
-
151
138
  `);
152
139
  });
153
140
  it("Creates a dataclass with all keyword arguments", () => {
154
- const res = toSourceText([_$createComponent(py.SourceFile, {
141
+ expect(_$createComponent(TestOutput, {
155
142
  path: "user.py",
143
+ externals: [dataclassesModule],
156
144
  get children() {
157
145
  return _$createComponent(py.DataclassDeclaration, {
158
146
  name: "User",
@@ -168,10 +156,7 @@ describe("DataclassDeclaration", () => {
168
156
  weakrefSlot: false
169
157
  });
170
158
  }
171
- })], {
172
- externals: [dataclassesModule]
173
- });
174
- expect(res).toRenderTo(d`
159
+ })).toRenderTo(`
175
160
  from dataclasses import dataclass
176
161
 
177
162
 
@@ -179,25 +164,24 @@ describe("DataclassDeclaration", () => {
179
164
  class User:
180
165
  pass
181
166
 
182
-
183
167
  `);
184
168
  });
185
169
  it("Throws error when weakref_slot=True without slots=True", () => {
186
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
170
+ expect(() => render(_$createComponent(TestOutput, {
187
171
  path: "user.py",
172
+ externals: [dataclassesModule],
188
173
  get children() {
189
174
  return _$createComponent(py.DataclassDeclaration, {
190
175
  name: "User",
191
176
  weakrefSlot: true
192
177
  });
193
178
  }
194
- })], {
195
- externals: [dataclassesModule]
196
- })).toThrowError(/weakref_slot=True requires slots=True in @dataclass decorator/);
179
+ }))).toThrowError(/weakref_slot=True requires slots=True in @dataclass decorator/);
197
180
  });
198
181
  it("Allows weakref_slot=True when slots=True", () => {
199
- const res = toSourceText([_$createComponent(py.SourceFile, {
182
+ expect(_$createComponent(TestOutput, {
200
183
  path: "user.py",
184
+ externals: [dataclassesModule],
201
185
  get children() {
202
186
  return _$createComponent(py.DataclassDeclaration, {
203
187
  name: "User",
@@ -205,10 +189,7 @@ describe("DataclassDeclaration", () => {
205
189
  weakrefSlot: true
206
190
  });
207
191
  }
208
- })], {
209
- externals: [dataclassesModule]
210
- });
211
- expect(res).toRenderTo(d`
192
+ })).toRenderTo(`
212
193
  from dataclasses import dataclass
213
194
 
214
195
 
@@ -216,12 +197,12 @@ describe("DataclassDeclaration", () => {
216
197
  class User:
217
198
  pass
218
199
 
219
-
220
200
  `);
221
201
  });
222
202
  it("Throws error when order=True and eq=False", () => {
223
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
203
+ expect(() => render(_$createComponent(TestOutput, {
224
204
  path: "user.py",
205
+ externals: [dataclassesModule],
225
206
  get children() {
226
207
  return _$createComponent(py.DataclassDeclaration, {
227
208
  name: "User",
@@ -229,23 +210,19 @@ describe("DataclassDeclaration", () => {
229
210
  eq: false
230
211
  });
231
212
  }
232
- })], {
233
- externals: [dataclassesModule]
234
- })).toThrowError(/order=True requires eq=True/);
213
+ }))).toThrowError(/order=True requires eq=True/);
235
214
  });
236
215
  it("Creates a dataclass with order=True and no conflicting methods", () => {
237
- const res = toSourceText([_$createComponent(py.SourceFile, {
216
+ expect(_$createComponent(TestOutput, {
238
217
  path: "user.py",
218
+ externals: [dataclassesModule],
239
219
  get children() {
240
220
  return _$createComponent(py.DataclassDeclaration, {
241
221
  name: "User",
242
222
  order: true
243
223
  });
244
224
  }
245
- })], {
246
- externals: [dataclassesModule]
247
- });
248
- expect(res).toRenderTo(d`
225
+ })).toRenderTo(`
249
226
  from dataclasses import dataclass
250
227
 
251
228
 
@@ -253,12 +230,12 @@ describe("DataclassDeclaration", () => {
253
230
  class User:
254
231
  pass
255
232
 
256
-
257
233
  `);
258
234
  });
259
235
  it("Throws error when order=True and class defines __lt__", () => {
260
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
236
+ expect(() => render(_$createComponent(TestOutput, {
261
237
  path: "user.py",
238
+ externals: [dataclassesModule],
262
239
  get children() {
263
240
  return _$createComponent(py.DataclassDeclaration, {
264
241
  name: "User",
@@ -270,13 +247,12 @@ describe("DataclassDeclaration", () => {
270
247
  }
271
248
  });
272
249
  }
273
- })], {
274
- externals: [dataclassesModule]
275
- })).toThrowError(/Cannot specify order=True when the class already defines __lt__\(\)/);
250
+ }))).toThrowError(/Cannot specify order=True when the class already defines __lt__\(\)/);
276
251
  });
277
252
  it("Throws error when order=True and class defines __le__", () => {
278
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
253
+ expect(() => render(_$createComponent(TestOutput, {
279
254
  path: "user.py",
255
+ externals: [dataclassesModule],
280
256
  get children() {
281
257
  return _$createComponent(py.DataclassDeclaration, {
282
258
  name: "User",
@@ -288,13 +264,12 @@ describe("DataclassDeclaration", () => {
288
264
  }
289
265
  });
290
266
  }
291
- })], {
292
- externals: [dataclassesModule]
293
- })).toThrowError(/Cannot specify order=True when the class already defines __le__\(\)/);
267
+ }))).toThrowError(/Cannot specify order=True when the class already defines __le__\(\)/);
294
268
  });
295
269
  it("Throws error when order=True and class defines __gt__", () => {
296
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
270
+ expect(() => render(_$createComponent(TestOutput, {
297
271
  path: "user.py",
272
+ externals: [dataclassesModule],
298
273
  get children() {
299
274
  return _$createComponent(py.DataclassDeclaration, {
300
275
  name: "User",
@@ -306,13 +281,12 @@ describe("DataclassDeclaration", () => {
306
281
  }
307
282
  });
308
283
  }
309
- })], {
310
- externals: [dataclassesModule]
311
- })).toThrowError(/Cannot specify order=True when the class already defines __gt__\(\)/);
284
+ }))).toThrowError(/Cannot specify order=True when the class already defines __gt__\(\)/);
312
285
  });
313
286
  it("Throws error when order=True and class defines __ge__", () => {
314
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
287
+ expect(() => render(_$createComponent(TestOutput, {
315
288
  path: "user.py",
289
+ externals: [dataclassesModule],
316
290
  get children() {
317
291
  return _$createComponent(py.DataclassDeclaration, {
318
292
  name: "User",
@@ -324,9 +298,7 @@ describe("DataclassDeclaration", () => {
324
298
  }
325
299
  });
326
300
  }
327
- })], {
328
- externals: [dataclassesModule]
329
- })).toThrowError(/Cannot specify order=True when the class already defines __ge__\(\)/);
301
+ }))).toThrowError(/Cannot specify order=True when the class already defines __ge__\(\)/);
330
302
  });
331
303
  it("Throws error when order=True and a wrapper defines __lt__", () => {
332
304
  function Wrapper() {
@@ -334,8 +306,9 @@ describe("DataclassDeclaration", () => {
334
306
  name: "__lt__"
335
307
  });
336
308
  }
337
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
309
+ expect(() => render(_$createComponent(TestOutput, {
338
310
  path: "user.py",
311
+ externals: [dataclassesModule],
339
312
  get children() {
340
313
  return _$createComponent(py.DataclassDeclaration, {
341
314
  name: "User",
@@ -345,13 +318,12 @@ describe("DataclassDeclaration", () => {
345
318
  }
346
319
  });
347
320
  }
348
- })], {
349
- externals: [dataclassesModule]
350
- })).toThrowError(/Cannot specify order=True when the class already defines __lt__\(\)/);
321
+ }))).toThrowError(/Cannot specify order=True when the class already defines __lt__\(\)/);
351
322
  });
352
323
  it("Throws error when unsafe_hash=True and class defines __hash__", () => {
353
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
324
+ expect(() => render(_$createComponent(TestOutput, {
354
325
  path: "user.py",
326
+ externals: [dataclassesModule],
355
327
  get children() {
356
328
  return _$createComponent(py.DataclassDeclaration, {
357
329
  name: "User",
@@ -363,13 +335,12 @@ describe("DataclassDeclaration", () => {
363
335
  }
364
336
  });
365
337
  }
366
- })], {
367
- externals: [dataclassesModule]
368
- })).toThrowError(/Cannot specify unsafe_hash=True when the class already defines __hash__\(\)/);
338
+ }))).toThrowError(/Cannot specify unsafe_hash=True when the class already defines __hash__\(\)/);
369
339
  });
370
340
  it("Throws error when frozen=True and class defines __setattr__", () => {
371
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
341
+ expect(() => render(_$createComponent(TestOutput, {
372
342
  path: "user.py",
343
+ externals: [dataclassesModule],
373
344
  get children() {
374
345
  return _$createComponent(py.DataclassDeclaration, {
375
346
  name: "User",
@@ -381,13 +352,12 @@ describe("DataclassDeclaration", () => {
381
352
  }
382
353
  });
383
354
  }
384
- })], {
385
- externals: [dataclassesModule]
386
- })).toThrowError(/Cannot specify frozen=True when the class already defines __setattr__\(\)/);
355
+ }))).toThrowError(/Cannot specify frozen=True when the class already defines __setattr__\(\)/);
387
356
  });
388
357
  it("Throws errorwhen frozen=True and class defines __delattr__", () => {
389
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
358
+ expect(() => render(_$createComponent(TestOutput, {
390
359
  path: "user.py",
360
+ externals: [dataclassesModule],
391
361
  get children() {
392
362
  return _$createComponent(py.DataclassDeclaration, {
393
363
  name: "User",
@@ -399,13 +369,12 @@ describe("DataclassDeclaration", () => {
399
369
  }
400
370
  });
401
371
  }
402
- })], {
403
- externals: [dataclassesModule]
404
- })).toThrowError(/Cannot specify frozen=True when the class already defines __delattr__\(\)/);
372
+ }))).toThrowError(/Cannot specify frozen=True when the class already defines __delattr__\(\)/);
405
373
  });
406
374
  it("Throws error when slots=True and class defines __slots__", () => {
407
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
375
+ expect(() => render(_$createComponent(TestOutput, {
408
376
  path: "user.py",
377
+ externals: [dataclassesModule],
409
378
  get children() {
410
379
  return _$createComponent(py.DataclassDeclaration, {
411
380
  name: "User",
@@ -417,13 +386,12 @@ describe("DataclassDeclaration", () => {
417
386
  }
418
387
  });
419
388
  }
420
- })], {
421
- externals: [dataclassesModule]
422
- })).toThrowError(/Cannot specify slots=True when the class already defines __slots__\(\)/);
389
+ }))).toThrowError(/Cannot specify slots=True when the class already defines __slots__\(\)/);
423
390
  });
424
391
  it("Creates a dataclass with kw_only=True on decorator (sentinel not used)", () => {
425
- const res = toSourceText([_$createComponent(py.SourceFile, {
392
+ expect(_$createComponent(TestOutput, {
426
393
  path: "user.py",
394
+ externals: [dataclassesModule],
427
395
  get children() {
428
396
  return _$createComponent(py.DataclassDeclaration, {
429
397
  name: "User",
@@ -438,10 +406,7 @@ describe("DataclassDeclaration", () => {
438
406
  }
439
407
  });
440
408
  }
441
- })], {
442
- externals: [dataclassesModule]
443
- });
444
- expect(res).toRenderTo(d`
409
+ })).toRenderTo(`
445
410
  from dataclasses import dataclass
446
411
 
447
412
 
@@ -449,22 +414,19 @@ describe("DataclassDeclaration", () => {
449
414
  class User:
450
415
  id: int
451
416
 
452
-
453
417
  `);
454
418
  });
455
419
  it("Creates a dataclass with base classes", () => {
456
- const res = toSourceText([_$createComponent(py.SourceFile, {
420
+ expect(_$createComponent(TestOutput, {
457
421
  path: "user.py",
422
+ externals: [dataclassesModule],
458
423
  get children() {
459
424
  return _$createComponent(py.DataclassDeclaration, {
460
425
  name: "User",
461
426
  bases: ["Base"]
462
427
  });
463
428
  }
464
- })], {
465
- externals: [dataclassesModule]
466
- });
467
- expect(res).toRenderTo(d`
429
+ })).toRenderTo(`
468
430
  from dataclasses import dataclass
469
431
 
470
432
 
@@ -472,12 +434,12 @@ describe("DataclassDeclaration", () => {
472
434
  class User(Base):
473
435
  pass
474
436
 
475
-
476
437
  `);
477
438
  });
478
439
  it("Throws error when more than one KW_ONLY sentinel is present", () => {
479
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
440
+ expect(() => render(_$createComponent(TestOutput, {
480
441
  path: "user.py",
442
+ externals: [dataclassesModule],
481
443
  get children() {
482
444
  return _$createComponent(py.DataclassDeclaration, {
483
445
  name: "User",
@@ -508,13 +470,12 @@ describe("DataclassDeclaration", () => {
508
470
  }
509
471
  });
510
472
  }
511
- })], {
512
- externals: [dataclassesModule]
513
- })).toThrowError(/Only one KW_ONLY sentinel is allowed per dataclass body/);
473
+ }))).toThrowError(/Only one KW_ONLY sentinel is allowed per dataclass body/);
514
474
  });
515
475
  it("Will raise arg validation errors first over member conflicts", () => {
516
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
476
+ expect(() => render(_$createComponent(TestOutput, {
517
477
  path: "user.py",
478
+ externals: [dataclassesModule],
518
479
  get children() {
519
480
  return _$createComponent(py.DataclassDeclaration, {
520
481
  name: "User",
@@ -527,13 +488,12 @@ describe("DataclassDeclaration", () => {
527
488
  }
528
489
  });
529
490
  }
530
- })], {
531
- externals: [dataclassesModule]
532
- })).toThrowError(/order=True requires eq=True/);
491
+ }))).toThrowError(/order=True requires eq=True/);
533
492
  });
534
493
  it("Does not raise errors for member conflict checks without the equivalent kwargs", () => {
535
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
494
+ expect(() => render(_$createComponent(TestOutput, {
536
495
  path: "user.py",
496
+ externals: [dataclassesModule],
537
497
  get children() {
538
498
  return _$createComponent(py.DataclassDeclaration, {
539
499
  name: "User",
@@ -552,23 +512,19 @@ describe("DataclassDeclaration", () => {
552
512
  }
553
513
  });
554
514
  }
555
- })], {
556
- externals: [dataclassesModule]
557
- })).not.toThrow();
515
+ }))).not.toThrow();
558
516
  });
559
517
  it("Allows unsafe_hash=True when no __hash__ is defined", () => {
560
- const res = toSourceText([_$createComponent(py.SourceFile, {
518
+ expect(_$createComponent(TestOutput, {
561
519
  path: "user.py",
520
+ externals: [dataclassesModule],
562
521
  get children() {
563
522
  return _$createComponent(py.DataclassDeclaration, {
564
523
  name: "User",
565
524
  unsafeHash: true
566
525
  });
567
526
  }
568
- })], {
569
- externals: [dataclassesModule]
570
- });
571
- expect(res).toRenderTo(d`
527
+ })).toRenderTo(`
572
528
  from dataclasses import dataclass
573
529
 
574
530
 
@@ -576,7 +532,6 @@ describe("DataclassDeclaration", () => {
576
532
  class User:
577
533
  pass
578
534
 
579
-
580
535
  `);
581
536
  });
582
537
  it("Counts KW_ONLY sentinels through wrappers (symbol-level)", () => {
@@ -594,8 +549,9 @@ describe("DataclassDeclaration", () => {
594
549
  omitNone: true
595
550
  });
596
551
  }
597
- expect(() => toSourceText([_$createComponent(py.SourceFile, {
552
+ expect(() => render(_$createComponent(TestOutput, {
598
553
  path: "user.py",
554
+ externals: [dataclassesModule],
599
555
  get children() {
600
556
  return _$createComponent(py.DataclassDeclaration, {
601
557
  name: "User",
@@ -615,23 +571,19 @@ describe("DataclassDeclaration", () => {
615
571
  }
616
572
  });
617
573
  }
618
- })], {
619
- externals: [dataclassesModule]
620
- })).toThrowError(/Only one KW_ONLY sentinel is allowed per dataclass body/);
574
+ }))).toThrowError(/Only one KW_ONLY sentinel is allowed per dataclass body/);
621
575
  });
622
576
  it("Allows frozen=True when no conflicting dunders exist", () => {
623
- const res = toSourceText([_$createComponent(py.SourceFile, {
577
+ expect(_$createComponent(TestOutput, {
624
578
  path: "user.py",
579
+ externals: [dataclassesModule],
625
580
  get children() {
626
581
  return _$createComponent(py.DataclassDeclaration, {
627
582
  name: "User",
628
583
  frozen: true
629
584
  });
630
585
  }
631
- })], {
632
- externals: [dataclassesModule]
633
- });
634
- expect(res).toRenderTo(d`
586
+ })).toRenderTo(`
635
587
  from dataclasses import dataclass
636
588
 
637
589
 
@@ -639,22 +591,19 @@ describe("DataclassDeclaration", () => {
639
591
  class User:
640
592
  pass
641
593
 
642
-
643
594
  `);
644
595
  });
645
596
  it("Allows slots=True when no __slots__ is defined", () => {
646
- const res = toSourceText([_$createComponent(py.SourceFile, {
597
+ expect(_$createComponent(TestOutput, {
647
598
  path: "user.py",
599
+ externals: [dataclassesModule],
648
600
  get children() {
649
601
  return _$createComponent(py.DataclassDeclaration, {
650
602
  name: "User",
651
603
  slots: true
652
604
  });
653
605
  }
654
- })], {
655
- externals: [dataclassesModule]
656
- });
657
- expect(res).toRenderTo(d`
606
+ })).toRenderTo(`
658
607
  from dataclasses import dataclass
659
608
 
660
609
 
@@ -662,75 +611,76 @@ describe("DataclassDeclaration", () => {
662
611
  class User:
663
612
  pass
664
613
 
665
-
666
614
  `);
667
615
  });
668
616
  it("Forwards refkey prop for symbol resolution in type references", () => {
669
617
  const userRefkey = refkey();
670
- const res = toSourceTextMultiple([_$createComponent(py.SourceFile, {
671
- path: "models.py",
618
+ expect(_$createComponent(TestOutputDirectory, {
619
+ externals: [dataclassesModule],
672
620
  get children() {
673
- return _$createComponent(py.DataclassDeclaration, {
674
- name: "User",
675
- refkey: userRefkey,
621
+ return [_$createComponent(py.SourceFile, {
622
+ path: "models.py",
676
623
  get children() {
677
- return [_$createComponent(py.VariableDeclaration, {
678
- instanceVariable: true,
679
- omitNone: true,
680
- name: "id",
681
- type: "int"
682
- }), _$createComponent(py.VariableDeclaration, {
683
- instanceVariable: true,
684
- omitNone: true,
685
- name: "name",
686
- type: "str"
687
- })];
624
+ return _$createComponent(py.DataclassDeclaration, {
625
+ name: "User",
626
+ refkey: userRefkey,
627
+ get children() {
628
+ return [_$createComponent(py.VariableDeclaration, {
629
+ instanceVariable: true,
630
+ omitNone: true,
631
+ name: "id",
632
+ type: "int"
633
+ }), _$createComponent(py.VariableDeclaration, {
634
+ instanceVariable: true,
635
+ omitNone: true,
636
+ name: "name",
637
+ type: "str"
638
+ })];
639
+ }
640
+ });
688
641
  }
689
- });
690
- }
691
- }), _$createComponent(py.SourceFile, {
692
- path: "services.py",
693
- get children() {
694
- return _$createComponent(py.FunctionDeclaration, {
695
- name: "get_user",
696
- returnType: userRefkey,
642
+ }), _$createComponent(py.SourceFile, {
643
+ path: "services.py",
697
644
  get children() {
698
- return [_$createComponent(py.VariableDeclaration, {
699
- name: "user",
700
- type: userRefkey,
701
- get initializer() {
702
- return _$createComponent(py.ClassInstantiation, {
703
- target: userRefkey,
704
- args: ["1", '"Alice"']
705
- });
645
+ return _$createComponent(py.FunctionDeclaration, {
646
+ name: "get_user",
647
+ returnType: userRefkey,
648
+ get children() {
649
+ return [_$createComponent(py.VariableDeclaration, {
650
+ name: "user",
651
+ type: userRefkey,
652
+ get initializer() {
653
+ return _$createComponent(py.ClassInstantiation, {
654
+ target: userRefkey,
655
+ args: ["1", '"Alice"']
656
+ });
657
+ }
658
+ }), _$createIntrinsic("hbr", {}), "return user"];
706
659
  }
707
- }), _$createIntrinsic("hbr", {}), "return user"];
660
+ });
708
661
  }
709
- });
662
+ })];
710
663
  }
711
- })], {
712
- externals: [dataclassesModule]
713
- });
714
- assertFileContents(res, {
664
+ })).toRenderTo({
715
665
  "models.py": `
716
- from dataclasses import dataclass
666
+ from dataclasses import dataclass
717
667
 
718
668
 
719
- @dataclass
720
- class User:
721
- id: int
722
- name: str
669
+ @dataclass
670
+ class User:
671
+ id: int
672
+ name: str
723
673
 
724
- `,
674
+ `,
725
675
  "services.py": `
726
- from models import User
676
+ from models import User
727
677
 
728
678
 
729
- def get_user() -> User:
730
- user: User = User(1, "Alice")
731
- return user
679
+ def get_user() -> User:
680
+ user: User = User(1, "Alice")
681
+ return user
732
682
 
733
- `
683
+ `
734
684
  });
735
685
  });
736
686
  });