@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,101 +1,102 @@
1
1
  import { Prose } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
3
2
  import { expect, it } from "vitest";
4
3
  import * as py from "../src/index.js";
5
4
  import { dataclassesModule } from "../src/index.js";
6
- import { toSourceText } from "./utils.jsx";
5
+ import { TestOutput, TestOutputDirectory } from "./utils.jsx";
7
6
 
8
7
  /**
9
- * toSourceText wraps the children in a SourceFile component
10
- * and renders it to a string.
8
+ * TestOutputDirectory wraps content in an Output component without a default
9
+ * SourceFile, so SourceFile components with their own path/props can be used.
11
10
  */
12
11
  it("renders an empty source file", () => {
13
- const result = toSourceText([]);
14
- expect(result).toRenderTo(d`
12
+ expect(<TestOutput></TestOutput>).toRenderTo(
13
+ `
15
14
 
16
-
17
- `);
15
+ `,
16
+ );
18
17
  });
19
18
 
20
19
  it("correct formatting of source file", () => {
21
- const result = toSourceText([
22
- <py.ClassDeclaration name="someClass">
23
- <py.StatementList>
24
- <py.FunctionDeclaration name="someMethod" returnType="str">
25
- <py.StatementList>
26
- <py.VariableDeclaration
27
- name="x"
28
- type="int"
29
- initializer={<py.Atom jsValue={42} />}
30
- />
31
- <py.VariableDeclaration
32
- name="y"
33
- type="int"
34
- initializer={<py.Atom jsValue={42} />}
35
- />
36
- <py.FunctionCallExpression target="foo" args={["a", "b"]} />
37
- <py.MemberExpression>
38
- <py.MemberExpression.Part id="a" />
39
- <py.MemberExpression.Part id="b" />
40
- <py.MemberExpression.Part key={"special-prop"} />
41
- </py.MemberExpression>
42
- <py.VariableDeclaration
43
- name="z"
44
- type="int"
45
- initializer={<py.Atom jsValue={42} />}
46
- />
47
- </py.StatementList>
48
- </py.FunctionDeclaration>
49
- <py.VariableDeclaration
50
- name="someVar"
51
- type="int"
52
- initializer={<py.Atom jsValue={42} />}
53
- />
54
- <py.FunctionDeclaration name="someOtherMethod" returnType="str" />
55
- <py.VariableDeclaration
56
- name="someOtherVar"
57
- type="int"
58
- initializer={<py.Atom jsValue={42} />}
59
- />
60
- </py.StatementList>
61
- </py.ClassDeclaration>,
62
- <py.FunctionDeclaration name="someFunction">
63
- <py.StatementList>
64
- <py.VariableDeclaration
65
- name="x"
66
- type="int"
67
- initializer={<py.Atom jsValue={42} />}
68
- />
69
- <py.VariableDeclaration
70
- name="y"
71
- type="int"
72
- initializer={<py.Atom jsValue={42} />}
73
- />
74
- <py.FunctionCallExpression target="foo" args={["a", "b"]} />
75
- <py.MemberExpression>
76
- <py.MemberExpression.Part id="a" />
77
- <py.MemberExpression.Part id="b" />
78
- <py.MemberExpression.Part key={"special-prop"} />
79
- </py.MemberExpression>
80
- <py.VariableDeclaration
81
- name="z"
82
- type="int"
83
- initializer={<py.Atom jsValue={42} />}
84
- />
85
- </py.StatementList>
86
- </py.FunctionDeclaration>,
87
- <py.ClassDeclaration name="someOtherClass">
88
- <py.StatementList>
89
- <py.FunctionDeclaration name="someMethod" returnType="str" />
90
- </py.StatementList>
91
- </py.ClassDeclaration>,
92
- <py.MemberExpression>
93
- <py.MemberExpression.Part id="a" />
94
- <py.MemberExpression.Part id="b" />
95
- <py.MemberExpression.Part key={"special-prop"} />
96
- </py.MemberExpression>,
97
- ]);
98
- expect(result).toRenderTo(d`
20
+ expect(
21
+ <TestOutput>
22
+ <py.ClassDeclaration name="someClass">
23
+ <py.StatementList>
24
+ <py.FunctionDeclaration name="someMethod" returnType="str">
25
+ <py.StatementList>
26
+ <py.VariableDeclaration
27
+ name="x"
28
+ type="int"
29
+ initializer={<py.Atom jsValue={42} />}
30
+ />
31
+ <py.VariableDeclaration
32
+ name="y"
33
+ type="int"
34
+ initializer={<py.Atom jsValue={42} />}
35
+ />
36
+ <py.FunctionCallExpression target="foo" args={["a", "b"]} />
37
+ <py.MemberExpression>
38
+ <py.MemberExpression.Part id="a" />
39
+ <py.MemberExpression.Part id="b" />
40
+ <py.MemberExpression.Part key={"special-prop"} />
41
+ </py.MemberExpression>
42
+ <py.VariableDeclaration
43
+ name="z"
44
+ type="int"
45
+ initializer={<py.Atom jsValue={42} />}
46
+ />
47
+ </py.StatementList>
48
+ </py.FunctionDeclaration>
49
+ <py.VariableDeclaration
50
+ name="someVar"
51
+ type="int"
52
+ initializer={<py.Atom jsValue={42} />}
53
+ />
54
+ <py.FunctionDeclaration name="someOtherMethod" returnType="str" />
55
+ <py.VariableDeclaration
56
+ name="someOtherVar"
57
+ type="int"
58
+ initializer={<py.Atom jsValue={42} />}
59
+ />
60
+ </py.StatementList>
61
+ </py.ClassDeclaration>
62
+ <py.FunctionDeclaration name="someFunction">
63
+ <py.StatementList>
64
+ <py.VariableDeclaration
65
+ name="x"
66
+ type="int"
67
+ initializer={<py.Atom jsValue={42} />}
68
+ />
69
+ <py.VariableDeclaration
70
+ name="y"
71
+ type="int"
72
+ initializer={<py.Atom jsValue={42} />}
73
+ />
74
+ <py.FunctionCallExpression target="foo" args={["a", "b"]} />
75
+ <py.MemberExpression>
76
+ <py.MemberExpression.Part id="a" />
77
+ <py.MemberExpression.Part id="b" />
78
+ <py.MemberExpression.Part key={"special-prop"} />
79
+ </py.MemberExpression>
80
+ <py.VariableDeclaration
81
+ name="z"
82
+ type="int"
83
+ initializer={<py.Atom jsValue={42} />}
84
+ />
85
+ </py.StatementList>
86
+ </py.FunctionDeclaration>
87
+ <py.ClassDeclaration name="someOtherClass">
88
+ <py.StatementList>
89
+ <py.FunctionDeclaration name="someMethod" returnType="str" />
90
+ </py.StatementList>
91
+ </py.ClassDeclaration>
92
+ <py.MemberExpression>
93
+ <py.MemberExpression.Part id="a" />
94
+ <py.MemberExpression.Part id="b" />
95
+ <py.MemberExpression.Part key={"special-prop"} />
96
+ </py.MemberExpression>
97
+ </TestOutput>,
98
+ ).toRenderTo(
99
+ `
99
100
  class SomeClass:
100
101
  def some_method() -> str:
101
102
  x: int = 42
@@ -126,8 +127,8 @@ it("correct formatting of source file", () => {
126
127
 
127
128
 
128
129
  a.b["special-prop"]
129
-
130
- `);
130
+ `,
131
+ );
131
132
  });
132
133
 
133
134
  it("renders module documentation correctly", () => {
@@ -156,15 +157,18 @@ it("renders module documentation correctly", () => {
156
157
  />
157
158
  );
158
159
 
159
- const content = (
160
- <py.SourceFile path="test.py" doc={moduleDoc}>
161
- <py.VariableDeclaration name="DEFAULT_TIMEOUT" initializer={30} />
162
- <py.VariableDeclaration name="MAX_RETRIES" initializer={3} />
163
- <py.FunctionDeclaration name="process_data">pass</py.FunctionDeclaration>
164
- </py.SourceFile>
165
- );
166
-
167
- expect(toSourceText(content)).toRenderTo(d`
160
+ expect(
161
+ <TestOutputDirectory>
162
+ <py.SourceFile path="test.py" doc={moduleDoc}>
163
+ <py.VariableDeclaration name="DEFAULT_TIMEOUT" initializer={30} />
164
+ <py.VariableDeclaration name="MAX_RETRIES" initializer={3} />
165
+ <py.FunctionDeclaration name="process_data">
166
+ pass
167
+ </py.FunctionDeclaration>
168
+ </py.SourceFile>
169
+ </TestOutputDirectory>,
170
+ ).toRenderTo({
171
+ "test.py": `
168
172
  """
169
173
  This module provides utility functions for data processing. It includes
170
174
  functions for validation, transformation, and analysis.
@@ -186,50 +190,52 @@ it("renders module documentation correctly", () => {
186
190
  def process_data():
187
191
  pass
188
192
 
189
-
190
- `);
193
+ `,
194
+ });
191
195
  });
192
196
 
193
197
  it("renders source file without documentation correctly", () => {
194
- const content = (
195
- <py.SourceFile path="test.py">
196
- <py.FunctionDeclaration name="hello_world">
197
- print("Hello, World!")
198
- </py.FunctionDeclaration>
199
- </py.SourceFile>
200
- );
201
-
202
- expect(toSourceText(content)).toRenderTo(d`
198
+ expect(
199
+ <TestOutputDirectory>
200
+ <py.SourceFile path="test.py">
201
+ <py.FunctionDeclaration name="hello_world">
202
+ print("Hello, World!")
203
+ </py.FunctionDeclaration>
204
+ </py.SourceFile>
205
+ </TestOutputDirectory>,
206
+ ).toRenderTo({
207
+ "test.py": `
203
208
  def hello_world():
204
209
  print("Hello, World!")
205
210
 
206
-
207
- `);
211
+ `,
212
+ });
208
213
  });
209
214
 
210
215
  it("nothing before top-level definition", () => {
211
- const content = (
212
- <py.SourceFile path="test.py">
213
- <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
214
- </py.SourceFile>
215
- );
216
-
217
- expect(toSourceText(content)).toRenderTo(d`
216
+ expect(
217
+ <TestOutputDirectory>
218
+ <py.SourceFile path="test.py">
219
+ <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
220
+ </py.SourceFile>
221
+ </TestOutputDirectory>,
222
+ ).toRenderTo({
223
+ "test.py": `
218
224
  def hello():
219
225
  pass
220
226
 
221
-
222
- `);
227
+ `,
228
+ });
223
229
  });
224
230
 
225
231
  it("nothing before non-definition", () => {
226
- const content = (
227
- <py.SourceFile path="test.py">
228
- <py.VariableDeclaration name="x" initializer={42} />
229
- </py.SourceFile>
230
- );
231
-
232
- expect(toSourceText(content)).toRenderTo("x = 42");
232
+ expect(
233
+ <TestOutputDirectory>
234
+ <py.SourceFile path="test.py">
235
+ <py.VariableDeclaration name="x" initializer={42} />
236
+ </py.SourceFile>
237
+ </TestOutputDirectory>,
238
+ ).toRenderTo({ "test.py": "x = 42" });
233
239
  });
234
240
 
235
241
  it("only doc before definition", () => {
@@ -237,13 +243,14 @@ it("only doc before definition", () => {
237
243
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
238
244
  );
239
245
 
240
- const content = (
241
- <py.SourceFile path="test.py" doc={moduleDoc}>
242
- <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
243
- </py.SourceFile>
244
- );
245
-
246
- expect(toSourceText(content)).toRenderTo(d`
246
+ expect(
247
+ <TestOutputDirectory>
248
+ <py.SourceFile path="test.py" doc={moduleDoc}>
249
+ <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
250
+ </py.SourceFile>
251
+ </TestOutputDirectory>,
252
+ ).toRenderTo({
253
+ "test.py": `
247
254
  """
248
255
  Module description.
249
256
  """
@@ -252,8 +259,8 @@ it("only doc before definition", () => {
252
259
  def hello():
253
260
  pass
254
261
 
255
-
256
- `);
262
+ `,
263
+ });
257
264
  });
258
265
 
259
266
  it("only doc before non-definition", () => {
@@ -261,101 +268,107 @@ it("only doc before non-definition", () => {
261
268
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
262
269
  );
263
270
 
264
- const content = (
265
- <py.SourceFile path="test.py" doc={moduleDoc}>
266
- <py.VariableDeclaration name="x" initializer={42} />
267
- </py.SourceFile>
268
- );
269
-
270
- expect(toSourceText(content)).toRenderTo(d`
271
+ expect(
272
+ <TestOutputDirectory>
273
+ <py.SourceFile path="test.py" doc={moduleDoc}>
274
+ <py.VariableDeclaration name="x" initializer={42} />
275
+ </py.SourceFile>
276
+ </TestOutputDirectory>,
277
+ ).toRenderTo({
278
+ "test.py": `
271
279
  """
272
280
  Module description.
273
281
  """
274
282
 
275
- x = 42`);
283
+ x = 42`,
284
+ });
276
285
  });
277
286
 
278
287
  it("only header before definition", () => {
279
- const content = (
280
- <py.SourceFile path="test.py" header="#!/usr/bin/env python3">
281
- <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
282
- </py.SourceFile>
283
- );
284
-
285
- // 2 blank lines before definition (PEP 8)
286
- expect(toSourceText(content)).toRenderTo(d`
288
+ expect(
289
+ <TestOutputDirectory>
290
+ <py.SourceFile path="test.py" header="#!/usr/bin/env python3">
291
+ <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
292
+ </py.SourceFile>
293
+ </TestOutputDirectory>,
294
+ ).toRenderTo({
295
+ "test.py": `
287
296
  #!/usr/bin/env python3
288
297
 
289
298
 
290
299
  def hello():
291
300
  pass
292
301
 
293
-
294
- `);
302
+ `,
303
+ });
295
304
  });
296
305
 
297
306
  it("only header before non-definition", () => {
298
- const content = (
299
- <py.SourceFile path="test.py" header="#!/usr/bin/env python3">
300
- <py.VariableDeclaration name="x" initializer={42} />
301
- </py.SourceFile>
302
- );
303
-
304
- // 1 blank line for non-definition
305
- expect(toSourceText(content)).toRenderTo(d`
307
+ expect(
308
+ <TestOutputDirectory>
309
+ <py.SourceFile path="test.py" header="#!/usr/bin/env python3">
310
+ <py.VariableDeclaration name="x" initializer={42} />
311
+ </py.SourceFile>
312
+ </TestOutputDirectory>,
313
+ ).toRenderTo({
314
+ "test.py": `
306
315
  #!/usr/bin/env python3
307
316
 
308
- x = 42`);
317
+ x = 42`,
318
+ });
309
319
  });
310
320
 
311
321
  it("only futureImports before definition", () => {
312
- const content = (
313
- <py.SourceFile
314
- path="test.py"
315
- futureImports={[<py.FutureStatement feature="annotations" />]}
316
- >
317
- <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
318
- </py.SourceFile>
319
- );
320
-
321
- expect(toSourceText(content)).toRenderTo(d`
322
+ expect(
323
+ <TestOutputDirectory>
324
+ <py.SourceFile
325
+ path="test.py"
326
+ futureImports={[<py.FutureStatement feature="annotations" />]}
327
+ >
328
+ <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
329
+ </py.SourceFile>
330
+ </TestOutputDirectory>,
331
+ ).toRenderTo({
332
+ "test.py": `
322
333
  from __future__ import annotations
323
334
 
324
335
 
325
336
  def hello():
326
337
  pass
327
338
 
328
-
329
- `);
339
+ `,
340
+ });
330
341
  });
331
342
 
332
343
  it("only futureImports before non-definition", () => {
333
- const content = (
334
- <py.SourceFile
335
- path="test.py"
336
- futureImports={[<py.FutureStatement feature="annotations" />]}
337
- >
338
- <py.VariableDeclaration name="x" initializer={42} />
339
- </py.SourceFile>
340
- );
341
-
342
- expect(toSourceText(content)).toRenderTo(d`
344
+ expect(
345
+ <TestOutputDirectory>
346
+ <py.SourceFile
347
+ path="test.py"
348
+ futureImports={[<py.FutureStatement feature="annotations" />]}
349
+ >
350
+ <py.VariableDeclaration name="x" initializer={42} />
351
+ </py.SourceFile>
352
+ </TestOutputDirectory>,
353
+ ).toRenderTo({
354
+ "test.py": `
343
355
  from __future__ import annotations
344
356
 
345
- x = 42`);
357
+ x = 42`,
358
+ });
346
359
  });
347
360
 
348
361
  it("only imports before definition", () => {
349
- const content = (
350
- <py.SourceFile path="test.py">
351
- <py.DataclassDeclaration name="User">
352
- <py.VariableDeclaration name="name" type="str" />
353
- </py.DataclassDeclaration>
354
- </py.SourceFile>
355
- );
356
-
357
- expect(toSourceText(content, { externals: [dataclassesModule] }))
358
- .toRenderTo(d`
362
+ expect(
363
+ <TestOutputDirectory externals={[dataclassesModule]}>
364
+ <py.SourceFile path="test.py">
365
+ <py.DataclassDeclaration name="User">
366
+ <py.VariableDeclaration name="name" type="str" />
367
+ </py.DataclassDeclaration>
368
+ </py.SourceFile>
369
+ </TestOutputDirectory>,
370
+ ).toRenderTo({
371
+ "test.py": `
359
372
  from dataclasses import dataclass
360
373
 
361
374
 
@@ -363,25 +376,28 @@ it("only imports before definition", () => {
363
376
  class User:
364
377
  name: str = None
365
378
 
366
-
367
- `);
379
+ `,
380
+ });
368
381
  });
369
382
 
370
383
  it("only imports before non-definition", () => {
371
- const content = (
372
- <py.SourceFile path="test.py">
373
- <py.VariableDeclaration
374
- name="x"
375
- initializer={<py.Reference refkey={dataclassesModule["."].dataclass} />}
376
- />
377
- </py.SourceFile>
378
- );
379
-
380
- expect(toSourceText(content, { externals: [dataclassesModule] }))
381
- .toRenderTo(d`
384
+ expect(
385
+ <TestOutputDirectory externals={[dataclassesModule]}>
386
+ <py.SourceFile path="test.py">
387
+ <py.VariableDeclaration
388
+ name="x"
389
+ initializer={
390
+ <py.Reference refkey={dataclassesModule["."].dataclass} />
391
+ }
392
+ />
393
+ </py.SourceFile>
394
+ </TestOutputDirectory>,
395
+ ).toRenderTo({
396
+ "test.py": `
382
397
  from dataclasses import dataclass
383
398
 
384
- x = dataclass`);
399
+ x = dataclass`,
400
+ });
385
401
  });
386
402
 
387
403
  it("doc + futureImports before definition", () => {
@@ -389,17 +405,18 @@ it("doc + futureImports before definition", () => {
389
405
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
390
406
  );
391
407
 
392
- const content = (
393
- <py.SourceFile
394
- path="test.py"
395
- doc={moduleDoc}
396
- futureImports={[<py.FutureStatement feature="annotations" />]}
397
- >
398
- <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
399
- </py.SourceFile>
400
- );
401
-
402
- expect(toSourceText(content)).toRenderTo(d`
408
+ expect(
409
+ <TestOutputDirectory>
410
+ <py.SourceFile
411
+ path="test.py"
412
+ doc={moduleDoc}
413
+ futureImports={[<py.FutureStatement feature="annotations" />]}
414
+ >
415
+ <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
416
+ </py.SourceFile>
417
+ </TestOutputDirectory>,
418
+ ).toRenderTo({
419
+ "test.py": `
403
420
  """
404
421
  Module description.
405
422
  """
@@ -410,8 +427,8 @@ it("doc + futureImports before definition", () => {
410
427
  def hello():
411
428
  pass
412
429
 
413
-
414
- `);
430
+ `,
431
+ });
415
432
  });
416
433
 
417
434
  it("doc + futureImports before non-definition", () => {
@@ -419,24 +436,26 @@ it("doc + futureImports before non-definition", () => {
419
436
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
420
437
  );
421
438
 
422
- const content = (
423
- <py.SourceFile
424
- path="test.py"
425
- doc={moduleDoc}
426
- futureImports={[<py.FutureStatement feature="annotations" />]}
427
- >
428
- <py.VariableDeclaration name="x" initializer={42} />
429
- </py.SourceFile>
430
- );
431
-
432
- expect(toSourceText(content)).toRenderTo(d`
439
+ expect(
440
+ <TestOutputDirectory>
441
+ <py.SourceFile
442
+ path="test.py"
443
+ doc={moduleDoc}
444
+ futureImports={[<py.FutureStatement feature="annotations" />]}
445
+ >
446
+ <py.VariableDeclaration name="x" initializer={42} />
447
+ </py.SourceFile>
448
+ </TestOutputDirectory>,
449
+ ).toRenderTo({
450
+ "test.py": `
433
451
  """
434
452
  Module description.
435
453
  """
436
454
 
437
455
  from __future__ import annotations
438
456
 
439
- x = 42`);
457
+ x = 42`,
458
+ });
440
459
  });
441
460
 
442
461
  it("doc + imports before definition", () => {
@@ -444,16 +463,16 @@ it("doc + imports before definition", () => {
444
463
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
445
464
  );
446
465
 
447
- const content = (
448
- <py.SourceFile path="test.py" doc={moduleDoc}>
449
- <py.DataclassDeclaration name="User">
450
- <py.VariableDeclaration name="name" type="str" />
451
- </py.DataclassDeclaration>
452
- </py.SourceFile>
453
- );
454
-
455
- expect(toSourceText(content, { externals: [dataclassesModule] }))
456
- .toRenderTo(d`
466
+ expect(
467
+ <TestOutputDirectory externals={[dataclassesModule]}>
468
+ <py.SourceFile path="test.py" doc={moduleDoc}>
469
+ <py.DataclassDeclaration name="User">
470
+ <py.VariableDeclaration name="name" type="str" />
471
+ </py.DataclassDeclaration>
472
+ </py.SourceFile>
473
+ </TestOutputDirectory>,
474
+ ).toRenderTo({
475
+ "test.py": `
457
476
  """
458
477
  Module description.
459
478
  """
@@ -465,8 +484,8 @@ it("doc + imports before definition", () => {
465
484
  class User:
466
485
  name: str = None
467
486
 
468
-
469
- `);
487
+ `,
488
+ });
470
489
  });
471
490
 
472
491
  it("doc + imports before non-definition", () => {
@@ -474,40 +493,43 @@ it("doc + imports before non-definition", () => {
474
493
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
475
494
  );
476
495
 
477
- const content = (
478
- <py.SourceFile path="test.py" doc={moduleDoc}>
479
- <py.VariableDeclaration
480
- name="x"
481
- initializer={<py.Reference refkey={dataclassesModule["."].dataclass} />}
482
- />
483
- </py.SourceFile>
484
- );
485
-
486
- expect(toSourceText(content, { externals: [dataclassesModule] }))
487
- .toRenderTo(d`
496
+ expect(
497
+ <TestOutputDirectory externals={[dataclassesModule]}>
498
+ <py.SourceFile path="test.py" doc={moduleDoc}>
499
+ <py.VariableDeclaration
500
+ name="x"
501
+ initializer={
502
+ <py.Reference refkey={dataclassesModule["."].dataclass} />
503
+ }
504
+ />
505
+ </py.SourceFile>
506
+ </TestOutputDirectory>,
507
+ ).toRenderTo({
508
+ "test.py": `
488
509
  """
489
510
  Module description.
490
511
  """
491
512
 
492
513
  from dataclasses import dataclass
493
514
 
494
- x = dataclass`);
515
+ x = dataclass`,
516
+ });
495
517
  });
496
518
 
497
519
  it("futureImports + imports before definition", () => {
498
- const content = (
499
- <py.SourceFile
500
- path="test.py"
501
- futureImports={[<py.FutureStatement feature="annotations" />]}
502
- >
503
- <py.DataclassDeclaration name="User">
504
- <py.VariableDeclaration name="name" type="str" />
505
- </py.DataclassDeclaration>
506
- </py.SourceFile>
507
- );
508
-
509
- expect(toSourceText(content, { externals: [dataclassesModule] }))
510
- .toRenderTo(d`
520
+ expect(
521
+ <TestOutputDirectory externals={[dataclassesModule]}>
522
+ <py.SourceFile
523
+ path="test.py"
524
+ futureImports={[<py.FutureStatement feature="annotations" />]}
525
+ >
526
+ <py.DataclassDeclaration name="User">
527
+ <py.VariableDeclaration name="name" type="str" />
528
+ </py.DataclassDeclaration>
529
+ </py.SourceFile>
530
+ </TestOutputDirectory>,
531
+ ).toRenderTo({
532
+ "test.py": `
511
533
  from __future__ import annotations
512
534
 
513
535
  from dataclasses import dataclass
@@ -517,30 +539,33 @@ it("futureImports + imports before definition", () => {
517
539
  class User:
518
540
  name: str = None
519
541
 
520
-
521
- `);
542
+ `,
543
+ });
522
544
  });
523
545
 
524
546
  it("futureImports + imports before non-definition", () => {
525
- const content = (
526
- <py.SourceFile
527
- path="test.py"
528
- futureImports={[<py.FutureStatement feature="annotations" />]}
529
- >
530
- <py.VariableDeclaration
531
- name="x"
532
- initializer={<py.Reference refkey={dataclassesModule["."].dataclass} />}
533
- />
534
- </py.SourceFile>
535
- );
536
-
537
- expect(toSourceText(content, { externals: [dataclassesModule] }))
538
- .toRenderTo(d`
547
+ expect(
548
+ <TestOutputDirectory externals={[dataclassesModule]}>
549
+ <py.SourceFile
550
+ path="test.py"
551
+ futureImports={[<py.FutureStatement feature="annotations" />]}
552
+ >
553
+ <py.VariableDeclaration
554
+ name="x"
555
+ initializer={
556
+ <py.Reference refkey={dataclassesModule["."].dataclass} />
557
+ }
558
+ />
559
+ </py.SourceFile>
560
+ </TestOutputDirectory>,
561
+ ).toRenderTo({
562
+ "test.py": `
539
563
  from __future__ import annotations
540
564
 
541
565
  from dataclasses import dataclass
542
566
 
543
- x = dataclass`);
567
+ x = dataclass`,
568
+ });
544
569
  });
545
570
 
546
571
  it("doc + futureImports + imports before definition", () => {
@@ -548,20 +573,20 @@ it("doc + futureImports + imports before definition", () => {
548
573
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
549
574
  );
550
575
 
551
- const content = (
552
- <py.SourceFile
553
- path="test.py"
554
- doc={moduleDoc}
555
- futureImports={[<py.FutureStatement feature="annotations" />]}
556
- >
557
- <py.DataclassDeclaration name="User">
558
- <py.VariableDeclaration name="name" type="str" />
559
- </py.DataclassDeclaration>
560
- </py.SourceFile>
561
- );
562
-
563
- expect(toSourceText(content, { externals: [dataclassesModule] }))
564
- .toRenderTo(d`
576
+ expect(
577
+ <TestOutputDirectory externals={[dataclassesModule]}>
578
+ <py.SourceFile
579
+ path="test.py"
580
+ doc={moduleDoc}
581
+ futureImports={[<py.FutureStatement feature="annotations" />]}
582
+ >
583
+ <py.DataclassDeclaration name="User">
584
+ <py.VariableDeclaration name="name" type="str" />
585
+ </py.DataclassDeclaration>
586
+ </py.SourceFile>
587
+ </TestOutputDirectory>,
588
+ ).toRenderTo({
589
+ "test.py": `
565
590
  """
566
591
  Module description.
567
592
  """
@@ -575,8 +600,8 @@ it("doc + futureImports + imports before definition", () => {
575
600
  class User:
576
601
  name: str = None
577
602
 
578
-
579
- `);
603
+ `,
604
+ });
580
605
  });
581
606
 
582
607
  it("doc + futureImports + imports before non-definition", () => {
@@ -584,21 +609,23 @@ it("doc + futureImports + imports before non-definition", () => {
584
609
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
585
610
  );
586
611
 
587
- const content = (
588
- <py.SourceFile
589
- path="test.py"
590
- doc={moduleDoc}
591
- futureImports={[<py.FutureStatement feature="annotations" />]}
592
- >
593
- <py.VariableDeclaration
594
- name="x"
595
- initializer={<py.Reference refkey={dataclassesModule["."].dataclass} />}
596
- />
597
- </py.SourceFile>
598
- );
599
-
600
- expect(toSourceText(content, { externals: [dataclassesModule] }))
601
- .toRenderTo(d`
612
+ expect(
613
+ <TestOutputDirectory externals={[dataclassesModule]}>
614
+ <py.SourceFile
615
+ path="test.py"
616
+ doc={moduleDoc}
617
+ futureImports={[<py.FutureStatement feature="annotations" />]}
618
+ >
619
+ <py.VariableDeclaration
620
+ name="x"
621
+ initializer={
622
+ <py.Reference refkey={dataclassesModule["."].dataclass} />
623
+ }
624
+ />
625
+ </py.SourceFile>
626
+ </TestOutputDirectory>,
627
+ ).toRenderTo({
628
+ "test.py": `
602
629
  """
603
630
  Module description.
604
631
  """
@@ -607,7 +634,8 @@ it("doc + futureImports + imports before non-definition", () => {
607
634
 
608
635
  from dataclasses import dataclass
609
636
 
610
- x = dataclass`);
637
+ x = dataclass`,
638
+ });
611
639
  });
612
640
 
613
641
  it("only doc in file (no children)", () => {
@@ -615,41 +643,44 @@ it("only doc in file (no children)", () => {
615
643
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
616
644
  );
617
645
 
618
- const content = <py.SourceFile path="test.py" doc={moduleDoc} />;
619
-
620
- expect(toSourceText(content)).toRenderTo(d`
646
+ expect(
647
+ <TestOutputDirectory>
648
+ <py.SourceFile path="test.py" doc={moduleDoc} />
649
+ </TestOutputDirectory>,
650
+ ).toRenderTo({
651
+ "test.py": `
621
652
  """
622
653
  Module description.
623
654
  """
624
655
 
625
-
626
- `);
656
+ `,
657
+ });
627
658
  });
628
659
 
629
660
  it("only header in file (no children)", () => {
630
- const content = (
631
- <py.SourceFile path="test.py" header="#!/usr/bin/env python3" />
632
- );
633
-
634
- expect(toSourceText(content)).toRenderTo(d`
661
+ expect(
662
+ <TestOutputDirectory>
663
+ <py.SourceFile path="test.py" header="#!/usr/bin/env python3" />
664
+ </TestOutputDirectory>,
665
+ ).toRenderTo({
666
+ "test.py": `
635
667
  #!/usr/bin/env python3
636
668
 
637
-
638
- `);
669
+ `,
670
+ });
639
671
  });
640
672
 
641
673
  it("only futureImports in file (no children)", () => {
642
- const content = (
643
- <py.SourceFile
644
- path="test.py"
645
- futureImports={[<py.FutureStatement feature="annotations" />]}
646
- />
647
- );
648
-
649
- expect(toSourceText(content)).toRenderTo(d`
650
- from __future__ import annotations
651
-
652
- `);
674
+ expect(
675
+ <TestOutputDirectory>
676
+ <py.SourceFile
677
+ path="test.py"
678
+ futureImports={[<py.FutureStatement feature="annotations" />]}
679
+ />
680
+ </TestOutputDirectory>,
681
+ ).toRenderTo({
682
+ "test.py": "from __future__ import annotations",
683
+ });
653
684
  });
654
685
 
655
686
  it("doc + futureImports in file (no children)", () => {
@@ -657,55 +688,58 @@ it("doc + futureImports in file (no children)", () => {
657
688
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
658
689
  );
659
690
 
660
- const content = (
661
- <py.SourceFile
662
- path="test.py"
663
- doc={moduleDoc}
664
- futureImports={[<py.FutureStatement feature="annotations" />]}
665
- />
666
- );
667
-
668
- expect(toSourceText(content)).toRenderTo(d`
691
+ expect(
692
+ <TestOutputDirectory>
693
+ <py.SourceFile
694
+ path="test.py"
695
+ doc={moduleDoc}
696
+ futureImports={[<py.FutureStatement feature="annotations" />]}
697
+ />
698
+ </TestOutputDirectory>,
699
+ ).toRenderTo({
700
+ "test.py": `
669
701
  """
670
702
  Module description.
671
703
  """
672
704
 
673
705
  from __future__ import annotations
674
-
675
- `);
706
+ `,
707
+ });
676
708
  });
677
709
 
678
710
  // headerComment tests
679
711
  it("only headerComment before definition", () => {
680
- const content = (
681
- <py.SourceFile path="test.py" headerComment="Copyright 2024 My Company">
682
- <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
683
- </py.SourceFile>
684
- );
685
-
686
- // 2 blank lines before definition (PEP 8)
687
- expect(toSourceText(content)).toRenderTo(d`
712
+ expect(
713
+ <TestOutputDirectory>
714
+ <py.SourceFile path="test.py" headerComment="Copyright 2024 My Company">
715
+ <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
716
+ </py.SourceFile>
717
+ </TestOutputDirectory>,
718
+ ).toRenderTo({
719
+ "test.py": `
688
720
  # Copyright 2024 My Company
689
721
 
690
722
 
691
723
  def hello():
692
724
  pass
693
725
 
694
-
695
- `);
726
+ `,
727
+ });
696
728
  });
697
729
 
698
730
  it("only headerComment before non-definition", () => {
699
- const content = (
700
- <py.SourceFile path="test.py" headerComment="Copyright 2024 My Company">
701
- <py.VariableDeclaration name="x" initializer={42} />
702
- </py.SourceFile>
703
- );
704
-
705
- expect(toSourceText(content)).toRenderTo(d`
731
+ expect(
732
+ <TestOutputDirectory>
733
+ <py.SourceFile path="test.py" headerComment="Copyright 2024 My Company">
734
+ <py.VariableDeclaration name="x" initializer={42} />
735
+ </py.SourceFile>
736
+ </TestOutputDirectory>,
737
+ ).toRenderTo({
738
+ "test.py": `
706
739
  # Copyright 2024 My Company
707
740
 
708
- x = 42`);
741
+ x = 42`,
742
+ });
709
743
  });
710
744
 
711
745
  it("headerComment + doc before definition", () => {
@@ -713,18 +747,18 @@ it("headerComment + doc before definition", () => {
713
747
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
714
748
  );
715
749
 
716
- const content = (
717
- <py.SourceFile
718
- path="test.py"
719
- headerComment="Copyright 2024 My Company"
720
- doc={moduleDoc}
721
- >
722
- <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
723
- </py.SourceFile>
724
- );
725
-
726
- // headerComment and doc adjacent, then PEP 8 spacing before definition
727
- expect(toSourceText(content)).toRenderTo(d`
750
+ expect(
751
+ <TestOutputDirectory>
752
+ <py.SourceFile
753
+ path="test.py"
754
+ headerComment="Copyright 2024 My Company"
755
+ doc={moduleDoc}
756
+ >
757
+ <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
758
+ </py.SourceFile>
759
+ </TestOutputDirectory>,
760
+ ).toRenderTo({
761
+ "test.py": `
728
762
  # Copyright 2024 My Company
729
763
  """
730
764
  Module description.
@@ -734,23 +768,23 @@ it("headerComment + doc before definition", () => {
734
768
  def hello():
735
769
  pass
736
770
 
737
-
738
- `);
771
+ `,
772
+ });
739
773
  });
740
774
 
741
775
  it("headerComment + futureImports before definition", () => {
742
- const content = (
743
- <py.SourceFile
744
- path="test.py"
745
- headerComment="Copyright 2024 My Company"
746
- futureImports={[<py.FutureStatement feature="annotations" />]}
747
- >
748
- <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
749
- </py.SourceFile>
750
- );
751
-
752
- // headerComment and futureImports adjacent, then PEP 8 spacing
753
- expect(toSourceText(content)).toRenderTo(d`
776
+ expect(
777
+ <TestOutputDirectory>
778
+ <py.SourceFile
779
+ path="test.py"
780
+ headerComment="Copyright 2024 My Company"
781
+ futureImports={[<py.FutureStatement feature="annotations" />]}
782
+ >
783
+ <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
784
+ </py.SourceFile>
785
+ </TestOutputDirectory>,
786
+ ).toRenderTo({
787
+ "test.py": `
754
788
  # Copyright 2024 My Company
755
789
 
756
790
  from __future__ import annotations
@@ -759,21 +793,21 @@ it("headerComment + futureImports before definition", () => {
759
793
  def hello():
760
794
  pass
761
795
 
762
-
763
- `);
796
+ `,
797
+ });
764
798
  });
765
799
 
766
800
  it("headerComment + imports before definition", () => {
767
- const content = (
768
- <py.SourceFile path="test.py" headerComment="Copyright 2024 My Company">
769
- <py.DataclassDeclaration name="User">
770
- <py.VariableDeclaration name="name" type="str" />
771
- </py.DataclassDeclaration>
772
- </py.SourceFile>
773
- );
774
-
775
- expect(toSourceText(content, { externals: [dataclassesModule] }))
776
- .toRenderTo(d`
801
+ expect(
802
+ <TestOutputDirectory externals={[dataclassesModule]}>
803
+ <py.SourceFile path="test.py" headerComment="Copyright 2024 My Company">
804
+ <py.DataclassDeclaration name="User">
805
+ <py.VariableDeclaration name="name" type="str" />
806
+ </py.DataclassDeclaration>
807
+ </py.SourceFile>
808
+ </TestOutputDirectory>,
809
+ ).toRenderTo({
810
+ "test.py": `
777
811
  # Copyright 2024 My Company
778
812
 
779
813
  from dataclasses import dataclass
@@ -783,8 +817,8 @@ it("headerComment + imports before definition", () => {
783
817
  class User:
784
818
  name: str = None
785
819
 
786
-
787
- `);
820
+ `,
821
+ });
788
822
  });
789
823
 
790
824
  it("headerComment + doc + futureImports before definition", () => {
@@ -792,18 +826,19 @@ it("headerComment + doc + futureImports before definition", () => {
792
826
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
793
827
  );
794
828
 
795
- const content = (
796
- <py.SourceFile
797
- path="test.py"
798
- headerComment="Copyright 2024 My Company"
799
- doc={moduleDoc}
800
- futureImports={[<py.FutureStatement feature="annotations" />]}
801
- >
802
- <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
803
- </py.SourceFile>
804
- );
805
-
806
- expect(toSourceText(content)).toRenderTo(d`
829
+ expect(
830
+ <TestOutputDirectory>
831
+ <py.SourceFile
832
+ path="test.py"
833
+ headerComment="Copyright 2024 My Company"
834
+ doc={moduleDoc}
835
+ futureImports={[<py.FutureStatement feature="annotations" />]}
836
+ >
837
+ <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
838
+ </py.SourceFile>
839
+ </TestOutputDirectory>,
840
+ ).toRenderTo({
841
+ "test.py": `
807
842
  # Copyright 2024 My Company
808
843
  """
809
844
  Module description.
@@ -815,8 +850,8 @@ it("headerComment + doc + futureImports before definition", () => {
815
850
  def hello():
816
851
  pass
817
852
 
818
-
819
- `);
853
+ `,
854
+ });
820
855
  });
821
856
 
822
857
  it("headerComment + doc + futureImports + imports before definition", () => {
@@ -824,21 +859,21 @@ it("headerComment + doc + futureImports + imports before definition", () => {
824
859
  <py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
825
860
  );
826
861
 
827
- const content = (
828
- <py.SourceFile
829
- path="test.py"
830
- headerComment="Copyright 2024 My Company"
831
- doc={moduleDoc}
832
- futureImports={[<py.FutureStatement feature="annotations" />]}
833
- >
834
- <py.DataclassDeclaration name="User">
835
- <py.VariableDeclaration name="name" type="str" />
836
- </py.DataclassDeclaration>
837
- </py.SourceFile>
838
- );
839
-
840
- expect(toSourceText(content, { externals: [dataclassesModule] }))
841
- .toRenderTo(d`
862
+ expect(
863
+ <TestOutputDirectory externals={[dataclassesModule]}>
864
+ <py.SourceFile
865
+ path="test.py"
866
+ headerComment="Copyright 2024 My Company"
867
+ doc={moduleDoc}
868
+ futureImports={[<py.FutureStatement feature="annotations" />]}
869
+ >
870
+ <py.DataclassDeclaration name="User">
871
+ <py.VariableDeclaration name="name" type="str" />
872
+ </py.DataclassDeclaration>
873
+ </py.SourceFile>
874
+ </TestOutputDirectory>,
875
+ ).toRenderTo({
876
+ "test.py": `
842
877
  # Copyright 2024 My Company
843
878
  """
844
879
  Module description.
@@ -853,34 +888,33 @@ it("headerComment + doc + futureImports + imports before definition", () => {
853
888
  class User:
854
889
  name: str = None
855
890
 
856
-
857
- `);
891
+ `,
892
+ });
858
893
  });
859
894
 
860
895
  it("only headerComment in file (no children)", () => {
861
- const content = (
862
- <py.SourceFile path="test.py" headerComment="Copyright 2024 My Company" />
863
- );
864
-
865
- expect(toSourceText(content)).toRenderTo(d`
866
- # Copyright 2024 My Company
867
-
868
- `);
896
+ expect(
897
+ <TestOutputDirectory>
898
+ <py.SourceFile path="test.py" headerComment="Copyright 2024 My Company" />
899
+ </TestOutputDirectory>,
900
+ ).toRenderTo({
901
+ "test.py": "# Copyright 2024 My Company",
902
+ });
869
903
  });
870
904
 
871
905
  it("header + headerComment before definition", () => {
872
- const content = (
873
- <py.SourceFile
874
- path="test.py"
875
- header="#!/usr/bin/env python3"
876
- headerComment="Copyright 2024 My Company"
877
- >
878
- <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
879
- </py.SourceFile>
880
- );
881
-
882
- // 2 blank lines before definition (PEP 8)
883
- expect(toSourceText(content)).toRenderTo(d`
906
+ expect(
907
+ <TestOutputDirectory>
908
+ <py.SourceFile
909
+ path="test.py"
910
+ header="#!/usr/bin/env python3"
911
+ headerComment="Copyright 2024 My Company"
912
+ >
913
+ <py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
914
+ </py.SourceFile>
915
+ </TestOutputDirectory>,
916
+ ).toRenderTo({
917
+ "test.py": `
884
918
  #!/usr/bin/env python3
885
919
  # Copyright 2024 My Company
886
920
 
@@ -888,23 +922,23 @@ it("header + headerComment before definition", () => {
888
922
  def hello():
889
923
  pass
890
924
 
891
-
892
- `);
925
+ `,
926
+ });
893
927
  });
894
928
 
895
929
  it("header + headerComment before class definition", () => {
896
- const content = (
897
- <py.SourceFile
898
- path="test.py"
899
- header="#!/usr/bin/env python3"
900
- headerComment="Copyright 2024 My Company"
901
- >
902
- <py.ClassDeclaration name="MyClass">pass</py.ClassDeclaration>
903
- </py.SourceFile>
904
- );
905
-
906
- // 2 blank lines before definition (PEP 8)
907
- expect(toSourceText(content)).toRenderTo(d`
930
+ expect(
931
+ <TestOutputDirectory>
932
+ <py.SourceFile
933
+ path="test.py"
934
+ header="#!/usr/bin/env python3"
935
+ headerComment="Copyright 2024 My Company"
936
+ >
937
+ <py.ClassDeclaration name="MyClass">pass</py.ClassDeclaration>
938
+ </py.SourceFile>
939
+ </TestOutputDirectory>,
940
+ ).toRenderTo({
941
+ "test.py": `
908
942
  #!/usr/bin/env python3
909
943
  # Copyright 2024 My Company
910
944
 
@@ -912,25 +946,26 @@ it("header + headerComment before class definition", () => {
912
946
  class MyClass:
913
947
  pass
914
948
 
915
-
916
- `);
949
+ `,
950
+ });
917
951
  });
918
952
 
919
953
  it("header + headerComment before non-definition", () => {
920
- const content = (
921
- <py.SourceFile
922
- path="test.py"
923
- header="#!/usr/bin/env python3"
924
- headerComment="Copyright 2024 My Company"
925
- >
926
- <py.VariableDeclaration name="x" initializer={42} />
927
- </py.SourceFile>
928
- );
929
-
930
- // 1 blank line for non-definition
931
- expect(toSourceText(content)).toRenderTo(d`
954
+ expect(
955
+ <TestOutputDirectory>
956
+ <py.SourceFile
957
+ path="test.py"
958
+ header="#!/usr/bin/env python3"
959
+ headerComment="Copyright 2024 My Company"
960
+ >
961
+ <py.VariableDeclaration name="x" initializer={42} />
962
+ </py.SourceFile>
963
+ </TestOutputDirectory>,
964
+ ).toRenderTo({
965
+ "test.py": `
932
966
  #!/usr/bin/env python3
933
967
  # Copyright 2024 My Company
934
968
 
935
- x = 42`);
969
+ x = 42`,
970
+ });
936
971
  });