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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/dev/src/components/CallSignature.js +2 -2
  3. package/dist/dev/src/components/CallSignature.js.map +1 -1
  4. package/dist/dev/src/components/ConstructorDeclaration.js +1 -1
  5. package/dist/dev/src/components/ConstructorDeclaration.js.map +1 -1
  6. package/dist/dev/src/components/DataclassDeclaration.js +5 -5
  7. package/dist/dev/src/components/DataclassDeclaration.js.map +1 -1
  8. package/dist/dev/src/components/FunctionBase.js +9 -9
  9. package/dist/dev/src/components/FunctionBase.js.map +1 -1
  10. package/dist/dev/src/components/PropertyDeclaration.js +8 -8
  11. package/dist/dev/src/components/PropertyDeclaration.js.map +1 -1
  12. package/dist/dev/src/components/PyDoc.js +64 -64
  13. package/dist/dev/src/components/PyDoc.js.map +1 -1
  14. package/dist/dev/src/components/PydanticClassDeclaration.js +5 -5
  15. package/dist/dev/src/components/PydanticClassDeclaration.js.map +1 -1
  16. package/dist/dev/src/components/SourceFile.js +44 -32
  17. package/dist/dev/src/components/SourceFile.js.map +1 -1
  18. package/dist/dev/src/symbols/python-output-symbol.js.map +1 -1
  19. package/dist/dev/test/callsignatures.test.js +471 -297
  20. package/dist/dev/test/callsignatures.test.js.map +1 -1
  21. package/dist/dev/test/class-method-declaration.test.js +21 -10
  22. package/dist/dev/test/class-method-declaration.test.js.map +1 -1
  23. package/dist/dev/test/classdeclarations.test.js +459 -393
  24. package/dist/dev/test/classdeclarations.test.js.map +1 -1
  25. package/dist/dev/test/classinstantiations.test.js +201 -168
  26. package/dist/dev/test/classinstantiations.test.js.map +1 -1
  27. package/dist/dev/test/constructordeclaration.test.js +22 -11
  28. package/dist/dev/test/constructordeclaration.test.js.map +1 -1
  29. package/dist/dev/test/dataclassdeclarations.test.js +322 -368
  30. package/dist/dev/test/dataclassdeclarations.test.js.map +1 -1
  31. package/dist/dev/test/decoratorlist.test.js +96 -49
  32. package/dist/dev/test/decoratorlist.test.js.map +1 -1
  33. package/dist/dev/test/dundermethoddeclaration.test.js +22 -11
  34. package/dist/dev/test/dundermethoddeclaration.test.js.map +1 -1
  35. package/dist/dev/test/enums.test.js +218 -184
  36. package/dist/dev/test/enums.test.js.map +1 -1
  37. package/dist/dev/test/externals.test.js +57 -45
  38. package/dist/dev/test/externals.test.js.map +1 -1
  39. package/dist/dev/test/factories.test.js +124 -50
  40. package/dist/dev/test/factories.test.js.map +1 -1
  41. package/dist/dev/test/functioncallexpressions.test.js +199 -164
  42. package/dist/dev/test/functioncallexpressions.test.js.map +1 -1
  43. package/dist/dev/test/functiondeclaration.test.js +439 -272
  44. package/dist/dev/test/functiondeclaration.test.js.map +1 -1
  45. package/dist/dev/test/imports.test.js +273 -221
  46. package/dist/dev/test/imports.test.js.map +1 -1
  47. package/dist/dev/test/memberexpressions.test.js +1237 -972
  48. package/dist/dev/test/memberexpressions.test.js.map +1 -1
  49. package/dist/dev/test/methoddeclaration.test.js +142 -78
  50. package/dist/dev/test/methoddeclaration.test.js.map +1 -1
  51. package/dist/dev/test/namepolicies.test.js +130 -94
  52. package/dist/dev/test/namepolicies.test.js.map +1 -1
  53. package/dist/dev/test/propertydeclaration.test.js +88 -59
  54. package/dist/dev/test/propertydeclaration.test.js.map +1 -1
  55. package/dist/dev/test/pydanticclassdeclarations.test.js +299 -347
  56. package/dist/dev/test/pydanticclassdeclarations.test.js.map +1 -1
  57. package/dist/dev/test/pydocs.test.js +888 -715
  58. package/dist/dev/test/pydocs.test.js.map +1 -1
  59. package/dist/dev/test/references.test.js +42 -35
  60. package/dist/dev/test/references.test.js.map +1 -1
  61. package/dist/dev/test/sourcefiles.test.js +1109 -841
  62. package/dist/dev/test/sourcefiles.test.js.map +1 -1
  63. package/dist/dev/test/staticmethoddeclaration.test.js +21 -10
  64. package/dist/dev/test/staticmethoddeclaration.test.js.map +1 -1
  65. package/dist/dev/test/type-checking-imports.test.js +408 -359
  66. package/dist/dev/test/type-checking-imports.test.js.map +1 -1
  67. package/dist/dev/test/typereference.test.js +55 -40
  68. package/dist/dev/test/typereference.test.js.map +1 -1
  69. package/dist/dev/test/uniontypeexpression.test.js +222 -146
  70. package/dist/dev/test/uniontypeexpression.test.js.map +1 -1
  71. package/dist/dev/test/utils.js +39 -77
  72. package/dist/dev/test/utils.js.map +1 -1
  73. package/dist/dev/test/values.test.js +237 -101
  74. package/dist/dev/test/values.test.js.map +1 -1
  75. package/dist/dev/test/variables.test.js +321 -203
  76. package/dist/dev/test/variables.test.js.map +1 -1
  77. package/dist/dev/test/vitest.setup.js +2 -0
  78. package/dist/dev/test/vitest.setup.js.map +1 -0
  79. package/dist/src/components/CallSignature.d.ts.map +1 -1
  80. package/dist/src/components/CallSignature.js.map +1 -1
  81. package/dist/src/components/ConstructorDeclaration.d.ts.map +1 -1
  82. package/dist/src/components/ConstructorDeclaration.js.map +1 -1
  83. package/dist/src/components/DataclassDeclaration.d.ts.map +1 -1
  84. package/dist/src/components/DataclassDeclaration.js.map +1 -1
  85. package/dist/src/components/FunctionBase.d.ts.map +1 -1
  86. package/dist/src/components/FunctionBase.js.map +1 -1
  87. package/dist/src/components/PropertyDeclaration.d.ts.map +1 -1
  88. package/dist/src/components/PropertyDeclaration.js.map +1 -1
  89. package/dist/src/components/PyDoc.d.ts.map +1 -1
  90. package/dist/src/components/PyDoc.js.map +1 -1
  91. package/dist/src/components/PydanticClassDeclaration.d.ts.map +1 -1
  92. package/dist/src/components/PydanticClassDeclaration.js.map +1 -1
  93. package/dist/src/components/SourceFile.d.ts +2 -2
  94. package/dist/src/components/SourceFile.d.ts.map +1 -1
  95. package/dist/src/components/SourceFile.js +12 -0
  96. package/dist/src/components/SourceFile.js.map +1 -1
  97. package/dist/src/symbols/python-output-symbol.d.ts.map +1 -1
  98. package/dist/src/symbols/python-output-symbol.js.map +1 -1
  99. package/dist/test/callsignatures.test.js +346 -272
  100. package/dist/test/callsignatures.test.js.map +1 -1
  101. package/dist/test/class-method-declaration.test.js +7 -4
  102. package/dist/test/class-method-declaration.test.js.map +1 -1
  103. package/dist/test/classdeclarations.test.js +302 -288
  104. package/dist/test/classdeclarations.test.js.map +1 -1
  105. package/dist/test/classinstantiations.test.js +112 -103
  106. package/dist/test/classinstantiations.test.js.map +1 -1
  107. package/dist/test/constructordeclaration.test.js +7 -4
  108. package/dist/test/constructordeclaration.test.js.map +1 -1
  109. package/dist/test/dataclassdeclarations.test.js +134 -184
  110. package/dist/test/dataclassdeclarations.test.js.map +1 -1
  111. package/dist/test/decoratorlist.test.js +59 -36
  112. package/dist/test/decoratorlist.test.js.map +1 -1
  113. package/dist/test/dundermethoddeclaration.test.js +7 -4
  114. package/dist/test/dundermethoddeclaration.test.js.map +1 -1
  115. package/dist/test/enums.test.js +161 -159
  116. package/dist/test/enums.test.js.map +1 -1
  117. package/dist/test/externals.test.js +24 -24
  118. package/dist/test/externals.test.js.map +1 -1
  119. package/dist/test/factories.test.js +75 -33
  120. package/dist/test/factories.test.js.map +1 -1
  121. package/dist/test/functioncallexpressions.test.js +117 -106
  122. package/dist/test/functioncallexpressions.test.js.map +1 -1
  123. package/dist/test/functiondeclaration.test.js +247 -180
  124. package/dist/test/functiondeclaration.test.js.map +1 -1
  125. package/dist/test/imports.test.js +171 -143
  126. package/dist/test/imports.test.js.map +1 -1
  127. package/dist/test/memberexpressions.test.js +582 -453
  128. package/dist/test/memberexpressions.test.js.map +1 -1
  129. package/dist/test/methoddeclaration.test.js +66 -46
  130. package/dist/test/methoddeclaration.test.js.map +1 -1
  131. package/dist/test/namepolicies.test.js +90 -78
  132. package/dist/test/namepolicies.test.js.map +1 -1
  133. package/dist/test/propertydeclaration.test.js +25 -20
  134. package/dist/test/propertydeclaration.test.js.map +1 -1
  135. package/dist/test/pydanticclassdeclarations.test.js +134 -190
  136. package/dist/test/pydanticclassdeclarations.test.js.map +1 -1
  137. package/dist/test/pydocs.test.js +573 -532
  138. package/dist/test/pydocs.test.js.map +1 -1
  139. package/dist/test/references.test.js +31 -28
  140. package/dist/test/references.test.js.map +1 -1
  141. package/dist/test/sourcefiles.test.js +700 -580
  142. package/dist/test/sourcefiles.test.js.map +1 -1
  143. package/dist/test/staticmethoddeclaration.test.js +7 -4
  144. package/dist/test/staticmethoddeclaration.test.js.map +1 -1
  145. package/dist/test/type-checking-imports.test.js +297 -284
  146. package/dist/test/type-checking-imports.test.js.map +1 -1
  147. package/dist/test/typereference.test.js +29 -22
  148. package/dist/test/typereference.test.js.map +1 -1
  149. package/dist/test/uniontypeexpression.test.js +124 -88
  150. package/dist/test/uniontypeexpression.test.js.map +1 -1
  151. package/dist/test/utils.d.ts +10 -17
  152. package/dist/test/utils.d.ts.map +1 -1
  153. package/dist/test/utils.js +32 -74
  154. package/dist/test/utils.js.map +1 -1
  155. package/dist/test/values.test.js +135 -67
  156. package/dist/test/values.test.js.map +1 -1
  157. package/dist/test/variables.test.js +201 -151
  158. package/dist/test/variables.test.js.map +1 -1
  159. package/dist/test/vitest.setup.d.ts +2 -0
  160. package/dist/test/vitest.setup.d.ts.map +1 -0
  161. package/dist/test/vitest.setup.js +2 -0
  162. package/dist/test/vitest.setup.js.map +1 -0
  163. package/dist/tsconfig.tsbuildinfo +1 -1
  164. package/docs/api/components/FunctionalEnumDeclaration.md +3 -6
  165. package/docs/api/components/MemberExpression.md +1 -5
  166. package/docs/api/components/SourceFile.md +20 -8
  167. package/docs/api/components/index.md +0 -2
  168. package/docs/api/functions/isTypeRefContext.md +1 -1
  169. package/docs/api/index.md +2 -2
  170. package/docs/api/types/ReferenceProps.md +7 -0
  171. package/docs/api/types/TypeRefContextProps.md +7 -0
  172. package/docs/api/types/index.md +2 -0
  173. package/package.json +11 -10
  174. package/src/components/CallSignature.tsx +4 -2
  175. package/src/components/ConstructorDeclaration.tsx +4 -2
  176. package/src/components/DataclassDeclaration.tsx +1 -2
  177. package/src/components/FunctionBase.tsx +1 -2
  178. package/src/components/PropertyDeclaration.tsx +8 -4
  179. package/src/components/PyDoc.tsx +12 -6
  180. package/src/components/PydanticClassDeclaration.tsx +1 -2
  181. package/src/components/SourceFile.tsx +6 -1
  182. package/src/symbols/python-output-symbol.ts +1 -2
  183. package/temp/api.json +107 -61
  184. package/test/callsignatures.test.tsx +309 -283
  185. package/test/class-method-declaration.test.tsx +3 -4
  186. package/test/classdeclarations.test.tsx +263 -248
  187. package/test/classinstantiations.test.tsx +115 -109
  188. package/test/constructordeclaration.test.tsx +9 -6
  189. package/test/dataclassdeclarations.test.tsx +243 -361
  190. package/test/decoratorlist.test.tsx +78 -59
  191. package/test/dundermethoddeclaration.test.tsx +3 -4
  192. package/test/enums.test.tsx +65 -81
  193. package/test/externals.test.tsx +25 -25
  194. package/test/factories.test.tsx +64 -22
  195. package/test/functioncallexpressions.test.tsx +123 -109
  196. package/test/functiondeclaration.test.tsx +209 -148
  197. package/test/imports.test.tsx +119 -91
  198. package/test/memberexpressions.test.tsx +265 -207
  199. package/test/methoddeclaration.test.tsx +84 -63
  200. package/test/namepolicies.test.tsx +69 -69
  201. package/test/propertydeclaration.test.tsx +7 -8
  202. package/test/pydanticclassdeclarations.test.tsx +355 -487
  203. package/test/pydocs.test.tsx +531 -579
  204. package/test/references.test.tsx +24 -23
  205. package/test/sourcefiles.test.tsx +527 -492
  206. package/test/staticmethoddeclaration.test.tsx +3 -4
  207. package/test/type-checking-imports.test.tsx +206 -218
  208. package/test/typereference.test.tsx +15 -12
  209. package/test/uniontypeexpression.test.tsx +74 -61
  210. package/test/utils.tsx +26 -110
  211. package/test/values.test.tsx +82 -32
  212. package/test/variables.test.tsx +162 -142
  213. package/test/vitest.setup.ts +1 -0
  214. package/tsdoc-metadata.json +1 -1
  215. package/vitest.config.ts +4 -0
  216. package/docs/api/components/Reference.md +0 -31
  217. package/docs/api/components/TypeRefContext.md +0 -41
