@alloy-js/python 0.5.0-dev.0 → 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 (276) hide show
  1. package/dist/dev/src/builtins/python.js +46 -0
  2. package/dist/dev/src/builtins/python.js.map +1 -1
  3. package/dist/dev/src/components/ClassDeclaration.js +19 -10
  4. package/dist/dev/src/components/ClassDeclaration.js.map +1 -1
  5. package/dist/dev/src/components/ClassMethodDeclaration.js +20 -5
  6. package/dist/dev/src/components/ClassMethodDeclaration.js.map +1 -1
  7. package/dist/dev/src/components/DataclassDeclaration.js +14 -12
  8. package/dist/dev/src/components/DataclassDeclaration.js.map +1 -1
  9. package/dist/dev/src/components/DecoratorList.js +55 -0
  10. package/dist/dev/src/components/DecoratorList.js.map +1 -0
  11. package/dist/dev/src/components/EnumDeclaration.js +21 -12
  12. package/dist/dev/src/components/EnumDeclaration.js.map +1 -1
  13. package/dist/dev/src/components/FunctionBase.js +21 -10
  14. package/dist/dev/src/components/FunctionBase.js.map +1 -1
  15. package/dist/dev/src/components/FutureStatement.js +1 -1
  16. package/dist/dev/src/components/MethodBase.js +16 -4
  17. package/dist/dev/src/components/MethodBase.js.map +1 -1
  18. package/dist/dev/src/components/PropertyDeclaration.js +68 -17
  19. package/dist/dev/src/components/PropertyDeclaration.js.map +1 -1
  20. package/dist/dev/src/components/PydanticClassDeclaration.js +136 -0
  21. package/dist/dev/src/components/PydanticClassDeclaration.js.map +1 -0
  22. package/dist/dev/src/components/SourceFile.js +44 -32
  23. package/dist/dev/src/components/SourceFile.js.map +1 -1
  24. package/dist/dev/src/components/StaticMethodDeclaration.js +19 -5
  25. package/dist/dev/src/components/StaticMethodDeclaration.js.map +1 -1
  26. package/dist/dev/src/components/index.js +1 -0
  27. package/dist/dev/src/components/index.js.map +1 -1
  28. package/dist/dev/test/callsignatures.test.js +471 -297
  29. package/dist/dev/test/callsignatures.test.js.map +1 -1
  30. package/dist/dev/test/class-method-declaration.test.js +21 -10
  31. package/dist/dev/test/class-method-declaration.test.js.map +1 -1
  32. package/dist/dev/test/classdeclarations.test.js +480 -381
  33. package/dist/dev/test/classdeclarations.test.js.map +1 -1
  34. package/dist/dev/test/classinstantiations.test.js +201 -168
  35. package/dist/dev/test/classinstantiations.test.js.map +1 -1
  36. package/dist/dev/test/constructordeclaration.test.js +22 -11
  37. package/dist/dev/test/constructordeclaration.test.js.map +1 -1
  38. package/dist/dev/test/dataclassdeclarations.test.js +345 -358
  39. package/dist/dev/test/dataclassdeclarations.test.js.map +1 -1
  40. package/dist/dev/test/decoratorlist.test.js +131 -0
  41. package/dist/dev/test/decoratorlist.test.js.map +1 -0
  42. package/dist/dev/test/dundermethoddeclaration.test.js +22 -11
  43. package/dist/dev/test/dundermethoddeclaration.test.js.map +1 -1
  44. package/dist/dev/test/enums.test.js +231 -166
  45. package/dist/dev/test/enums.test.js.map +1 -1
  46. package/dist/dev/test/externals.test.js +57 -45
  47. package/dist/dev/test/externals.test.js.map +1 -1
  48. package/dist/dev/test/factories.test.js +124 -50
  49. package/dist/dev/test/factories.test.js.map +1 -1
  50. package/dist/dev/test/functioncallexpressions.test.js +199 -164
  51. package/dist/dev/test/functioncallexpressions.test.js.map +1 -1
  52. package/dist/dev/test/functiondeclaration.test.js +452 -265
  53. package/dist/dev/test/functiondeclaration.test.js.map +1 -1
  54. package/dist/dev/test/imports.test.js +273 -221
  55. package/dist/dev/test/imports.test.js.map +1 -1
  56. package/dist/dev/test/memberexpressions.test.js +1237 -972
  57. package/dist/dev/test/memberexpressions.test.js.map +1 -1
  58. package/dist/dev/test/methoddeclaration.test.js +200 -45
  59. package/dist/dev/test/methoddeclaration.test.js.map +1 -1
  60. package/dist/dev/test/namepolicies.test.js +130 -94
  61. package/dist/dev/test/namepolicies.test.js.map +1 -1
  62. package/dist/dev/test/propertydeclaration.test.js +177 -46
  63. package/dist/dev/test/propertydeclaration.test.js.map +1 -1
  64. package/dist/dev/test/pydanticclassdeclarations.test.js +1089 -0
  65. package/dist/dev/test/pydanticclassdeclarations.test.js.map +1 -0
  66. package/dist/dev/test/pydocs.test.js +888 -715
  67. package/dist/dev/test/pydocs.test.js.map +1 -1
  68. package/dist/dev/test/references.test.js +42 -35
  69. package/dist/dev/test/references.test.js.map +1 -1
  70. package/dist/dev/test/sourcefiles.test.js +1109 -841
  71. package/dist/dev/test/sourcefiles.test.js.map +1 -1
  72. package/dist/dev/test/staticmethoddeclaration.test.js +21 -10
  73. package/dist/dev/test/staticmethoddeclaration.test.js.map +1 -1
  74. package/dist/dev/test/type-checking-imports.test.js +408 -359
  75. package/dist/dev/test/type-checking-imports.test.js.map +1 -1
  76. package/dist/dev/test/typereference.test.js +55 -40
  77. package/dist/dev/test/typereference.test.js.map +1 -1
  78. package/dist/dev/test/uniontypeexpression.test.js +222 -146
  79. package/dist/dev/test/uniontypeexpression.test.js.map +1 -1
  80. package/dist/dev/test/utils.js +39 -77
  81. package/dist/dev/test/utils.js.map +1 -1
  82. package/dist/dev/test/values.test.js +237 -101
  83. package/dist/dev/test/values.test.js.map +1 -1
  84. package/dist/dev/test/variables.test.js +321 -203
  85. package/dist/dev/test/variables.test.js.map +1 -1
  86. package/dist/dev/test/vitest.setup.js +2 -0
  87. package/dist/dev/test/vitest.setup.js.map +1 -0
  88. package/dist/src/builtins/python.d.ts +30 -0
  89. package/dist/src/builtins/python.d.ts.map +1 -1
  90. package/dist/src/builtins/python.js +46 -0
  91. package/dist/src/builtins/python.js.map +1 -1
  92. package/dist/src/components/ClassDeclaration.d.ts +21 -0
  93. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  94. package/dist/src/components/ClassDeclaration.js +6 -1
  95. package/dist/src/components/ClassDeclaration.js.map +1 -1
  96. package/dist/src/components/ClassMethodDeclaration.d.ts +5 -1
  97. package/dist/src/components/ClassMethodDeclaration.d.ts.map +1 -1
  98. package/dist/src/components/ClassMethodDeclaration.js +14 -3
  99. package/dist/src/components/ClassMethodDeclaration.js.map +1 -1
  100. package/dist/src/components/DataclassDeclaration.d.ts.map +1 -1
  101. package/dist/src/components/DataclassDeclaration.js +10 -4
  102. package/dist/src/components/DataclassDeclaration.js.map +1 -1
  103. package/dist/src/components/DecoratorList.d.ts +43 -0
  104. package/dist/src/components/DecoratorList.d.ts.map +1 -0
  105. package/dist/src/components/DecoratorList.js +47 -0
  106. package/dist/src/components/DecoratorList.js.map +1 -0
  107. package/dist/src/components/EnumDeclaration.d.ts +9 -0
  108. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  109. package/dist/src/components/EnumDeclaration.js +6 -1
  110. package/dist/src/components/EnumDeclaration.js.map +1 -1
  111. package/dist/src/components/FunctionBase.d.ts +31 -1
  112. package/dist/src/components/FunctionBase.d.ts.map +1 -1
  113. package/dist/src/components/FunctionBase.js +9 -2
  114. package/dist/src/components/FunctionBase.js.map +1 -1
  115. package/dist/src/components/FutureStatement.d.ts +1 -1
  116. package/dist/src/components/FutureStatement.js +1 -1
  117. package/dist/src/components/MethodBase.d.ts.map +1 -1
  118. package/dist/src/components/MethodBase.js +10 -2
  119. package/dist/src/components/MethodBase.js.map +1 -1
  120. package/dist/src/components/PropertyDeclaration.d.ts +29 -0
  121. package/dist/src/components/PropertyDeclaration.d.ts.map +1 -1
  122. package/dist/src/components/PropertyDeclaration.js +48 -1
  123. package/dist/src/components/PropertyDeclaration.js.map +1 -1
  124. package/dist/src/components/PydanticClassDeclaration.d.ts +120 -0
  125. package/dist/src/components/PydanticClassDeclaration.d.ts.map +1 -0
  126. package/dist/src/components/PydanticClassDeclaration.js +116 -0
  127. package/dist/src/components/PydanticClassDeclaration.js.map +1 -0
  128. package/dist/src/components/SourceFile.d.ts +2 -2
  129. package/dist/src/components/SourceFile.d.ts.map +1 -1
  130. package/dist/src/components/SourceFile.js +12 -0
  131. package/dist/src/components/SourceFile.js.map +1 -1
  132. package/dist/src/components/StaticMethodDeclaration.d.ts +3 -0
  133. package/dist/src/components/StaticMethodDeclaration.d.ts.map +1 -1
  134. package/dist/src/components/StaticMethodDeclaration.js +13 -3
  135. package/dist/src/components/StaticMethodDeclaration.js.map +1 -1
  136. package/dist/src/components/index.d.ts +1 -0
  137. package/dist/src/components/index.d.ts.map +1 -1
  138. package/dist/src/components/index.js +1 -0
  139. package/dist/src/components/index.js.map +1 -1
  140. package/dist/test/callsignatures.test.js +346 -272
  141. package/dist/test/callsignatures.test.js.map +1 -1
  142. package/dist/test/class-method-declaration.test.js +7 -4
  143. package/dist/test/class-method-declaration.test.js.map +1 -1
  144. package/dist/test/classdeclarations.test.js +316 -277
  145. package/dist/test/classdeclarations.test.js.map +1 -1
  146. package/dist/test/classinstantiations.test.js +112 -103
  147. package/dist/test/classinstantiations.test.js.map +1 -1
  148. package/dist/test/constructordeclaration.test.js +7 -4
  149. package/dist/test/constructordeclaration.test.js.map +1 -1
  150. package/dist/test/dataclassdeclarations.test.js +153 -178
  151. package/dist/test/dataclassdeclarations.test.js.map +1 -1
  152. package/dist/test/decoratorlist.test.d.ts +2 -0
  153. package/dist/test/decoratorlist.test.d.ts.map +1 -0
  154. package/dist/test/decoratorlist.test.js +83 -0
  155. package/dist/test/decoratorlist.test.js.map +1 -0
  156. package/dist/test/dundermethoddeclaration.test.js +7 -4
  157. package/dist/test/dundermethoddeclaration.test.js.map +1 -1
  158. package/dist/test/enums.test.js +172 -143
  159. package/dist/test/enums.test.js.map +1 -1
  160. package/dist/test/externals.test.js +24 -24
  161. package/dist/test/externals.test.js.map +1 -1
  162. package/dist/test/factories.test.js +75 -33
  163. package/dist/test/factories.test.js.map +1 -1
  164. package/dist/test/functioncallexpressions.test.js +117 -106
  165. package/dist/test/functioncallexpressions.test.js.map +1 -1
  166. package/dist/test/functiondeclaration.test.js +256 -173
  167. package/dist/test/functiondeclaration.test.js.map +1 -1
  168. package/dist/test/imports.test.js +171 -143
  169. package/dist/test/imports.test.js.map +1 -1
  170. package/dist/test/memberexpressions.test.js +582 -453
  171. package/dist/test/memberexpressions.test.js.map +1 -1
  172. package/dist/test/methoddeclaration.test.js +106 -19
  173. package/dist/test/methoddeclaration.test.js.map +1 -1
  174. package/dist/test/namepolicies.test.js +90 -78
  175. package/dist/test/namepolicies.test.js.map +1 -1
  176. package/dist/test/propertydeclaration.test.js +90 -15
  177. package/dist/test/propertydeclaration.test.js.map +1 -1
  178. package/dist/test/pydanticclassdeclarations.test.d.ts +2 -0
  179. package/dist/test/pydanticclassdeclarations.test.d.ts.map +1 -0
  180. package/dist/test/pydanticclassdeclarations.test.js +773 -0
  181. package/dist/test/pydanticclassdeclarations.test.js.map +1 -0
  182. package/dist/test/pydocs.test.js +573 -532
  183. package/dist/test/pydocs.test.js.map +1 -1
  184. package/dist/test/references.test.js +31 -28
  185. package/dist/test/references.test.js.map +1 -1
  186. package/dist/test/sourcefiles.test.js +700 -580
  187. package/dist/test/sourcefiles.test.js.map +1 -1
  188. package/dist/test/staticmethoddeclaration.test.js +7 -4
  189. package/dist/test/staticmethoddeclaration.test.js.map +1 -1
  190. package/dist/test/type-checking-imports.test.js +297 -284
  191. package/dist/test/type-checking-imports.test.js.map +1 -1
  192. package/dist/test/typereference.test.js +29 -22
  193. package/dist/test/typereference.test.js.map +1 -1
  194. package/dist/test/uniontypeexpression.test.js +124 -88
  195. package/dist/test/uniontypeexpression.test.js.map +1 -1
  196. package/dist/test/utils.d.ts +10 -17
  197. package/dist/test/utils.d.ts.map +1 -1
  198. package/dist/test/utils.js +32 -74
  199. package/dist/test/utils.js.map +1 -1
  200. package/dist/test/values.test.js +135 -67
  201. package/dist/test/values.test.js.map +1 -1
  202. package/dist/test/variables.test.js +201 -151
  203. package/dist/test/variables.test.js.map +1 -1
  204. package/dist/test/vitest.setup.d.ts +2 -0
  205. package/dist/test/vitest.setup.d.ts.map +1 -0
  206. package/dist/test/vitest.setup.js +2 -0
  207. package/dist/test/vitest.setup.js.map +1 -0
  208. package/dist/tsconfig.tsbuildinfo +1 -1
  209. package/docs/api/components/ClassDeclaration.md +10 -7
  210. package/docs/api/components/ClassEnumDeclaration.md +9 -6
  211. package/docs/api/components/ClassMethodDeclaration.md +7 -5
  212. package/docs/api/components/DataclassDeclaration.md +9 -5
  213. package/docs/api/components/DunderMethodDeclaration.md +7 -5
  214. package/docs/api/components/FunctionDeclaration.md +9 -5
  215. package/docs/api/components/FutureStatement.md +1 -1
  216. package/docs/api/components/MethodDeclaration.md +11 -6
  217. package/docs/api/components/PropertyDeclaration.md +11 -8
  218. package/docs/api/components/PydanticClassDeclaration.md +146 -0
  219. package/docs/api/components/SourceFile.md +20 -8
  220. package/docs/api/components/StaticMethodDeclaration.md +7 -5
  221. package/docs/api/components/index.md +1 -0
  222. package/docs/api/index.md +3 -3
  223. package/docs/api/types/CommonFunctionProps.md +4 -3
  224. package/docs/api/types/PydanticModelConfigDictProps.md +32 -0
  225. package/docs/api/types/index.md +1 -0
  226. package/docs/api/variables/index.md +3 -0
  227. package/docs/api/variables/pydanticModule.md +27 -0
  228. package/docs/api/variables/pydanticSettingsModule.md +7 -0
  229. package/docs/api/variables/typingModule.md +9 -0
  230. package/package.json +4 -4
  231. package/src/builtins/python.ts +539 -1
  232. package/src/components/ClassDeclaration.tsx +23 -0
  233. package/src/components/ClassMethodDeclaration.tsx +9 -1
  234. package/src/components/DataclassDeclaration.tsx +18 -11
  235. package/src/components/DecoratorList.tsx +50 -0
  236. package/src/components/EnumDeclaration.tsx +11 -0
  237. package/src/components/FunctionBase.tsx +34 -3
  238. package/src/components/FutureStatement.tsx +1 -1
  239. package/src/components/MethodBase.tsx +6 -2
  240. package/src/components/PropertyDeclaration.tsx +48 -1
  241. package/src/components/PydanticClassDeclaration.tsx +222 -0
  242. package/src/components/SourceFile.tsx +6 -1
  243. package/src/components/StaticMethodDeclaration.tsx +7 -1
  244. package/src/components/index.ts +1 -0
  245. package/temp/api.json +1158 -86
  246. package/test/callsignatures.test.tsx +309 -283
  247. package/test/class-method-declaration.test.tsx +3 -4
  248. package/test/classdeclarations.test.tsx +277 -235
  249. package/test/classinstantiations.test.tsx +115 -109
  250. package/test/constructordeclaration.test.tsx +9 -6
  251. package/test/dataclassdeclarations.test.tsx +256 -349
  252. package/test/decoratorlist.test.tsx +114 -0
  253. package/test/dundermethoddeclaration.test.tsx +3 -4
  254. package/test/enums.test.tsx +84 -71
  255. package/test/externals.test.tsx +25 -25
  256. package/test/factories.test.tsx +64 -22
  257. package/test/functioncallexpressions.test.tsx +123 -109
  258. package/test/functiondeclaration.test.tsx +218 -140
  259. package/test/imports.test.tsx +119 -91
  260. package/test/memberexpressions.test.tsx +265 -207
  261. package/test/methoddeclaration.test.tsx +115 -24
  262. package/test/namepolicies.test.tsx +69 -69
  263. package/test/propertydeclaration.test.tsx +71 -7
  264. package/test/pydanticclassdeclarations.test.tsx +704 -0
  265. package/test/pydocs.test.tsx +531 -579
  266. package/test/references.test.tsx +24 -23
  267. package/test/sourcefiles.test.tsx +527 -492
  268. package/test/staticmethoddeclaration.test.tsx +3 -4
  269. package/test/type-checking-imports.test.tsx +206 -218
  270. package/test/typereference.test.tsx +15 -12
  271. package/test/uniontypeexpression.test.tsx +74 -61
  272. package/test/utils.tsx +26 -110
  273. package/test/values.test.tsx +82 -32
  274. package/test/variables.test.tsx +162 -142
  275. package/test/vitest.setup.ts +1 -0
  276. package/vitest.config.ts +3 -0
