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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/dist/dev/src/components/SourceFile.js +44 -32
  2. package/dist/dev/src/components/SourceFile.js.map +1 -1
  3. package/dist/dev/test/callsignatures.test.js +471 -297
  4. package/dist/dev/test/callsignatures.test.js.map +1 -1
  5. package/dist/dev/test/class-method-declaration.test.js +21 -10
  6. package/dist/dev/test/class-method-declaration.test.js.map +1 -1
  7. package/dist/dev/test/classdeclarations.test.js +459 -393
  8. package/dist/dev/test/classdeclarations.test.js.map +1 -1
  9. package/dist/dev/test/classinstantiations.test.js +201 -168
  10. package/dist/dev/test/classinstantiations.test.js.map +1 -1
  11. package/dist/dev/test/constructordeclaration.test.js +22 -11
  12. package/dist/dev/test/constructordeclaration.test.js.map +1 -1
  13. package/dist/dev/test/dataclassdeclarations.test.js +322 -368
  14. package/dist/dev/test/dataclassdeclarations.test.js.map +1 -1
  15. package/dist/dev/test/decoratorlist.test.js +96 -49
  16. package/dist/dev/test/decoratorlist.test.js.map +1 -1
  17. package/dist/dev/test/dundermethoddeclaration.test.js +22 -11
  18. package/dist/dev/test/dundermethoddeclaration.test.js.map +1 -1
  19. package/dist/dev/test/enums.test.js +218 -184
  20. package/dist/dev/test/enums.test.js.map +1 -1
  21. package/dist/dev/test/externals.test.js +57 -45
  22. package/dist/dev/test/externals.test.js.map +1 -1
  23. package/dist/dev/test/factories.test.js +124 -50
  24. package/dist/dev/test/factories.test.js.map +1 -1
  25. package/dist/dev/test/functioncallexpressions.test.js +199 -164
  26. package/dist/dev/test/functioncallexpressions.test.js.map +1 -1
  27. package/dist/dev/test/functiondeclaration.test.js +439 -272
  28. package/dist/dev/test/functiondeclaration.test.js.map +1 -1
  29. package/dist/dev/test/imports.test.js +273 -221
  30. package/dist/dev/test/imports.test.js.map +1 -1
  31. package/dist/dev/test/memberexpressions.test.js +1237 -972
  32. package/dist/dev/test/memberexpressions.test.js.map +1 -1
  33. package/dist/dev/test/methoddeclaration.test.js +142 -78
  34. package/dist/dev/test/methoddeclaration.test.js.map +1 -1
  35. package/dist/dev/test/namepolicies.test.js +130 -94
  36. package/dist/dev/test/namepolicies.test.js.map +1 -1
  37. package/dist/dev/test/propertydeclaration.test.js +88 -59
  38. package/dist/dev/test/propertydeclaration.test.js.map +1 -1
  39. package/dist/dev/test/pydanticclassdeclarations.test.js +299 -347
  40. package/dist/dev/test/pydanticclassdeclarations.test.js.map +1 -1
  41. package/dist/dev/test/pydocs.test.js +888 -715
  42. package/dist/dev/test/pydocs.test.js.map +1 -1
  43. package/dist/dev/test/references.test.js +42 -35
  44. package/dist/dev/test/references.test.js.map +1 -1
  45. package/dist/dev/test/sourcefiles.test.js +1109 -841
  46. package/dist/dev/test/sourcefiles.test.js.map +1 -1
  47. package/dist/dev/test/staticmethoddeclaration.test.js +21 -10
  48. package/dist/dev/test/staticmethoddeclaration.test.js.map +1 -1
  49. package/dist/dev/test/type-checking-imports.test.js +408 -359
  50. package/dist/dev/test/type-checking-imports.test.js.map +1 -1
  51. package/dist/dev/test/typereference.test.js +55 -40
  52. package/dist/dev/test/typereference.test.js.map +1 -1
  53. package/dist/dev/test/uniontypeexpression.test.js +222 -146
  54. package/dist/dev/test/uniontypeexpression.test.js.map +1 -1
  55. package/dist/dev/test/utils.js +39 -77
  56. package/dist/dev/test/utils.js.map +1 -1
  57. package/dist/dev/test/values.test.js +237 -101
  58. package/dist/dev/test/values.test.js.map +1 -1
  59. package/dist/dev/test/variables.test.js +321 -203
  60. package/dist/dev/test/variables.test.js.map +1 -1
  61. package/dist/dev/test/vitest.setup.js +2 -0
  62. package/dist/dev/test/vitest.setup.js.map +1 -0
  63. package/dist/src/components/SourceFile.d.ts +2 -2
  64. package/dist/src/components/SourceFile.d.ts.map +1 -1
  65. package/dist/src/components/SourceFile.js +12 -0
  66. package/dist/src/components/SourceFile.js.map +1 -1
  67. package/dist/test/callsignatures.test.js +346 -272
  68. package/dist/test/callsignatures.test.js.map +1 -1
  69. package/dist/test/class-method-declaration.test.js +7 -4
  70. package/dist/test/class-method-declaration.test.js.map +1 -1
  71. package/dist/test/classdeclarations.test.js +302 -288
  72. package/dist/test/classdeclarations.test.js.map +1 -1
  73. package/dist/test/classinstantiations.test.js +112 -103
  74. package/dist/test/classinstantiations.test.js.map +1 -1
  75. package/dist/test/constructordeclaration.test.js +7 -4
  76. package/dist/test/constructordeclaration.test.js.map +1 -1
  77. package/dist/test/dataclassdeclarations.test.js +134 -184
  78. package/dist/test/dataclassdeclarations.test.js.map +1 -1
  79. package/dist/test/decoratorlist.test.js +59 -36
  80. package/dist/test/decoratorlist.test.js.map +1 -1
  81. package/dist/test/dundermethoddeclaration.test.js +7 -4
  82. package/dist/test/dundermethoddeclaration.test.js.map +1 -1
  83. package/dist/test/enums.test.js +161 -159
  84. package/dist/test/enums.test.js.map +1 -1
  85. package/dist/test/externals.test.js +24 -24
  86. package/dist/test/externals.test.js.map +1 -1
  87. package/dist/test/factories.test.js +75 -33
  88. package/dist/test/factories.test.js.map +1 -1
  89. package/dist/test/functioncallexpressions.test.js +117 -106
  90. package/dist/test/functioncallexpressions.test.js.map +1 -1
  91. package/dist/test/functiondeclaration.test.js +247 -180
  92. package/dist/test/functiondeclaration.test.js.map +1 -1
  93. package/dist/test/imports.test.js +171 -143
  94. package/dist/test/imports.test.js.map +1 -1
  95. package/dist/test/memberexpressions.test.js +582 -453
  96. package/dist/test/memberexpressions.test.js.map +1 -1
  97. package/dist/test/methoddeclaration.test.js +66 -46
  98. package/dist/test/methoddeclaration.test.js.map +1 -1
  99. package/dist/test/namepolicies.test.js +90 -78
  100. package/dist/test/namepolicies.test.js.map +1 -1
  101. package/dist/test/propertydeclaration.test.js +25 -20
  102. package/dist/test/propertydeclaration.test.js.map +1 -1
  103. package/dist/test/pydanticclassdeclarations.test.js +134 -190
  104. package/dist/test/pydanticclassdeclarations.test.js.map +1 -1
  105. package/dist/test/pydocs.test.js +573 -532
  106. package/dist/test/pydocs.test.js.map +1 -1
  107. package/dist/test/references.test.js +31 -28
  108. package/dist/test/references.test.js.map +1 -1
  109. package/dist/test/sourcefiles.test.js +700 -580
  110. package/dist/test/sourcefiles.test.js.map +1 -1
  111. package/dist/test/staticmethoddeclaration.test.js +7 -4
  112. package/dist/test/staticmethoddeclaration.test.js.map +1 -1
  113. package/dist/test/type-checking-imports.test.js +297 -284
  114. package/dist/test/type-checking-imports.test.js.map +1 -1
  115. package/dist/test/typereference.test.js +29 -22
  116. package/dist/test/typereference.test.js.map +1 -1
  117. package/dist/test/uniontypeexpression.test.js +124 -88
  118. package/dist/test/uniontypeexpression.test.js.map +1 -1
  119. package/dist/test/utils.d.ts +10 -17
  120. package/dist/test/utils.d.ts.map +1 -1
  121. package/dist/test/utils.js +32 -74
  122. package/dist/test/utils.js.map +1 -1
  123. package/dist/test/values.test.js +135 -67
  124. package/dist/test/values.test.js.map +1 -1
  125. package/dist/test/variables.test.js +201 -151
  126. package/dist/test/variables.test.js.map +1 -1
  127. package/dist/test/vitest.setup.d.ts +2 -0
  128. package/dist/test/vitest.setup.d.ts.map +1 -0
  129. package/dist/test/vitest.setup.js +2 -0
  130. package/dist/test/vitest.setup.js.map +1 -0
  131. package/dist/tsconfig.tsbuildinfo +1 -1
  132. package/docs/api/components/SourceFile.md +20 -8
  133. package/package.json +2 -2
  134. package/src/components/SourceFile.tsx +6 -1
  135. package/temp/api.json +16 -2
  136. package/test/callsignatures.test.tsx +309 -283
  137. package/test/class-method-declaration.test.tsx +3 -4
  138. package/test/classdeclarations.test.tsx +263 -248
  139. package/test/classinstantiations.test.tsx +115 -109
  140. package/test/constructordeclaration.test.tsx +9 -6
  141. package/test/dataclassdeclarations.test.tsx +243 -361
  142. package/test/decoratorlist.test.tsx +78 -59
  143. package/test/dundermethoddeclaration.test.tsx +3 -4
  144. package/test/enums.test.tsx +65 -81
  145. package/test/externals.test.tsx +25 -25
  146. package/test/factories.test.tsx +64 -22
  147. package/test/functioncallexpressions.test.tsx +123 -109
  148. package/test/functiondeclaration.test.tsx +209 -148
  149. package/test/imports.test.tsx +119 -91
  150. package/test/memberexpressions.test.tsx +265 -207
  151. package/test/methoddeclaration.test.tsx +84 -63
  152. package/test/namepolicies.test.tsx +69 -69
  153. package/test/propertydeclaration.test.tsx +7 -8
  154. package/test/pydanticclassdeclarations.test.tsx +355 -487
  155. package/test/pydocs.test.tsx +531 -579
  156. package/test/references.test.tsx +24 -23
  157. package/test/sourcefiles.test.tsx +527 -492
  158. package/test/staticmethoddeclaration.test.tsx +3 -4
  159. package/test/type-checking-imports.test.tsx +206 -218
  160. package/test/typereference.test.tsx +15 -12
  161. package/test/uniontypeexpression.test.tsx +74 -61
  162. package/test/utils.tsx +26 -110
  163. package/test/values.test.tsx +82 -32
  164. package/test/variables.test.tsx +162 -142
  165. package/test/vitest.setup.ts +1 -0
  166. package/vitest.config.ts +3 -0