@@ -1,26 +1,24 @@
1
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
1
+ import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
2
  import { Prose } from "@alloy-js/core";
3
- import { d } from "@alloy-js/core/testing";
4
3
  import { describe, expect, it } from "vitest";
5
4
  import { enumModule } 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("PyDoc", () => {
9
8
  it("formats properly", () => {
10
- const res = toSourceText([_$createComponent(py.PyDoc, {
9
+ expect(_$createComponent(TestOutput, {
11
10
  get children() {
12
- return [_$createComponent(Prose, {
13
- children: "This is an example of a long docstring that will be broken in lines. We will also render another paragraph after this one."
14
- }), _$createComponent(Prose, {
15
- children: "This is another paragraph, and there's a line break before it."
16
- })];
17
- }
18
- })], {
19
- printOptions: {
20
- printWidth: 40
11
+ return _$createComponent(py.PyDoc, {
12
+ get children() {
13
+ return [_$createComponent(Prose, {
14
+ children: "This is an example of a long docstring that will be broken in lines. We will also render another paragraph after this one."
15
+ }), _$createComponent(Prose, {
16
+ children: "This is another paragraph, and there's a line break before it."
17
+ })];
18
+ }
19
+ });
21
20
  }
22
- });
23
- expect(res).toRenderTo(d`
21
+ })).toRenderTo(`
24
22
  """
25
23
  This is an example of a long docstring
26
24
  that will be broken in lines. We will
@@ -31,26 +29,27 @@ describe("PyDoc", () => {
31
29
  line break before it.
32
30
  """
33
31
 
34
-
35
- `);
32
+ `, {
33
+ tabWidth: 4,
34
+ printWidth: 40
35
+ });
36
36
  });
37
37
  });
38
38
  describe("PyDocExample", () => {
39
39
  it("creates docstring with a code sample", () => {
40
- const res = toSourceText([_$createComponent(py.PyDoc, {
40
+ expect(_$createComponent(TestOutput, {
41
41
  get children() {
42
- return [_$createComponent(Prose, {
43
- children: "This is an example of a docstring with a code sample."
44
- }), _$createComponent(py.PyDocExample, {
45
- children: "print(\"Hello world!\")"
46
- })];
47
- }
48
- })], {
49
- printOptions: {
50
- printWidth: 40
42
+ return _$createComponent(py.PyDoc, {
43
+ get children() {
44
+ return [_$createComponent(Prose, {
45
+ children: "This is an example of a docstring with a code sample."
46
+ }), _$createComponent(py.PyDocExample, {
47
+ children: "print(\"Hello world!\")"
48
+ })];
49
+ }
50
+ });
51
51
  }
52
- });
53
- expect(res).toRenderTo(d`
52
+ })).toRenderTo(`
54
53
  """
55
54
  This is an example of a docstring with a
56
55
  code sample.
@@ -58,26 +57,27 @@ describe("PyDocExample", () => {
58
57
  >> print("Hello world!")
59
58
  """
60
59
 
61
-
62
- `);
60
+ `, {
61
+ tabWidth: 4,
62
+ printWidth: 40
63
+ });
63
64
  });
64
65
  it("creates docstring with more than one code sample", () => {
65
- const res = toSourceText([_$createComponent(py.PyDoc, {
66
+ expect(_$createComponent(TestOutput, {
66
67
  get children() {
67
- return [_$createComponent(Prose, {
68
- children: "This is an example of a docstring with a code sample."
69
- }), _$createComponent(py.PyDocExample, {
70
- children: "print(\"Hello world!\")"
71
- }), _$createComponent(py.PyDocExample, {
72
- children: "print(\"Hello world again!\")"
73
- })];
74
- }
75
- })], {
76
- printOptions: {
77
- printWidth: 40
68
+ return _$createComponent(py.PyDoc, {
69
+ get children() {
70
+ return [_$createComponent(Prose, {
71
+ children: "This is an example of a docstring with a code sample."
72
+ }), _$createComponent(py.PyDocExample, {
73
+ children: "print(\"Hello world!\")"
74
+ }), _$createComponent(py.PyDocExample, {
75
+ children: "print(\"Hello world again!\")"
76
+ })];
77
+ }
78
+ });
78
79
  }
79
- });
80
- expect(res).toRenderTo(d`
80
+ })).toRenderTo(`
81
81
  """
82
82
  This is an example of a docstring with a
83
83
  code sample.
@@ -87,24 +87,25 @@ describe("PyDocExample", () => {
87
87
  >> print("Hello world again!")
88
88
  """
89
89
 
90
-
91
- `);
90
+ `, {
91
+ tabWidth: 4,
92
+ printWidth: 40
93
+ });
92
94
  });
93
95
  it("creates docstring with a multiline code sample", () => {
94
- const res = toSourceText([_$createComponent(py.PyDoc, {
96
+ expect(_$createComponent(TestOutput, {
95
97
  get children() {
96
- return [_$createComponent(Prose, {
97
- children: "This is an example of a docstring with a code sample."
98
- }), _$createComponent(py.PyDocExample, {
99
- children: `print("Hello world!")\nx = "Hello"\nprint(x)`
100
- })];
101
- }
102
- })], {
103
- printOptions: {
104
- printWidth: 40
98
+ return _$createComponent(py.PyDoc, {
99
+ get children() {
100
+ return [_$createComponent(Prose, {
101
+ children: "This is an example of a docstring with a code sample."
102
+ }), _$createComponent(py.PyDocExample, {
103
+ children: `print("Hello world!")\nx = "Hello"\nprint(x)`
104
+ })];
105
+ }
106
+ });
105
107
  }
106
- });
107
- expect(res).toRenderTo(d`
108
+ })).toRenderTo(`
108
109
  """
109
110
  This is an example of a docstring with a
110
111
  code sample.
@@ -114,74 +115,85 @@ describe("PyDocExample", () => {
114
115
  >> print(x)
115
116
  """
116
117
 
117
-
118
- `);
118
+ `, {
119
+ tabWidth: 4,
120
+ printWidth: 40
121
+ });
119
122
  });
120
123
  });
121
124
  describe("SimpleCommentBlock", () => {
122
125
  it("renders simple comment block", () => {
123
- const res = toSourceText([_$createComponent(py.SimpleCommentBlock, {
124
- children: "This is a simple comment block that spans multiple lines and should be split automatically."
125
- })]);
126
- expect(res).toRenderTo(d`
126
+ expect(_$createComponent(TestOutput, {
127
+ get children() {
128
+ return _$createComponent(py.SimpleCommentBlock, {
129
+ children: "This is a simple comment block that spans multiple lines and should be split automatically."
130
+ });
131
+ }
132
+ })).toRenderTo(`
127
133
  # This is a simple comment block that spans multiple lines and should be split
128
134
  # automatically.
129
-
130
135
  `);
131
136
  });
132
137
  it("renders comment block with line breaks", () => {
133
- const res = toSourceText([_$createComponent(py.SimpleCommentBlock, {
134
- children: "First line of comment.\\nSecond line of comment."
135
- })]);
136
- expect(res).toRenderTo(d`
138
+ expect(_$createComponent(TestOutput, {
139
+ get children() {
140
+ return _$createComponent(py.SimpleCommentBlock, {
141
+ children: "First line of comment.\\nSecond line of comment."
142
+ });
143
+ }
144
+ })).toRenderTo(`
137
145
  # First line of comment.
138
146
  # Second line of comment.
139
-
140
147
  `);
141
148
  });
142
149
  });
143
150
  describe("SimpleInlineComment", () => {
144
151
  it("renders inline comment", () => {
145
- const res = toSourceText([["x = 42", _$createComponent(py.SimpleInlineComment, {
146
- children: "This is an inline comment"
147
- })]]);
148
- expect(res).toRenderTo(d`
149
- x = 42 # This is an inline comment
150
- `);
152
+ expect(_$createComponent(TestOutput, {
153
+ get children() {
154
+ return [["x = 42", _$createComponent(py.SimpleInlineComment, {
155
+ children: "This is an inline comment"
156
+ })]];
157
+ }
158
+ })).toRenderTo(`x = 42 # This is an inline comment`);
151
159
  });
152
160
  it("renders inline comment with complex text", () => {
153
- const res = toSourceText([["result = calculate()", _$createComponent(py.SimpleInlineComment, {
154
- children: "TODO: Add error handling here"
155
- })]]);
156
- expect(res).toRenderTo(d`
157
- result = calculate() # TODO: Add error handling here
158
- `);
161
+ expect(_$createComponent(TestOutput, {
162
+ get children() {
163
+ return [["result = calculate()", _$createComponent(py.SimpleInlineComment, {
164
+ children: "TODO: Add error handling here"
165
+ })]];
166
+ }
167
+ })).toRenderTo(`result = calculate() # TODO: Add error handling here`);
159
168
  });
160
169
  });
161
170
  describe("New Documentation Components", () => {
162
171
  it("ModuleDoc renders correctly", () => {
163
- const res = toSourceText([_$createComponent(py.ModuleDoc, {
164
- get description() {
165
- return [_$createComponent(Prose, {
166
- children: "This module demonstrates documentation as specified by the Google Python Style Guide."
167
- })];
168
- },
169
- attributes: [{
170
- name: "module_level_variable1",
171
- type: "int",
172
- children: "Module level variables may be documented."
173
- }],
174
- get examples() {
175
- return [_$createComponent(py.PyDocExample, {
176
- children: "print(\"mod\")"
177
- })];
178
- },
179
- seeAlso: ["another_module.func", "RelatedClass"],
180
- warning: "Internal API.",
181
- deprecated: "Use new_module instead.",
182
- todo: ["For module TODOs", "You have to also use sphinx.ext.todo extension"]
183
- })]);
184
- expect(res).toRenderTo(d`
172
+ expect(_$createComponent(TestOutput, {
173
+ get children() {
174
+ return _$createComponent(py.ModuleDoc, {
175
+ get description() {
176
+ return [_$createComponent(Prose, {
177
+ children: "This module demonstrates documentation as specified by the Google Python Style Guide."
178
+ })];
179
+ },
180
+ attributes: [{
181
+ name: "module_level_variable1",
182
+ type: "int",
183
+ children: "Module level variables may be documented."
184
+ }],
185
+ get examples() {
186
+ return [_$createComponent(py.PyDocExample, {
187
+ children: "print(\"mod\")"
188
+ })];
189
+ },
190
+ seeAlso: ["another_module.func", "RelatedClass"],
191
+ warning: "Internal API.",
192
+ deprecated: "Use new_module instead.",
193
+ todo: ["For module TODOs", "You have to also use sphinx.ext.todo extension"]
194
+ });
195
+ }
196
+ })).toRenderTo(`
185
197
  """
186
198
  This module demonstrates documentation as specified by the Google Python Style
187
199
  Guide.
@@ -207,28 +219,30 @@ describe("New Documentation Components", () => {
207
219
  * You have to also use sphinx.ext.todo extension
208
220
  """
209
221
 
210
-
211
222
  `);
212
223
  });
213
224
  it("PropertyDoc renders correctly", () => {
214
- const res = toSourceText([_$createComponent(py.PropertyDoc, {
215
- get description() {
216
- return [_$createComponent(Prose, {
217
- children: "Properties should be documented in their getter method."
218
- })];
219
- },
220
- returns: "str: The readonly property value.",
221
- get examples() {
222
- return [_$createComponent(py.PyDocExample, {
223
- children: "print(obj.name)"
224
- })];
225
- },
226
- seeAlso: ["other_property"],
227
- warning: "Access may be slow.",
228
- deprecated: "Use full_name instead.",
229
- note: "If the setter method contains notable behavior, it should be mentioned here."
230
- })]);
231
- expect(res).toRenderTo(d`
225
+ expect(_$createComponent(TestOutput, {
226
+ get children() {
227
+ return _$createComponent(py.PropertyDoc, {
228
+ get description() {
229
+ return [_$createComponent(Prose, {
230
+ children: "Properties should be documented in their getter method."
231
+ })];
232
+ },
233
+ returns: "str: The readonly property value.",
234
+ get examples() {
235
+ return [_$createComponent(py.PyDocExample, {
236
+ children: "print(obj.name)"
237
+ })];
238
+ },
239
+ seeAlso: ["other_property"],
240
+ warning: "Access may be slow.",
241
+ deprecated: "Use full_name instead.",
242
+ note: "If the setter method contains notable behavior, it should be mentioned here."
243
+ });
244
+ }
245
+ })).toRenderTo(`
232
246
  """
233
247
  Properties should be documented in their getter method.
234
248
 
@@ -251,33 +265,35 @@ describe("New Documentation Components", () => {
251
265
  If the setter method contains notable behavior, it should be mentioned here.
252
266
  """
253
267
 
254
-
255
268
  `);
256
269
  });
257
270
  it("GeneratorDoc renders correctly", () => {
258
- const res = toSourceText([_$createComponent(py.GeneratorDoc, {
259
- get description() {
260
- return [_$createComponent(Prose, {
261
- children: "Generators have a Yields section instead of a Returns section."
262
- })];
263
- },
264
- parameters: [{
265
- name: "n",
266
- type: "int",
267
- doc: "The upper limit of the range to generate, from 0 to n - 1."
268
- }],
269
- yields: "int: The next number in the range of 0 to n - 1.",
270
- get examples() {
271
- return [_$createComponent(py.PyDocExample, {
272
- children: "print(next(gen))"
273
- })];
274
- },
275
- seeAlso: ["make_generator"],
276
- warning: "Do not consume in tight loops without sleep.",
277
- deprecated: "Use new_generator instead.",
278
- note: "Examples should be written in doctest format."
279
- })]);
280
- expect(res).toRenderTo(d`
271
+ expect(_$createComponent(TestOutput, {
272
+ get children() {
273
+ return _$createComponent(py.GeneratorDoc, {
274
+ get description() {
275
+ return [_$createComponent(Prose, {
276
+ children: "Generators have a Yields section instead of a Returns section."
277
+ })];
278
+ },
279
+ parameters: [{
280
+ name: "n",
281
+ type: "int",
282
+ doc: "The upper limit of the range to generate, from 0 to n - 1."
283
+ }],
284
+ yields: "int: The next number in the range of 0 to n - 1.",
285
+ get examples() {
286
+ return [_$createComponent(py.PyDocExample, {
287
+ children: "print(next(gen))"
288
+ })];
289
+ },
290
+ seeAlso: ["make_generator"],
291
+ warning: "Do not consume in tight loops without sleep.",
292
+ deprecated: "Use new_generator instead.",
293
+ note: "Examples should be written in doctest format."
294
+ });
295
+ }
296
+ })).toRenderTo(`
281
297
  """
282
298
  Generators have a Yields section instead of a Returns section.
283
299
 
@@ -303,40 +319,42 @@ describe("New Documentation Components", () => {
303
319
  Examples should be written in doctest format.
304
320
  """
305
321
 
306
-
307
322
  `);
308
323
  });
309
324
  it("ExceptionDoc renders correctly", () => {
310
- const res = toSourceText([_$createComponent(py.ExceptionDoc, {
311
- get description() {
312
- return [_$createComponent(Prose, {
313
- children: "Exceptions are documented in the same way as classes."
314
- })];
315
- },
316
- parameters: [{
317
- name: "msg",
318
- type: "str",
319
- doc: "Human readable string describing the exception."
320
- }, {
321
- name: "code",
322
- type: "int",
323
- default: undefined,
324
- doc: "Error code."
325
- }],
326
- attributes: [{
327
- name: "msg",
328
- type: "str",
329
- children: "Human readable string describing the exception."
330
- }, {
331
- name: "code",
332
- type: "int",
333
- children: "Exception error code."
334
- }],
335
- seeAlso: ["BaseException"],
336
- deprecated: "Use NewException instead.",
337
- note: "Do not include the 'self' parameter in the Args section."
338
- })]);
339
- expect(res).toRenderTo(d`
325
+ expect(_$createComponent(TestOutput, {
326
+ get children() {
327
+ return _$createComponent(py.ExceptionDoc, {
328
+ get description() {
329
+ return [_$createComponent(Prose, {
330
+ children: "Exceptions are documented in the same way as classes."
331
+ })];
332
+ },
333
+ parameters: [{
334
+ name: "msg",
335
+ type: "str",
336
+ doc: "Human readable string describing the exception."
337
+ }, {
338
+ name: "code",
339
+ type: "int",
340
+ default: undefined,
341
+ doc: "Error code."
342
+ }],
343
+ attributes: [{
344
+ name: "msg",
345
+ type: "str",
346
+ children: "Human readable string describing the exception."
347
+ }, {
348
+ name: "code",
349
+ type: "int",
350
+ children: "Exception error code."
351
+ }],
352
+ seeAlso: ["BaseException"],
353
+ deprecated: "Use NewException instead.",
354
+ note: "Do not include the 'self' parameter in the Args section."
355
+ });
356
+ }
357
+ })).toRenderTo(`
340
358
  """
341
359
  Exceptions are documented in the same way as classes.
342
360
 
@@ -360,27 +378,29 @@ describe("New Documentation Components", () => {
360
378
  Do not include the 'self' parameter in the Args section.
361
379
  """
362
380
 
363
-
364
381
  `);
365
382
  });
366
383
  it("MethodDoc renders correctly without default note", () => {
367
- const res = toSourceText([_$createComponent(py.MethodDoc, {
368
- get description() {
369
- return [_$createComponent(Prose, {
370
- children: "Class methods are similar to regular functions."
371
- })];
372
- },
373
- parameters: [{
374
- name: "param1",
375
- doc: "The first parameter."
376
- }, {
377
- name: "param2",
378
- doc: "The second parameter."
379
- }],
380
- returns: "True if successful, False otherwise.",
381
- overrides: "Base.method"
382
- })]);
383
- expect(res).toRenderTo(d`
384
+ expect(_$createComponent(TestOutput, {
385
+ get children() {
386
+ return _$createComponent(py.MethodDoc, {
387
+ get description() {
388
+ return [_$createComponent(Prose, {
389
+ children: "Class methods are similar to regular functions."
390
+ })];
391
+ },
392
+ parameters: [{
393
+ name: "param1",
394
+ doc: "The first parameter."
395
+ }, {
396
+ name: "param2",
397
+ doc: "The second parameter."
398
+ }],
399
+ returns: "True if successful, False otherwise.",
400
+ overrides: "Base.method"
401
+ });
402
+ }
403
+ })).toRenderTo(`
384
404
  """
385
405
  Class methods are similar to regular functions.
386
406
 
@@ -396,24 +416,26 @@ describe("New Documentation Components", () => {
396
416
  Base.method
397
417
  """
398
418
 
399
-
400
419
  `);
401
420
  });
402
421
  it("MethodDoc renders correctly with custom note", () => {
403
- const res = toSourceText([_$createComponent(py.MethodDoc, {
404
- get description() {
405
- return [_$createComponent(Prose, {
406
- children: "Class methods are similar to regular functions."
407
- })];
408
- },
409
- parameters: [{
410
- name: "param1",
411
- doc: "The first parameter."
412
- }],
413
- returns: "True if successful, False otherwise.",
414
- note: "This method has special behavior when called multiple times."
415
- })]);
416
- expect(res).toRenderTo(d`
422
+ expect(_$createComponent(TestOutput, {
423
+ get children() {
424
+ return _$createComponent(py.MethodDoc, {
425
+ get description() {
426
+ return [_$createComponent(Prose, {
427
+ children: "Class methods are similar to regular functions."
428
+ })];
429
+ },
430
+ parameters: [{
431
+ name: "param1",
432
+ doc: "The first parameter."
433
+ }],
434
+ returns: "True if successful, False otherwise.",
435
+ note: "This method has special behavior when called multiple times."
436
+ });
437
+ }
438
+ })).toRenderTo(`
417
439
  """
418
440
  Class methods are similar to regular functions.
419
441
 
@@ -427,35 +449,39 @@ describe("New Documentation Components", () => {
427
449
  This method has special behavior when called multiple times.
428
450
  """
429
451
 
430
-
431
452
  `);
432
453
  });
433
454
  it("ModuleDoc with minimal content", () => {
434
- const res = toSourceText([_$createComponent(py.ModuleDoc, {
435
- get description() {
436
- return [_$createComponent(Prose, {
437
- children: "Simple module description."
438
- })];
455
+ expect(_$createComponent(TestOutput, {
456
+ get children() {
457
+ return _$createComponent(py.ModuleDoc, {
458
+ get description() {
459
+ return [_$createComponent(Prose, {
460
+ children: "Simple module description."
461
+ })];
462
+ }
463
+ });
439
464
  }
440
- })]);
441
- expect(res).toRenderTo(d`
465
+ })).toRenderTo(`
442
466
  """
443
467
  Simple module description.
444
468
  """
445
469
 
446
-
447
470
  `);
448
471
  });
449
472
  it("ModuleDoc with only todo items", () => {
450
- const res = toSourceText([_$createComponent(py.ModuleDoc, {
451
- get description() {
452
- return [_$createComponent(Prose, {
453
- children: "Module with pending tasks."
454
- })];
455
- },
456
- todo: ["Implement feature X", "Add more tests", "Update documentation"]
457
- })]);
458
- expect(res).toRenderTo(d`
473
+ expect(_$createComponent(TestOutput, {
474
+ get children() {
475
+ return _$createComponent(py.ModuleDoc, {
476
+ get description() {
477
+ return [_$createComponent(Prose, {
478
+ children: "Module with pending tasks."
479
+ })];
480
+ },
481
+ todo: ["Implement feature X", "Add more tests", "Update documentation"]
482
+ });
483
+ }
484
+ })).toRenderTo(`
459
485
  """
460
486
  Module with pending tasks.
461
487
 
@@ -465,36 +491,40 @@ describe("New Documentation Components", () => {
465
491
  * Update documentation
466
492
  """
467
493
 
468
-
469
494
  `);
470
495
  });
471
496
  it("PropertyDoc minimal (description only)", () => {
472
- const res = toSourceText([_$createComponent(py.PropertyDoc, {
473
- get description() {
474
- return [_$createComponent(Prose, {
475
- children: "A simple readonly property."
476
- })];
497
+ expect(_$createComponent(TestOutput, {
498
+ get children() {
499
+ return _$createComponent(py.PropertyDoc, {
500
+ get description() {
501
+ return [_$createComponent(Prose, {
502
+ children: "A simple readonly property."
503
+ })];
504
+ }
505
+ });
477
506
  }
478
- })]);
479
- expect(res).toRenderTo(d`
507
+ })).toRenderTo(`
480
508
  """
481
509
  A simple readonly property.
482
510
  """
483
511
 
484
-
485
512
  `);
486
513
  });
487
514
  it("PropertyDoc with getter and setter info", () => {
488
- const res = toSourceText([_$createComponent(py.PropertyDoc, {
489
- get description() {
490
- return [_$createComponent(Prose, {
491
- children: "Properties with both a getter and setter should only be documented in their getter method."
492
- })];
493
- },
494
- returns: ":obj:`list` of :obj:`str`: The property value.",
495
- note: "If the setter method contains notable behavior, it should be mentioned here."
496
- })]);
497
- expect(res).toRenderTo(d`
515
+ expect(_$createComponent(TestOutput, {
516
+ get children() {
517
+ return _$createComponent(py.PropertyDoc, {
518
+ get description() {
519
+ return [_$createComponent(Prose, {
520
+ children: "Properties with both a getter and setter should only be documented in their getter method."
521
+ })];
522
+ },
523
+ returns: ":obj:`list` of :obj:`str`: The property value.",
524
+ note: "If the setter method contains notable behavior, it should be mentioned here."
525
+ });
526
+ }
527
+ })).toRenderTo(`
498
528
  """
499
529
  Properties with both a getter and setter should only be documented in their
500
530
  getter method.
@@ -506,35 +536,37 @@ describe("New Documentation Components", () => {
506
536
  If the setter method contains notable behavior, it should be mentioned here.
507
537
  """
508
538
 
509
-
510
539
  `);
511
540
  });
512
541
  it("GeneratorDoc with complex parameters", () => {
513
- const res = toSourceText([_$createComponent(py.GeneratorDoc, {
514
- get description() {
515
- return [_$createComponent(Prose, {
516
- children: "A more complex generator example with multiple parameters."
517
- })];
518
- },
519
- parameters: [{
520
- name: "start",
521
- type: "int",
522
- default: "0",
523
- doc: "Starting value for the sequence."
524
- }, {
525
- name: "stop",
526
- type: "int",
527
- doc: "Ending value for the sequence (exclusive)."
528
- }, {
529
- name: "step",
530
- type: "int",
531
- default: "1",
532
- doc: "Step size between values."
533
- }],
534
- yields: "int: The next number in the sequence.",
535
- raises: ["ValueError: If step is zero.", "TypeError: If parameters are not integers."]
536
- })]);
537
- expect(res).toRenderTo(d`
542
+ expect(_$createComponent(TestOutput, {
543
+ get children() {
544
+ return _$createComponent(py.GeneratorDoc, {
545
+ get description() {
546
+ return [_$createComponent(Prose, {
547
+ children: "A more complex generator example with multiple parameters."
548
+ })];
549
+ },
550
+ parameters: [{
551
+ name: "start",
552
+ type: "int",
553
+ default: "0",
554
+ doc: "Starting value for the sequence."
555
+ }, {
556
+ name: "stop",
557
+ type: "int",
558
+ doc: "Ending value for the sequence (exclusive)."
559
+ }, {
560
+ name: "step",
561
+ type: "int",
562
+ default: "1",
563
+ doc: "Step size between values."
564
+ }],
565
+ yields: "int: The next number in the sequence.",
566
+ raises: ["ValueError: If step is zero.", "TypeError: If parameters are not integers."]
567
+ });
568
+ }
569
+ })).toRenderTo(`
538
570
  """
539
571
  A more complex generator example with multiple parameters.
540
572
 
@@ -555,49 +587,51 @@ describe("New Documentation Components", () => {
555
587
  TypeError: If parameters are not integers.
556
588
  """
557
589
 
558
-
559
590
  `);
560
591
  });
561
592
  it("ExceptionDoc with comprehensive documentation", () => {
562
- const res = toSourceText([_$createComponent(py.ExceptionDoc, {
563
- get description() {
564
- return [_$createComponent(Prose, {
565
- children: "A custom exception for authentication failures."
566
- }), _$createComponent(Prose, {
567
- children: "This exception is raised when authentication credentials are invalid or when authentication tokens have expired."
568
- })];
569
- },
570
- parameters: [{
571
- name: "message",
572
- type: "str",
573
- doc: "Human readable error message describing the authentication failure."
574
- }, {
575
- name: "error_code",
576
- type: "int",
577
- default: "401",
578
- doc: "HTTP error code associated with the authentication failure."
579
- }, {
580
- name: "retry_after",
581
- type: "int",
582
- default: undefined,
583
- doc: "Number of seconds to wait before retrying authentication."
584
- }],
585
- attributes: [{
586
- name: "message",
587
- type: "str",
588
- children: "The error message."
589
- }, {
590
- name: "error_code",
591
- type: "int",
592
- children: "HTTP status code."
593
- }, {
594
- name: "retry_after",
595
- type: "int",
596
- children: "Retry delay in seconds, if applicable."
597
- }],
598
- note: "This exception should be caught and handled gracefully in production code."
599
- })]);
600
- expect(res).toRenderTo(d`
593
+ expect(_$createComponent(TestOutput, {
594
+ get children() {
595
+ return _$createComponent(py.ExceptionDoc, {
596
+ get description() {
597
+ return [_$createComponent(Prose, {
598
+ children: "A custom exception for authentication failures."
599
+ }), _$createComponent(Prose, {
600
+ children: "This exception is raised when authentication credentials are invalid or when authentication tokens have expired."
601
+ })];
602
+ },
603
+ parameters: [{
604
+ name: "message",
605
+ type: "str",
606
+ doc: "Human readable error message describing the authentication failure."
607
+ }, {
608
+ name: "error_code",
609
+ type: "int",
610
+ default: "401",
611
+ doc: "HTTP error code associated with the authentication failure."
612
+ }, {
613
+ name: "retry_after",
614
+ type: "int",
615
+ default: undefined,
616
+ doc: "Number of seconds to wait before retrying authentication."
617
+ }],
618
+ attributes: [{
619
+ name: "message",
620
+ type: "str",
621
+ children: "The error message."
622
+ }, {
623
+ name: "error_code",
624
+ type: "int",
625
+ children: "HTTP status code."
626
+ }, {
627
+ name: "retry_after",
628
+ type: "int",
629
+ children: "Retry delay in seconds, if applicable."
630
+ }],
631
+ note: "This exception should be caught and handled gracefully in production code."
632
+ });
633
+ }
634
+ })).toRenderTo(`
601
635
  """
602
636
  A custom exception for authentication failures.
603
637
 
@@ -624,24 +658,26 @@ describe("New Documentation Components", () => {
624
658
  This exception should be caught and handled gracefully in production code.
625
659
  """
626
660
 
627
-
628
661
  `);
629
662
  });
630
663
  it("MethodDoc with raises but no returns", () => {
631
- const res = toSourceText([_$createComponent(py.MethodDoc, {
632
- get description() {
633
- return [_$createComponent(Prose, {
634
- children: "A method that performs an action but doesn't return a value."
635
- })];
636
- },
637
- parameters: [{
638
- name: "data",
639
- type: "bytes",
640
- doc: "Raw data to process."
641
- }],
642
- raises: ["ValueError: If data is empty or invalid.", "IOError: If processing fails due to I/O issues."]
643
- })]);
644
- expect(res).toRenderTo(d`
664
+ expect(_$createComponent(TestOutput, {
665
+ get children() {
666
+ return _$createComponent(py.MethodDoc, {
667
+ get description() {
668
+ return [_$createComponent(Prose, {
669
+ children: "A method that performs an action but doesn't return a value."
670
+ })];
671
+ },
672
+ parameters: [{
673
+ name: "data",
674
+ type: "bytes",
675
+ doc: "Raw data to process."
676
+ }],
677
+ raises: ["ValueError: If data is empty or invalid.", "IOError: If processing fails due to I/O issues."]
678
+ });
679
+ }
680
+ })).toRenderTo(`
645
681
  """
646
682
  A method that performs an action but doesn't return a value.
647
683
 
@@ -655,20 +691,22 @@ describe("New Documentation Components", () => {
655
691
  IOError: If processing fails due to I/O issues.
656
692
  """
657
693
 
658
-
659
694
  `);
660
695
  });
661
696
  it("MethodDoc with no parameters", () => {
662
- const res = toSourceText([_$createComponent(py.MethodDoc, {
663
- get description() {
664
- return [_$createComponent(Prose, {
665
- children: "A simple method with no parameters (except self)."
666
- })];
667
- },
668
- returns: "bool: True if the operation was successful.",
669
- note: "This is a parameterless method that only operates on instance state."
670
- })]);
671
- expect(res).toRenderTo(d`
697
+ expect(_$createComponent(TestOutput, {
698
+ get children() {
699
+ return _$createComponent(py.MethodDoc, {
700
+ get description() {
701
+ return [_$createComponent(Prose, {
702
+ children: "A simple method with no parameters (except self)."
703
+ })];
704
+ },
705
+ returns: "bool: True if the operation was successful.",
706
+ note: "This is a parameterless method that only operates on instance state."
707
+ });
708
+ }
709
+ })).toRenderTo(`
672
710
  """
673
711
  A simple method with no parameters (except self).
674
712
 
@@ -679,46 +717,50 @@ describe("New Documentation Components", () => {
679
717
  This is a parameterless method that only operates on instance state.
680
718
  """
681
719
 
682
-
683
720
  `);
684
721
  });
685
722
  it("AttributeDoc standalone usage", () => {
686
- const res = toSourceText([_$createComponent(py.PyDoc, {
723
+ expect(_$createComponent(TestOutput, {
687
724
  get children() {
688
- return _$createComponent(py.AttributeDoc, {
689
- name: "connection_timeout",
690
- type: "float",
691
- children: "Maximum time in seconds to wait for a connection to be established."
725
+ return _$createComponent(py.PyDoc, {
726
+ get children() {
727
+ return _$createComponent(py.AttributeDoc, {
728
+ name: "connection_timeout",
729
+ type: "float",
730
+ children: "Maximum time in seconds to wait for a connection to be established."
731
+ });
732
+ }
692
733
  });
693
734
  }
694
- })]);
695
- expect(res).toRenderTo(d`
735
+ })).toRenderTo(`
696
736
  """
697
737
  connection_timeout (float): Maximum time in seconds to wait for a connection to
698
738
  be established.
699
739
  """
700
740
 
701
-
702
741
  `);
703
742
  });
704
743
  it("GeneratorDoc with examples in description", () => {
705
- const res = toSourceText([_$createComponent(py.GeneratorDoc, {
706
- get description() {
707
- return [_$createComponent(Prose, {
708
- children: "Generators have a Yields section instead of a Returns section."
709
- }), _$createComponent(py.PyDocExample, {
710
- children: `print([i for i in example_generator(4)])\n[0, 1, 2, 3]`
711
- })];
712
- },
713
- parameters: [{
714
- name: "n",
715
- type: "int",
716
- doc: "The upper limit of the range to generate, from 0 to n - 1."
717
- }],
718
- yields: "int: The next number in the range of 0 to n - 1.",
719
- note: "Examples should be written in doctest format, and should illustrate how to use the function."
720
- })]);
721
- expect(res).toRenderTo(d`
744
+ expect(_$createComponent(TestOutput, {
745
+ get children() {
746
+ return _$createComponent(py.GeneratorDoc, {
747
+ get description() {
748
+ return [_$createComponent(Prose, {
749
+ children: "Generators have a Yields section instead of a Returns section."
750
+ }), _$createComponent(py.PyDocExample, {
751
+ children: `print([i for i in example_generator(4)])\n[0, 1, 2, 3]`
752
+ })];
753
+ },
754
+ parameters: [{
755
+ name: "n",
756
+ type: "int",
757
+ doc: "The upper limit of the range to generate, from 0 to n - 1."
758
+ }],
759
+ yields: "int: The next number in the range of 0 to n - 1.",
760
+ note: "Examples should be written in doctest format, and should illustrate how to use the function."
761
+ });
762
+ }
763
+ })).toRenderTo(`
722
764
  """
723
765
  Generators have a Yields section instead of a Returns section.
724
766
 
@@ -735,7 +777,6 @@ describe("New Documentation Components", () => {
735
777
  Examples should be written in doctest format, and should illustrate how to use the function.
736
778
  """
737
779
 
738
-
739
780
  `);
740
781
  });
741
782
  });
@@ -779,32 +820,30 @@ describe("Full example", () => {
779
820
  note: "Do not include the 'self' parameter in the Args section.",
780
821
  style: "google"
781
822
  });
782
- const res = toSourceText([_$createComponent(py.ClassDeclaration, {
783
- name: "A",
784
- doc: doc,
823
+ expect(_$createComponent(TestOutput, {
785
824
  get children() {
786
- return _$createComponent(py.StatementList, {
825
+ return _$createComponent(py.ClassDeclaration, {
826
+ name: "A",
827
+ doc: doc,
787
828
  get children() {
788
- return [_$createComponent(py.VariableDeclaration, {
789
- name: "just_name"
790
- }), _$createComponent(py.VariableDeclaration, {
791
- name: "name_and_type",
792
- type: "int"
793
- }), _$createComponent(py.VariableDeclaration, {
794
- name: "name_type_and_value",
795
- type: "int",
796
- initializer: 12
797
- })];
829
+ return _$createComponent(py.StatementList, {
830
+ get children() {
831
+ return [_$createComponent(py.VariableDeclaration, {
832
+ name: "just_name"
833
+ }), _$createComponent(py.VariableDeclaration, {
834
+ name: "name_and_type",
835
+ type: "int"
836
+ }), _$createComponent(py.VariableDeclaration, {
837
+ name: "name_type_and_value",
838
+ type: "int",
839
+ initializer: 12
840
+ })];
841
+ }
842
+ });
798
843
  }
799
844
  });
800
845
  }
801
- })], {
802
- printOptions: {
803
- printWidth: 80,
804
- tabWidth: 4
805
- }
806
- });
807
- expect(res).toRenderTo(d`
846
+ })).toRenderTo(`
808
847
  class A:
809
848
  """
810
849
  This is an example of a long docstring that will be broken in lines. We will
@@ -825,7 +864,7 @@ describe("Full example", () => {
825
864
  nickname, or even a codename (e.g., 'Agent X'). It's used primarily
826
865
  for display purposes, logging, or greeting messages and is not
827
866
  required to be unique or validated unless specified by the caller.
828
- Defaults to \"John Doe\".
867
+ Defaults to "John Doe".
829
868
 
830
869
  somebody2 (str): Somebody's name. This can be any string representing a
831
870
  person, whether it's a first name, full name, nickname, or even a
@@ -854,7 +893,6 @@ describe("Full example", () => {
854
893
  name_and_type: int = None
855
894
  name_type_and_value: int = 12
856
895
 
857
-
858
896
  `);
859
897
  });
860
898
  it("renders correctly in a Function", () => {
@@ -882,32 +920,30 @@ describe("Full example", () => {
882
920
  note: "This function can be used as both a regular function and a generator.",
883
921
  style: "google"
884
922
  });
885
- const res = toSourceText([_$createComponent(py.FunctionDeclaration, {
886
- name: "some_function",
887
- doc: doc,
923
+ expect(_$createComponent(TestOutput, {
888
924
  get children() {
889
- return _$createComponent(py.StatementList, {
925
+ return _$createComponent(py.FunctionDeclaration, {
926
+ name: "some_function",
927
+ doc: doc,
890
928
  get children() {
891
- return [_$createComponent(py.VariableDeclaration, {
892
- name: "just_name"
893
- }), _$createComponent(py.VariableDeclaration, {
894
- name: "name_and_type",
895
- type: "number"
896
- }), _$createComponent(py.VariableDeclaration, {
897
- name: "name_type_and_value",
898
- type: "number",
899
- initializer: 12
900
- })];
929
+ return _$createComponent(py.StatementList, {
930
+ get children() {
931
+ return [_$createComponent(py.VariableDeclaration, {
932
+ name: "just_name"
933
+ }), _$createComponent(py.VariableDeclaration, {
934
+ name: "name_and_type",
935
+ type: "number"
936
+ }), _$createComponent(py.VariableDeclaration, {
937
+ name: "name_type_and_value",
938
+ type: "number",
939
+ initializer: 12
940
+ })];
941
+ }
942
+ });
901
943
  }
902
944
  });
903
945
  }
904
- })], {
905
- printOptions: {
906
- printWidth: 80,
907
- tabWidth: 4
908
- }
909
- });
910
- expect(res).toRenderTo(d`
946
+ })).toRenderTo(`
911
947
  def some_function():
912
948
  """
913
949
  This is an example of a long docstring that will be broken in lines. We will
@@ -923,7 +959,7 @@ describe("Full example", () => {
923
959
  nickname, or even a codename (e.g., 'Agent X'). It's used primarily
924
960
  for display purposes, logging, or greeting messages and is not
925
961
  required to be unique or validated unless specified by the caller.
926
- Defaults to \"John Doe\".
962
+ Defaults to "John Doe".
927
963
 
928
964
  somebody2 (str): Somebody's name. This can be any string representing a
929
965
  person, whether it's a first name, full name, nickname, or even a
@@ -947,21 +983,18 @@ describe("Full example", () => {
947
983
  name_and_type: number = None
948
984
  name_type_and_value: number = 12
949
985
 
950
-
951
986
  `);
952
987
  });
953
988
  it("renders correctly in a Variable", () => {
954
- const res = toSourceText([_$createComponent(py.VariableDeclaration, {
955
- name: "myVar",
956
- initializer: 42,
957
- doc: "This is a very long docstring that will be broken in two lines when rendered. This part of the docstring will be in the second line."
958
- })], {
959
- printOptions: {
960
- printWidth: 80,
961
- tabWidth: 4
989
+ expect(_$createComponent(TestOutput, {
990
+ get children() {
991
+ return _$createComponent(py.VariableDeclaration, {
992
+ name: "myVar",
993
+ initializer: 42,
994
+ doc: "This is a very long docstring that will be broken in two lines when rendered. This part of the docstring will be in the second line."
995
+ });
962
996
  }
963
- });
964
- expect(res).toRenderTo(d`
997
+ })).toRenderTo(`
965
998
  # This is a very long docstring that will be broken in two lines when rendered.
966
999
  # This part of the docstring will be in the second line.
967
1000
  my_var = 42
@@ -975,27 +1008,29 @@ describe("Full example", () => {
975
1008
  })];
976
1009
  }
977
1010
  });
978
- const result = toSourceText([_$createComponent(py.ClassEnumDeclaration, {
979
- name: "Color",
980
- baseType: "IntEnum",
981
- members: [{
982
- name: "RED",
983
- value: "1",
984
- doc: "The color red."
985
- }, {
986
- name: "GREEN",
987
- value: "2",
988
- doc: "The color green."
989
- }, {
990
- name: "BLUE",
991
- value: "3",
992
- doc: "The color blue."
993
- }],
994
- doc: doc
995
- })], {
996
- externals: [enumModule]
997
- });
998
- const expected = d`
1011
+ expect(_$createComponent(TestOutput, {
1012
+ externals: [enumModule],
1013
+ get children() {
1014
+ return _$createComponent(py.ClassEnumDeclaration, {
1015
+ name: "Color",
1016
+ baseType: "IntEnum",
1017
+ members: [{
1018
+ name: "RED",
1019
+ value: "1",
1020
+ doc: "The color red."
1021
+ }, {
1022
+ name: "GREEN",
1023
+ value: "2",
1024
+ doc: "The color green."
1025
+ }, {
1026
+ name: "BLUE",
1027
+ value: "3",
1028
+ doc: "The color blue."
1029
+ }],
1030
+ doc: doc
1031
+ });
1032
+ }
1033
+ })).toRenderTo(`
999
1034
  from enum import IntEnum
1000
1035
 
1001
1036
 
@@ -1017,9 +1052,7 @@ describe("Full example", () => {
1017
1052
  The color blue.
1018
1053
  """
1019
1054
 
1020
-
1021
- `;
1022
- expect(result).toRenderTo(expected);
1055
+ `);
1023
1056
  });
1024
1057
  it("ModuleDoc with SourceFile integration", () => {
1025
1058
  const moduleDoc = _$createComponent(py.ModuleDoc, {
@@ -1040,50 +1073,49 @@ describe("Full example", () => {
1040
1073
  todo: ["Add caching functionality", "Improve error messages"],
1041
1074
  style: "google"
1042
1075
  });
1043
- const content = _$createComponent(py.SourceFile, {
1044
- path: "utils.py",
1045
- doc: moduleDoc,
1076
+ expect(_$createComponent(TestOutputDirectory, {
1046
1077
  get children() {
1047
- return [_$createComponent(py.VariableDeclaration, {
1048
- name: "DEFAULT_TIMEOUT",
1049
- initializer: 30
1050
- }), _$createComponent(py.VariableDeclaration, {
1051
- name: "MAX_RETRIES",
1052
- initializer: 3
1053
- }), _$createComponent(py.FunctionDeclaration, {
1054
- name: "process_data",
1055
- children: "pass"
1056
- })];
1078
+ return _$createComponent(py.SourceFile, {
1079
+ path: "utils.py",
1080
+ doc: moduleDoc,
1081
+ get children() {
1082
+ return [_$createComponent(py.VariableDeclaration, {
1083
+ name: "DEFAULT_TIMEOUT",
1084
+ initializer: 30
1085
+ }), _$createComponent(py.VariableDeclaration, {
1086
+ name: "MAX_RETRIES",
1087
+ initializer: 3
1088
+ }), _$createComponent(py.FunctionDeclaration, {
1089
+ name: "process_data",
1090
+ children: "pass"
1091
+ })];
1092
+ }
1093
+ });
1057
1094
  }
1058
- });
1059
- const res = toSourceTextMultiple([content]);
1060
- const file = res.contents.find(f => f.kind === "file" && f.path === "utils.py");
1061
- expect(file).toBeDefined();
1062
- assertFileContents(res, {
1063
- "utils.py": d`
1064
- """
1065
- This module provides utility functions for data processing. It includes
1066
- functions for validation, transformation, and analysis.
1067
-
1068
- Attributes:
1069
- DEFAULT_TIMEOUT (int): Default timeout value in seconds.
1095
+ })).toRenderTo({
1096
+ "utils.py": `
1097
+ """
1098
+ This module provides utility functions for data processing. It includes
1099
+ functions for validation, transformation, and analysis.
1070
1100
 
1071
- MAX_RETRIES (int): Maximum number of retry attempts.
1101
+ Attributes:
1102
+ DEFAULT_TIMEOUT (int): Default timeout value in seconds.
1072
1103
 
1073
- Todo:
1074
- * Add caching functionality
1075
- * Improve error messages
1076
- """
1104
+ MAX_RETRIES (int): Maximum number of retry attempts.
1077
1105
 
1078
- default_timeout = 30
1106
+ Todo:
1107
+ * Add caching functionality
1108
+ * Improve error messages
1109
+ """
1079
1110
 
1080
- max_retries = 3
1111
+ default_timeout = 30
1081
1112
 
1082
- def process_data():
1083
- pass
1113
+ max_retries = 3
1084
1114
 
1115
+ def process_data():
1116
+ pass
1085
1117
 
1086
- `
1118
+ `
1087
1119
  });
1088
1120
  });
1089
1121
  it("GeneratorDoc with FunctionDeclaration integration", () => {
@@ -1101,12 +1133,15 @@ describe("Full example", () => {
1101
1133
  yields: "int: The next fibonacci number in the sequence.",
1102
1134
  style: "google"
1103
1135
  });
1104
- const result = toSourceText([_$createComponent(py.FunctionDeclaration, {
1105
- name: "fibonacci_generator",
1106
- doc: generatorDoc,
1107
- children: "yield 0"
1108
- })]);
1109
- expect(result).toRenderTo(d`
1136
+ expect(_$createComponent(TestOutput, {
1137
+ get children() {
1138
+ return _$createComponent(py.FunctionDeclaration, {
1139
+ name: "fibonacci_generator",
1140
+ doc: generatorDoc,
1141
+ children: "yield 0"
1142
+ });
1143
+ }
1144
+ })).toRenderTo(`
1110
1145
  def fibonacci_generator():
1111
1146
  """
1112
1147
  A generator function that yields fibonacci numbers. This is an efficient way
@@ -1120,7 +1155,6 @@ describe("Full example", () => {
1120
1155
  """
1121
1156
  yield 0
1122
1157
 
1123
-
1124
1158
  `);
1125
1159
  });
1126
1160
  it("ExceptionDoc with ClassDeclaration integration", () => {
@@ -1141,25 +1175,28 @@ describe("Full example", () => {
1141
1175
  }],
1142
1176
  style: "google"
1143
1177
  });
1144
- const result = toSourceText([_$createComponent(py.ClassDeclaration, {
1145
- name: "ValidationError",
1146
- bases: ["Exception"],
1147
- doc: exceptionDoc,
1178
+ expect(_$createComponent(TestOutput, {
1148
1179
  get children() {
1149
- return _$createComponent(py.StatementList, {
1180
+ return _$createComponent(py.ClassDeclaration, {
1181
+ name: "ValidationError",
1182
+ bases: ["Exception"],
1183
+ doc: exceptionDoc,
1150
1184
  get children() {
1151
- return [_$createComponent(py.VariableDeclaration, {
1152
- name: "field_name",
1153
- type: "str"
1154
- }), _$createComponent(py.VariableDeclaration, {
1155
- name: "error_code",
1156
- type: "int"
1157
- })];
1185
+ return _$createComponent(py.StatementList, {
1186
+ get children() {
1187
+ return [_$createComponent(py.VariableDeclaration, {
1188
+ name: "field_name",
1189
+ type: "str"
1190
+ }), _$createComponent(py.VariableDeclaration, {
1191
+ name: "error_code",
1192
+ type: "int"
1193
+ })];
1194
+ }
1195
+ });
1158
1196
  }
1159
1197
  });
1160
1198
  }
1161
- })]);
1162
- expect(result).toRenderTo(d`
1199
+ })).toRenderTo(`
1163
1200
  class ValidationError(Exception):
1164
1201
  """
1165
1202
  Custom exception raised when data validation fails. This exception includes
@@ -1174,7 +1211,6 @@ describe("Full example", () => {
1174
1211
  field_name: str = None
1175
1212
  error_code: int = None
1176
1213
 
1177
-
1178
1214
  `);
1179
1215
  });
1180
1216
  it("PropertyDoc with FunctionDeclaration (as property method) integration", () => {
@@ -1186,18 +1222,21 @@ describe("Full example", () => {
1186
1222
  },
1187
1223
  style: "google"
1188
1224
  });
1189
- const result = toSourceText([_$createComponent(py.ClassDeclaration, {
1190
- name: "Person",
1225
+ expect(_$createComponent(TestOutput, {
1191
1226
  get children() {
1192
- return _$createComponent(py.PropertyDeclaration, {
1193
- name: "full_name",
1194
- doc: propertyDoc,
1195
- type: "str",
1196
- children: "return \"John Doe\""
1227
+ return _$createComponent(py.ClassDeclaration, {
1228
+ name: "Person",
1229
+ get children() {
1230
+ return _$createComponent(py.PropertyDeclaration, {
1231
+ name: "full_name",
1232
+ doc: propertyDoc,
1233
+ type: "str",
1234
+ children: "return \"John Doe\""
1235
+ });
1236
+ }
1197
1237
  });
1198
1238
  }
1199
- })]);
1200
- expect(result).toRenderTo(`
1239
+ })).toRenderTo(`
1201
1240
  class Person:
1202
1241
  @property
1203
1242
  def full_name(self) -> str:
@@ -1232,26 +1271,29 @@ describe("Full example", () => {
1232
1271
  note: "This method modifies the internal validation state.",
1233
1272
  style: "google"
1234
1273
  });
1235
- const result = toSourceText([_$createComponent(py.ClassDeclaration, {
1236
- name: "DataValidator",
1274
+ expect(_$createComponent(TestOutput, {
1237
1275
  get children() {
1238
- return _$createComponent(py.MethodDeclaration, {
1239
- name: "validate",
1240
- doc: methodDoc,
1241
- parameters: [{
1242
- name: "data",
1243
- type: "dict"
1244
- }, {
1245
- name: "strict",
1246
- type: "bool",
1247
- default: true
1248
- }],
1249
- returnType: "bool",
1250
- children: "return self.validate(data, strict)"
1276
+ return _$createComponent(py.ClassDeclaration, {
1277
+ name: "DataValidator",
1278
+ get children() {
1279
+ return _$createComponent(py.MethodDeclaration, {
1280
+ name: "validate",
1281
+ doc: methodDoc,
1282
+ parameters: [{
1283
+ name: "data",
1284
+ type: "dict"
1285
+ }, {
1286
+ name: "strict",
1287
+ type: "bool",
1288
+ default: true
1289
+ }],
1290
+ returnType: "bool",
1291
+ children: "return self.validate(data, strict)"
1292
+ });
1293
+ }
1251
1294
  });
1252
1295
  }
1253
- })]);
1254
- expect(result).toRenderTo(d`
1296
+ })).toRenderTo(`
1255
1297
  class DataValidator:
1256
1298
  def validate(self, data: dict, strict: bool = True) -> bool:
1257
1299
  """
@@ -1276,7 +1318,6 @@ describe("Full example", () => {
1276
1318
  return self.validate(data, strict)
1277
1319
 
1278
1320
 
1279
-
1280
1321
  `);
1281
1322
  });
1282
1323
  });