@@ -1,24 +1,101 @@
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", () => {
7
+ it("renders decorators above def", () => {
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
+ `
21
+ class MyClass:
22
+ @some_decorator
23
+ def with_decorator(self):
24
+ pass
25
+
26
+
27
+ `,
28
+ );
29
+ });
30
+
31
+ it("renders multiple decorators above def without blank lines", () => {
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
+ `
45
+ class MyClass:
46
+ @outer
47
+ @middle
48
+ @inner
49
+ def with_decorators(self):
50
+ pass
51
+
52
+
53
+ `,
54
+ );
55
+ });
56
+
57
+ it("renders multiple decorators above @classmethod without blank lines", () => {
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
+ `
71
+ class MyClass:
72
+ @outer
73
+ @inner
74
+ @classmethod
75
+ def with_decorators(cls):
76
+ pass
77
+
78
+
79
+ `,
80
+ );
81
+ });
82
+
8
83
  it("renders an instance function with a body", () => {
9
- const result = toSourceText([
10
- <py.ClassDeclaration name="MyClass">
11
- <py.MethodDeclaration name="bar">print('hi')</py.MethodDeclaration>
12
- </py.ClassDeclaration>,
13
- ]);
14
- 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
+ `
15
92
  class MyClass:
16
93
  def bar(self):
17
94
  print('hi')
18
95
 
19
96
 
20
-
21
- `);
97
+ `,
98
+ );
22
99
  });
23
100
 
24
101
  it("can be an async method", () => {
@@ -34,13 +111,15 @@ describe("Method-like Declarations", () => {
34
111
  </py.StatementList>
35
112
  );
36
113
 
37
- expect(toSourceText([decl])).toBe(d`
114
+ expect(<TestOutput>{decl}</TestOutput>).toRenderTo(
115
+ `
38
116
  class MyClass:
39
117
  async def my_method(self) -> str:
40
118
  return "async result"
41
119
 
42
120
 
43
- `);
121
+ `,
122
+ );
44
123
  });
45
124
 
46
125
  it("can be an async class method", () => {
@@ -60,14 +139,16 @@ describe("Method-like Declarations", () => {
60
139
  </py.StatementList>
61
140
  );
62
141
 
63
- expect(toSourceText([decl])).toBe(d`
142
+ expect(<TestOutput>{decl}</TestOutput>).toRenderTo(
143
+ `
64
144
  class MyClass:
65
145
  @classmethod
66
146
  async def create_async(cls) -> MyClass:
67
147
  return cls()
68
148
 
69
149
 
70
- `);
150
+ `,
151
+ );
71
152
  });
72
153
 
73
154
  it("can be an async static method", () => {
@@ -83,14 +164,16 @@ describe("Method-like Declarations", () => {
83
164
  </py.StatementList>
84
165
  );
85
166
 
86
- expect(toSourceText([decl])).toBe(d`
167
+ expect(<TestOutput>{decl}</TestOutput>).toRenderTo(
168
+ `
87
169
  class MyClass:
88
170
  @staticmethod
89
171
  async def utility() -> str:
90
172
  return "utility result"
91
173
 
92
174
 
93
- `);
175
+ `,
176
+ );
94
177
  });
95
178
 
96
179
  it("renders method with parameters", () => {
@@ -103,13 +186,15 @@ describe("Method-like Declarations", () => {
103
186
  </py.ClassDeclaration>
104
187
  );
105
188
 
106
- expect(toSourceText([decl])).toBe(d`
189
+ expect(<TestOutput>{decl}</TestOutput>).toRenderTo(
190
+ `
107
191
  class MyClass:
108
192
  def foo(self, x: int):
109
193
  self.attribute = "value"
110
194
 
111
195
 
112
- `);
196
+ `,
197
+ );
113
198
  });
114
199
 
115
200
  it("renders class method with parameters", () => {
@@ -122,14 +207,16 @@ describe("Method-like Declarations", () => {
122
207
  </py.ClassDeclaration>
123
208
  );
124
209
 
125
- expect(toSourceText([decl])).toBe(d`
210
+ expect(<TestOutput>{decl}</TestOutput>).toRenderTo(
211
+ `
126
212
  class MyClass:
127
213
  @classmethod
128
214
  def foo(cls, x: int):
129
215
  self.attribute = "value"
130
216
 
131
217
 
132
- `);
218
+ `,
219
+ );
133
220
  });
134
221
 
135
222
  it("renders static method with parameters", () => {
@@ -142,14 +229,16 @@ describe("Method-like Declarations", () => {
142
229
  </py.ClassDeclaration>
143
230
  );
144
231
 
145
- expect(toSourceText([decl])).toBe(d`
232
+ expect(<TestOutput>{decl}</TestOutput>).toRenderTo(
233
+ `
146
234
  class MyClass:
147
235
  @staticmethod
148
236
  def foo(x: int):
149
237
  attribute = "value"
150
238
 
151
239
 
152
- `);
240
+ `,
241
+ );
153
242
  });
154
243
 
155
244
  it("renders abstract methods", () => {
@@ -178,7 +267,8 @@ describe("Method-like Declarations", () => {
178
267
  </py.StatementList>
179
268
  );
180
269
 
181
- expect(toSourceText([decl], { externals: [abcModule] })).toBe(d`
270
+ expect(<TestOutput externals={[abcModule]}>{decl}</TestOutput>).toRenderTo(
271
+ `
182
272
  from abc import abstractmethod
183
273
 
184
274
 
@@ -198,6 +288,7 @@ describe("Method-like Declarations", () => {
198
288
  pass
199
289
 
200
290
 
201
- `);
291
+ `,
292
+ );
202
293
  });
203
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
- import { Prose } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
1
+ import { Prose, code } from "@alloy-js/core";
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:
@@ -148,6 +147,71 @@ describe("PropertyDeclaration", () => {
148
147
  `);