@@ -1,93 +1,105 @@
1
1
  import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
2
  import { memberRefkey, namekey, refkey } from "@alloy-js/core";
3
- import { d } from "@alloy-js/core/testing";
4
3
  import { describe, expect, it } from "vitest";
5
4
  import * as py from "../src/index.js";
6
- import { assertFileContents, toSourceText, toSourceTextMultiple } from "./utils.js";
5
+ import { TestOutput, TestOutputDirectory } from "./utils.js";
7
6
  describe("Python Class", () => {
8
7
  it("renders class-level decorators above `class`", () => {
9
- const result = toSourceText([_$createComponent(py.ClassDeclaration, {
10
- name: "Foo",
11
- decorators: ["@final", "@deprecated('use Bar')"]
12
- })]);
13
- expect(result).toRenderTo(d`
8
+ expect(_$createComponent(TestOutput, {
9
+ get children() {
10
+ return _$createComponent(py.ClassDeclaration, {
11
+ name: "Foo",
12
+ decorators: ["@final", "@deprecated('use Bar')"]
13
+ });
14
+ }
15
+ })).toRenderTo(`
14
16
  @final
15
17
  @deprecated('use Bar')
16
18
  class Foo:
17
19
  pass
18
20
 
19
-
20
21
  `);
21
22
  });
22
23
  it("renders nothing extra when decorators is undefined", () => {
23
- const result = toSourceText([_$createComponent(py.ClassDeclaration, {
24
- name: "Foo"
25
- })]);
26
- expect(result).toRenderTo(d`
24
+ expect(_$createComponent(TestOutput, {
25
+ get children() {
26
+ return _$createComponent(py.ClassDeclaration, {
27
+ name: "Foo"
28
+ });
29
+ }
30
+ })).toRenderTo(`
27
31
  class Foo:
28
32
  pass
29
33
 
30
-
31
34
  `);
32
35
  });
33
36
  it("renders a class with no body as 'pass'", () => {
34
- const result = toSourceText([_$createComponent(py.ClassDeclaration, {
35
- name: "Foo"
36
- })]);
37
- expect(result).toRenderTo(d`
37
+ expect(_$createComponent(TestOutput, {
38
+ get children() {
39
+ return _$createComponent(py.ClassDeclaration, {
40
+ name: "Foo"
41
+ });
42
+ }
43
+ })).toRenderTo(`
38
44
  class Foo:
39
45
  pass
40
46
 
41
-
42
47
  `);
43
48
  });
44
49
  it("takes a namekey", () => {
45
- const result = toSourceText([_$createComponent(py.ClassDeclaration, {
46
- get name() {
47
- return namekey("Foo");
50
+ expect(_$createComponent(TestOutput, {
51
+ get children() {
52
+ return _$createComponent(py.ClassDeclaration, {
53
+ get name() {
54
+ return namekey("Foo");
55
+ }
56
+ });
48
57
  }
49
- })]);
50
- expect(result).toRenderTo(d`
58
+ })).toRenderTo(`
51
59
  class Foo:
52
60
  pass
53
61
 
54
-
55
62
  `);
56
63
  });
57
64
  it("renders a class with a body", () => {
58
- const result = toSourceText([_$createComponent(py.ClassDeclaration, {
59
- name: "Bar",
60
- children: "print('hi')"
61
- })]);
62
- expect(result).toRenderTo(d`
65
+ expect(_$createComponent(TestOutput, {
66
+ get children() {
67
+ return _$createComponent(py.ClassDeclaration, {
68
+ name: "Bar",
69
+ children: "print('hi')"
70
+ });
71
+ }
72
+ })).toRenderTo(`
63
73
  class Bar:
64
74
  print('hi')
65
75
 
66
-
67
76
  `);
68
77
  });
69
78
  it("renders a class with base classes", () => {
70
- const result = toSourceText([_$createComponent(py.StatementList, {
79
+ expect(_$createComponent(TestOutput, {
71
80
  get children() {
72
- return [_$createComponent(py.ClassDeclaration, {
73
- name: "Base1",
74
- get refkey() {
75
- return refkey("Base1");
76
- }
77
- }), _$createComponent(py.ClassDeclaration, {
78
- name: "Base2",
79
- get refkey() {
80
- return refkey("Base2");
81
- }
82
- }), _$createComponent(py.ClassDeclaration, {
83
- name: "Baz",
84
- get bases() {
85
- return [refkey("Base1"), refkey("Base2")];
81
+ return _$createComponent(py.StatementList, {
82
+ get children() {
83
+ return [_$createComponent(py.ClassDeclaration, {
84
+ name: "Base1",
85
+ get refkey() {
86
+ return refkey("Base1");
87
+ }
88
+ }), _$createComponent(py.ClassDeclaration, {
89
+ name: "Base2",
90
+ get refkey() {
91
+ return refkey("Base2");
92
+ }
93
+ }), _$createComponent(py.ClassDeclaration, {
94
+ name: "Baz",
95
+ get bases() {
96
+ return [refkey("Base1"), refkey("Base2")];
97
+ }
98
+ })];
86
99
  }
87
- })];
100
+ });
88
101
  }
89
- })]);
90
- const expected = d`
102
+ })).toRenderTo(`
91
103
  class Base1:
92
104
  pass
93
105
 
@@ -97,123 +109,119 @@ describe("Python Class", () => {
97
109
  class Baz(Base1, Base2):
98
110
  pass
99
111
 
100
-
101
- `;
102
- expect(result).toRenderTo(expected);
112
+ `);
103
113
  });
104
114
  it("renders a class with base classes and body", () => {
105
- const result = toSourceText([_$createComponent(py.ClassDeclaration, {
106
- name: "Qux",
107
- bases: ["Base"],
108
- children: "print('hello')"
109
- })]);
110
- expect(result).toRenderTo(d`
115
+ expect(_$createComponent(TestOutput, {
116
+ get children() {
117
+ return _$createComponent(py.ClassDeclaration, {
118
+ name: "Qux",
119
+ bases: ["Base"],
120
+ children: "print('hello')"
121
+ });
122
+ }
123
+ })).toRenderTo(`
111
124
  class Qux(Base):
112
125
  print('hello')
113
126
 
114
-
115
127
  `);
116
128
  });