149
148
  });
150
149
 
150
+ it("renders decorators above @property in source order", () => {
151
+ const decl = (
152
+ <py.StatementList>
153
+ <py.ClassDeclaration name="MyClass">
154
+ <py.StatementList>
155
+ <py.PropertyDeclaration
156
+ name="area"
157
+ type="float"
158
+ decorators={[
159
+ code`@computed_field`,
160
+ code`@deprecated("use width**2")`,
161
+ ]}
162
+ >
163
+ return self.width ** 2
164
+ </py.PropertyDeclaration>
165
+ </py.StatementList>
166
+ </py.ClassDeclaration>
167
+ </py.StatementList>
168
+ );
169
+
170
+ expect(<TestOutput externals={[abcModule]}>{decl}</TestOutput>).toRenderTo(`
171
+ class MyClass:
172
+ @computed_field
173
+ @deprecated("use width**2")
174
+ @property
175
+ def area(self) -> float:
176
+ return self.width ** 2
177
+
178
+
179
+ `);
180
+ });
181
+
182
+ it("stacks decorators above @property and @abstractmethod below it", () => {
183
+ const decl = (
184
+ <py.StatementList>
185
+ <py.ClassDeclaration name="MyClass">
186
+ <py.StatementList>
187
+ <py.PropertyDeclaration
188
+ name="area"
189
+ type="float"
190
+ abstract
191
+ decorators={[code`@computed_field`]}
192
+ >
193
+ return self.width ** 2
194
+ </py.PropertyDeclaration>
195
+ </py.StatementList>
196
+ </py.ClassDeclaration>
197
+ </py.StatementList>
198
+ );
199
+
200
+ expect(<TestOutput externals={[abcModule]}>{decl}</TestOutput>).toRenderTo(`
201
+ from abc import abstractmethod
202
+
203
+
204
+ class MyClass:
205
+ @computed_field
206
+ @property
207
+ @abstractmethod
208
+ def area(self) -> float:
209
+ return self.width ** 2
210
+
211
+
212
+ `);
213
+ });
214
+
151
215
  it("renders abstract property with getter, setter, deleter", () => {
152
216
  const decl = (
153
217
  <py.StatementList>
@@ -167,7 +231,7 @@ describe("PropertyDeclaration", () => {
167
231
  </py.StatementList>
168
232
  );
169
233
 
170
- expect(toSourceText([decl], { externals: [abcModule] })).toBe(d`
234
+ expect(<TestOutput externals={[abcModule]}>{decl}</TestOutput>).toRenderTo(`
171
235
  from abc import abstractmethod
172
236
 
173
237