117
129
  it("renders classes across modules with inheritance", () => {
118
- const result = toSourceTextMultiple([_$createComponent(py.SourceFile, {
119
- path: "mod1.py",
130
+ expect(_$createComponent(TestOutputDirectory, {
120
131
  get children() {
121
- return _$createComponent(py.ClassDeclaration, {
122
- name: "A",
123
- get refkey() {
124
- return refkey("A");
132
+ return [_$createComponent(py.SourceFile, {
133
+ path: "mod1.py",
134
+ get children() {
135
+ return _$createComponent(py.ClassDeclaration, {
136
+ name: "A",
137
+ get refkey() {
138
+ return refkey("A");
139
+ }
140
+ });
125
141
  }
126
- });
127
- }
128
- }), _$createComponent(py.SourceFile, {
129
- path: "folder/mod2.py",
130
- get children() {
131
- return _$createComponent(py.ClassDeclaration, {
132
- name: "B",
133
- get refkey() {
134
- return refkey("B");
135
- },
136
- get bases() {
137
- return [refkey("A")];
142
+ }), _$createComponent(py.SourceFile, {
143
+ path: "folder/mod2.py",
144
+ get children() {
145
+ return _$createComponent(py.ClassDeclaration, {
146
+ name: "B",
147
+ get refkey() {
148
+ return refkey("B");
149
+ },
150
+ get bases() {
151
+ return [refkey("A")];
152
+ }
153
+ });
138
154
  }
139
- });
140
- }
141
- }), _$createComponent(py.SourceFile, {
142
- path: "mod3.py",
143
- get children() {
144
- return _$createComponent(py.ClassDeclaration, {
145
- name: "C",
146
- get bases() {
147
- return [refkey("B")];
155
+ }), _$createComponent(py.SourceFile, {
156
+ path: "mod3.py",
157
+ get children() {
158
+ return _$createComponent(py.ClassDeclaration, {
159
+ name: "C",
160
+ get bases() {
161
+ return [refkey("B")];
162
+ }
163
+ });
148
164
  }
149
- });
165
+ })];
150
166
  }
151
- })]);
152
- const mod1Expected = d`
153
- class A:
154
- pass
155
-
156
-
157
- `;
158
- const mod2Expected = d`
159
- from mod1 import A
160
-
167
+ })).toRenderTo({
168
+ "mod1.py": `
169
+ class A:
170
+ pass
161
171
 
162
- class B(A):
163
- pass
172
+ `,
173
+ "folder/mod2.py": `
174
+ from mod1 import A
164
175
 
165
176
 
166
- `;
167
- const mod3Expected = d`
168
- from folder.mod2 import B
177
+ class B(A):
178
+ pass
169
179
 
180
+ `,
181
+ "mod3.py": `
182
+ from folder.mod2 import B
170
183
 
171
- class C(B):
172
- pass
173
184
 
185
+ class C(B):
186
+ pass
174
187
 
175
- `;
176
- assertFileContents(result, {
177
- "mod1.py": mod1Expected
178
- });
179
- assertFileContents(result, {
180
- "folder/mod2.py": mod2Expected
181
- });
182
- assertFileContents(result, {
183
- "mod3.py": mod3Expected
188
+ `
184
189
  });
185
190
  });
186
191
  it("renders a class with class variables like foo: str, and also bar: A where A is another class", () => {
187
- const result = toSourceText([_$createComponent(py.StatementList, {
192
+ expect(_$createComponent(TestOutput, {
188
193
  get children() {
189
- return [_$createComponent(py.ClassDeclaration, {
190
- name: "A",
191
- get refkey() {
192
- return refkey("A");
193
- }
194
- }), _$createComponent(py.ClassDeclaration, {
195
- name: "B",
194
+ return _$createComponent(py.StatementList, {
196
195
  get children() {
197
- return _$createComponent(py.StatementList, {
196
+ return [_$createComponent(py.ClassDeclaration, {
197
+ name: "A",
198
+ get refkey() {
199
+ return refkey("A");
200
+ }
201
+ }), _$createComponent(py.ClassDeclaration, {
202
+ name: "B",
198
203
  get children() {
199
- return [_$createComponent(py.VariableDeclaration, {
200
- name: "bar",
201
- get type() {
202
- return refkey("A");
203
- },
204
- omitNone: true
205
- }), _$createComponent(py.VariableDeclaration, {
206
- name: "foo",
207
- type: "str",
208
- omitNone: true
209
- })];
204
+ return _$createComponent(py.StatementList, {
205
+ get children() {
206
+ return [_$createComponent(py.VariableDeclaration, {
207
+ name: "bar",
208
+ get type() {
209
+ return refkey("A");
210
+ },
211
+ omitNone: true
212
+ }), _$createComponent(py.VariableDeclaration, {
213
+ name: "foo",
214
+ type: "str",
215
+ omitNone: true
216
+ })];
217
+ }
218
+ });
210
219
  }
211
- });
220
+ })];
212
221
  }
213
- })];
222
+ });
214
223
  }
215
- })]);
216
- const expected = d`
224
+ })).toRenderTo(`
217
225
  class A:
218
226
  pass
219
227
 
@@ -221,47 +229,48 @@ describe("Python Class", () => {
221
229
  bar: A
222
230
  foo: str
223
231
 
224
-
225
- `;
226
- expect(result).toRenderTo(expected);
232
+ `);
227
233
  });
228
234
  it("renders a class with class variables like foo: str, and another identical class", () => {
229
235
  const fooKey = refkey();
230
236
  const barKey = refkey();
231
- const result = toSourceText([_$createComponent(py.StatementList, {
237
+ expect(_$createComponent(TestOutput, {
232
238
  get children() {
233
- return [_$createComponent(py.ClassDeclaration, {
234
- name: "A",
239
+ return _$createComponent(py.StatementList, {
235
240
  get children() {
236
- return _$createComponent(py.StatementList, {
241
+ return [_$createComponent(py.ClassDeclaration, {
242
+ name: "A",
237
243
  get children() {
238
- return _$createComponent(py.VariableDeclaration, {
239
- name: "foo",
240
- type: "str",
241
- refkey: fooKey,
242
- omitNone: true
244
+ return _$createComponent(py.StatementList, {
245
+ get children() {
246
+ return _$createComponent(py.VariableDeclaration, {
247
+ name: "foo",
248
+ type: "str",
249
+ refkey: fooKey,
250
+ omitNone: true
251
+ });
252
+ }
243
253
  });
244
254
  }
245
- });
246
- }
247
- }), _$createComponent(py.ClassDeclaration, {
248
- name: "B",
249
- get children() {
250
- return _$createComponent(py.StatementList, {
255
+ }), _$createComponent(py.ClassDeclaration, {
256
+ name: "B",
251
257
  get children() {
252
- return _$createComponent(py.VariableDeclaration, {
253
- name: "foo",
254
- type: "str",
255
- refkey: barKey,
256
- omitNone: true
258
+ return _$createComponent(py.StatementList, {
259
+ get children() {
260
+ return _$createComponent(py.VariableDeclaration, {
261
+ name: "foo",
262
+ type: "str",
263
+ refkey: barKey,
264
+ omitNone: true
265
+ });
266
+ }
257
267
  });
258
268
  }
259
- });
269
+ }), fooKey, barKey];
260
270
  }
261
- }), fooKey, barKey];
271
+ });
262
272
  }
263
- })]);
264
- const expected = d`
273
+ })).toRenderTo(`
265
274
  class A:
266
275
  foo: str
267
276
 
@@ -270,53 +279,55 @@ describe("Python Class", () => {
270
279
 
271
280
  A.foo
272
281
  B.foo
273
- `;
274
- expect(result).toRenderTo(expected);
282
+ `);
275
283
  });
276
284
  });
277
285
  describe("Python Class - VariableDeclaration", () => {
278
286
  it("renders a class with class fields", () => {
279
- const result = toSourceText([_$createComponent(py.StatementList, {
287
+ expect(_$createComponent(TestOutput, {
280
288
  get children() {
281
- return [_$createComponent(py.ClassDeclaration, {
282
- get refkey() {
283
- return refkey("Base");
284
- },
285
- name: "Base"
286
- }), _$createComponent(py.ClassDeclaration, {
287
- get refkey() {
288
- return refkey("A");
289
- },
290
- name: "A",
289
+ return _$createComponent(py.StatementList, {
291
290
  get children() {
292
- return _$createComponent(py.StatementList, {
291
+ return [_$createComponent(py.ClassDeclaration, {
292
+ get refkey() {
293
+ return refkey("Base");
294
+ },
295
+ name: "Base"
296
+ }), _$createComponent(py.ClassDeclaration, {
297
+ get refkey() {
298
+ return refkey("A");
299
+ },
300
+ name: "A",
293
301
  get children() {
294
- return [_$createComponent(py.VariableDeclaration, {
295
- instanceVariable: true,
296
- name: "just_name"
297
- }), _$createComponent(py.VariableDeclaration, {
298
- name: "name_and_type",
299
- type: "number",
300
- instanceVariable: true
301
- }), _$createComponent(py.VariableDeclaration, {
302
- instanceVariable: true,
303
- name: "name_type_and_value",
304
- type: "number",
305
- initializer: 12
306
- }), _$createComponent(py.VariableDeclaration, {
307
- instanceVariable: true,
308
- name: "class_based",
309
- get type() {
310
- return refkey("Base");
302
+ return _$createComponent(py.StatementList, {
303
+ get children() {
304
+ return [_$createComponent(py.VariableDeclaration, {
305
+ instanceVariable: true,
306
+ name: "just_name"
307
+ }), _$createComponent(py.VariableDeclaration, {
308
+ name: "name_and_type",
309
+ type: "number",
310
+ instanceVariable: true
311
+ }), _$createComponent(py.VariableDeclaration, {
312
+ instanceVariable: true,
313
+ name: "name_type_and_value",
314
+ type: "number",
315
+ initializer: 12
316
+ }), _$createComponent(py.VariableDeclaration, {
317
+ instanceVariable: true,
318
+ name: "class_based",
319
+ get type() {
320
+ return refkey("Base");
321
+ }
322
+ })];
311
323
  }
312
- })];
324
+ });
313
325
  }
314
- });
326
+ })];
315
327
  }
316
- })];
328
+ });
317
329
  }
318
- })]);
319
- const expected = d`
330
+ })).toRenderTo(`
320
331
  class Base:
321
332
  pass
322
333
 
@@ -326,74 +337,75 @@ describe("Python Class - VariableDeclaration", () => {
326
337
  name_type_and_value: number = 12
327
338
  class_based: Base = None
328
339
 
329
-
330
- `;
331
- expect(result).toRenderTo(expected);
340
+ `);
332
341
  });
333
342
  it("correctly access members of its type", () => {
334
343
  const classRk = refkey();
335
344
  const classMemberRk = refkey();
336
345
  const classMethodRk = refkey();
337
346
  const v1Rk = refkey();
338
- const res = toSourceTextMultiple([_$createComponent(py.SourceFile, {
339
- path: "inst.py",
347
+ expect(_$createComponent(TestOutputDirectory, {
340
348
  get children() {
341
- return _$createComponent(py.StatementList, {
349
+ return [_$createComponent(py.SourceFile, {
350
+ path: "inst.py",
342
351
  get children() {
343
- return [_$createComponent(py.VariableDeclaration, {
344
- name: "one",
345
- refkey: v1Rk,
346
- type: classRk,
347
- get initializer() {
348
- return _$createComponent(py.ClassInstantiation, {
349
- target: classRk
350
- });
352
+ return _$createComponent(py.StatementList, {
353
+ get children() {
354
+ return [_$createComponent(py.VariableDeclaration, {
355
+ name: "one",
356
+ refkey: v1Rk,
357
+ type: classRk,
358
+ get initializer() {
359
+ return _$createComponent(py.ClassInstantiation, {
360
+ target: classRk
361
+ });
362
+ }
363
+ }), [_$memo(() => memberRefkey(v1Rk, classMemberRk))], [_$memo(() => memberRefkey(v1Rk, classMethodRk)), "()"]];
351
364
  }
352
- }), [_$memo(() => memberRefkey(v1Rk, classMemberRk))], [_$memo(() => memberRefkey(v1Rk, classMethodRk)), "()"]];
365
+ });
353
366
  }
354
- });
355
- }
356
- }), _$createComponent(py.SourceFile, {
357
- path: "decl.py",
358
- get children() {
359
- return _$createComponent(py.ClassDeclaration, {
360
- name: "Bar",
361
- refkey: classRk,
367
+ }), _$createComponent(py.SourceFile, {
368
+ path: "decl.py",
362
369
  get children() {
363
- return _$createComponent(py.StatementList, {
370
+ return _$createComponent(py.ClassDeclaration, {
371
+ name: "Bar",
372
+ refkey: classRk,
364
373
  get children() {
365
- return [_$createComponent(py.VariableDeclaration, {
366
- name: "instanceProp",
367
- refkey: classMemberRk,
368
- initializer: 42,
369
- instanceVariable: true
370
- }), _$createComponent(py.MethodDeclaration, {
371
- name: "instanceMethod",
372
- refkey: classMethodRk,
373
- returnType: "int"
374
- })];
374
+ return _$createComponent(py.StatementList, {
375
+ get children() {
376
+ return [_$createComponent(py.VariableDeclaration, {
377
+ name: "instanceProp",
378
+ refkey: classMemberRk,
379
+ initializer: 42,
380
+ instanceVariable: true
381
+ }), _$createComponent(py.MethodDeclaration, {
382
+ name: "instanceMethod",
383
+ refkey: classMethodRk,
384
+ returnType: "int"
385
+ })];
386
+ }
387
+ });
375
388
  }
376
389
  });
377
390
  }
378
- });
391
+ })];
379
392
  }
380
- })]);
381
- assertFileContents(res, {
393
+ })).toRenderTo({
382
394
  "inst.py": `
383
- from decl import Bar
395
+ from decl import Bar
384
396
 
385
- one: Bar = Bar()
386
- one.instance_prop
387
- one.instance_method()
388
- `,
397
+ one: Bar = Bar()
398
+ one.instance_prop
399
+ one.instance_method()
400
+ `,
389
401
  "decl.py": `
390
- class Bar:
391
- instance_prop = 42
392
- def instance_method(self) -> int:
393
- pass
402
+ class Bar:
403
+ instance_prop = 42
404
+ def instance_method(self) -> int:
405
+ pass
394
406
 
395
407
 
396
- `
408
+ `
397
409
  });
398
410
  });
399
411
  });
@@ -402,52 +414,55 @@ describe("Python Class - FunctionDeclaration", () => {
402
414
  const methodRefkey = refkey();
403
415
  const classMethodRefkey = refkey();
404
416
  const staticMethodRefkey = refkey();
405
- const result = toSourceText([_$createComponent(py.StatementList, {
417
+ expect(_$createComponent(TestOutput, {
406
418
  get children() {
407
- return [_$createComponent(py.ClassDeclaration, {
408
- name: "MyClass",
409
- bases: ["BaseClass"],
419
+ return _$createComponent(py.StatementList, {
410
420
  get children() {
411
- return _$createComponent(py.StatementList, {
421
+ return [_$createComponent(py.ClassDeclaration, {
422
+ name: "MyClass",
423
+ bases: ["BaseClass"],
412
424
  get children() {
413
- return [_$createComponent(py.VariableDeclaration, {
414
- name: "a",
415
- type: "int",
416
- instanceVariable: true
417
- }), _$createComponent(py.VariableDeclaration, {
418
- name: "b",
419
- type: "int",
420
- instanceVariable: true
421
- }), _$createComponent(py.MethodDeclaration, {
422
- name: "my_method",
423
- parameters: [{
424
- name: "a",
425
- type: "int"
426
- }, {
427
- name: "b",
428
- type: "int"
429
- }],
430
- returnType: "int",
431
- refkey: methodRefkey,
432
- children: "return a + b"
433
- }), _$createComponent(py.ClassMethodDeclaration, {
434
- name: "my_class_method",
435
- returnType: "int",
436
- refkey: classMethodRefkey,
437
- children: "pass"
438
- }), _$createComponent(py.FunctionDeclaration, {
439
- name: "my_standalone_function",
440
- returnType: "int",
441
- refkey: staticMethodRefkey,
442
- children: "pass"
443
- })];
425
+ return _$createComponent(py.StatementList, {
426
+ get children() {
427
+ return [_$createComponent(py.VariableDeclaration, {
428
+ name: "a",
429
+ type: "int",
430
+ instanceVariable: true
431
+ }), _$createComponent(py.VariableDeclaration, {
432
+ name: "b",
433
+ type: "int",
434
+ instanceVariable: true
435
+ }), _$createComponent(py.MethodDeclaration, {
436
+ name: "my_method",
437
+ parameters: [{
438
+ name: "a",
439
+ type: "int"
440
+ }, {
441
+ name: "b",
442
+ type: "int"
443
+ }],
444
+ returnType: "int",
445
+ refkey: methodRefkey,
446
+ children: "return a + b"
447
+ }), _$createComponent(py.ClassMethodDeclaration, {
448
+ name: "my_class_method",
449
+ returnType: "int",
450
+ refkey: classMethodRefkey,
451
+ children: "pass"
452
+ }), _$createComponent(py.FunctionDeclaration, {
453
+ name: "my_standalone_function",
454
+ returnType: "int",
455
+ refkey: staticMethodRefkey,
456
+ children: "pass"
457
+ })];
458
+ }
459
+ });
444
460
  }
445
- });
461
+ }), classMethodRefkey, staticMethodRefkey];
446
462
  }
447
- }), classMethodRefkey, staticMethodRefkey];
463
+ });
448
464
  }
449
- })]);
450
- const expected = d`
465
+ })).toRenderTo(`
451
466
  class MyClass(BaseClass):
452
467
  a: int = None
453
468
  b: int = None
@@ -464,8 +479,7 @@ describe("Python Class - FunctionDeclaration", () => {
464
479
 
465
480
  MyClass.my_class_method
466
481
  MyClass.my_standalone_function
467
- `;
468
- expect(result).toRenderTo(expected);
482
+ `);
469
483
  });
470
484
  });
471
485
  //# sourceMappingURL=classdeclarations.test.js.map