@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.
- package/dist/dev/src/components/SourceFile.js +44 -32
- package/dist/dev/src/components/SourceFile.js.map +1 -1
- package/dist/dev/test/callsignatures.test.js +471 -297
- package/dist/dev/test/callsignatures.test.js.map +1 -1
- package/dist/dev/test/class-method-declaration.test.js +21 -10
- package/dist/dev/test/class-method-declaration.test.js.map +1 -1
- package/dist/dev/test/classdeclarations.test.js +459 -393
- package/dist/dev/test/classdeclarations.test.js.map +1 -1
- package/dist/dev/test/classinstantiations.test.js +201 -168
- package/dist/dev/test/classinstantiations.test.js.map +1 -1
- package/dist/dev/test/constructordeclaration.test.js +22 -11
- package/dist/dev/test/constructordeclaration.test.js.map +1 -1
- package/dist/dev/test/dataclassdeclarations.test.js +322 -368
- package/dist/dev/test/dataclassdeclarations.test.js.map +1 -1
- package/dist/dev/test/decoratorlist.test.js +96 -49
- package/dist/dev/test/decoratorlist.test.js.map +1 -1
- package/dist/dev/test/dundermethoddeclaration.test.js +22 -11
- package/dist/dev/test/dundermethoddeclaration.test.js.map +1 -1
- package/dist/dev/test/enums.test.js +218 -184
- package/dist/dev/test/enums.test.js.map +1 -1
- package/dist/dev/test/externals.test.js +57 -45
- package/dist/dev/test/externals.test.js.map +1 -1
- package/dist/dev/test/factories.test.js +124 -50
- package/dist/dev/test/factories.test.js.map +1 -1
- package/dist/dev/test/functioncallexpressions.test.js +199 -164
- package/dist/dev/test/functioncallexpressions.test.js.map +1 -1
- package/dist/dev/test/functiondeclaration.test.js +439 -272
- package/dist/dev/test/functiondeclaration.test.js.map +1 -1
- package/dist/dev/test/imports.test.js +273 -221
- package/dist/dev/test/imports.test.js.map +1 -1
- package/dist/dev/test/memberexpressions.test.js +1237 -972
- package/dist/dev/test/memberexpressions.test.js.map +1 -1
- package/dist/dev/test/methoddeclaration.test.js +142 -78
- package/dist/dev/test/methoddeclaration.test.js.map +1 -1
- package/dist/dev/test/namepolicies.test.js +130 -94
- package/dist/dev/test/namepolicies.test.js.map +1 -1
- package/dist/dev/test/propertydeclaration.test.js +88 -59
- package/dist/dev/test/propertydeclaration.test.js.map +1 -1
- package/dist/dev/test/pydanticclassdeclarations.test.js +299 -347
- package/dist/dev/test/pydanticclassdeclarations.test.js.map +1 -1
- package/dist/dev/test/pydocs.test.js +888 -715
- package/dist/dev/test/pydocs.test.js.map +1 -1
- package/dist/dev/test/references.test.js +42 -35
- package/dist/dev/test/references.test.js.map +1 -1
- package/dist/dev/test/sourcefiles.test.js +1109 -841
- package/dist/dev/test/sourcefiles.test.js.map +1 -1
- package/dist/dev/test/staticmethoddeclaration.test.js +21 -10
- package/dist/dev/test/staticmethoddeclaration.test.js.map +1 -1
- package/dist/dev/test/type-checking-imports.test.js +408 -359
- package/dist/dev/test/type-checking-imports.test.js.map +1 -1
- package/dist/dev/test/typereference.test.js +55 -40
- package/dist/dev/test/typereference.test.js.map +1 -1
- package/dist/dev/test/uniontypeexpression.test.js +222 -146
- package/dist/dev/test/uniontypeexpression.test.js.map +1 -1
- package/dist/dev/test/utils.js +39 -77
- package/dist/dev/test/utils.js.map +1 -1
- package/dist/dev/test/values.test.js +237 -101
- package/dist/dev/test/values.test.js.map +1 -1
- package/dist/dev/test/variables.test.js +321 -203
- package/dist/dev/test/variables.test.js.map +1 -1
- package/dist/dev/test/vitest.setup.js +2 -0
- package/dist/dev/test/vitest.setup.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts +2 -2
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +12 -0
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/test/callsignatures.test.js +346 -272
- package/dist/test/callsignatures.test.js.map +1 -1
- package/dist/test/class-method-declaration.test.js +7 -4
- package/dist/test/class-method-declaration.test.js.map +1 -1
- package/dist/test/classdeclarations.test.js +302 -288
- package/dist/test/classdeclarations.test.js.map +1 -1
- package/dist/test/classinstantiations.test.js +112 -103
- package/dist/test/classinstantiations.test.js.map +1 -1
- package/dist/test/constructordeclaration.test.js +7 -4
- package/dist/test/constructordeclaration.test.js.map +1 -1
- package/dist/test/dataclassdeclarations.test.js +134 -184
- package/dist/test/dataclassdeclarations.test.js.map +1 -1
- package/dist/test/decoratorlist.test.js +59 -36
- package/dist/test/decoratorlist.test.js.map +1 -1
- package/dist/test/dundermethoddeclaration.test.js +7 -4
- package/dist/test/dundermethoddeclaration.test.js.map +1 -1
- package/dist/test/enums.test.js +161 -159
- package/dist/test/enums.test.js.map +1 -1
- package/dist/test/externals.test.js +24 -24
- package/dist/test/externals.test.js.map +1 -1
- package/dist/test/factories.test.js +75 -33
- package/dist/test/factories.test.js.map +1 -1
- package/dist/test/functioncallexpressions.test.js +117 -106
- package/dist/test/functioncallexpressions.test.js.map +1 -1
- package/dist/test/functiondeclaration.test.js +247 -180
- package/dist/test/functiondeclaration.test.js.map +1 -1
- package/dist/test/imports.test.js +171 -143
- package/dist/test/imports.test.js.map +1 -1
- package/dist/test/memberexpressions.test.js +582 -453
- package/dist/test/memberexpressions.test.js.map +1 -1
- package/dist/test/methoddeclaration.test.js +66 -46
- package/dist/test/methoddeclaration.test.js.map +1 -1
- package/dist/test/namepolicies.test.js +90 -78
- package/dist/test/namepolicies.test.js.map +1 -1
- package/dist/test/propertydeclaration.test.js +25 -20
- package/dist/test/propertydeclaration.test.js.map +1 -1
- package/dist/test/pydanticclassdeclarations.test.js +134 -190
- package/dist/test/pydanticclassdeclarations.test.js.map +1 -1
- package/dist/test/pydocs.test.js +573 -532
- package/dist/test/pydocs.test.js.map +1 -1
- package/dist/test/references.test.js +31 -28
- package/dist/test/references.test.js.map +1 -1
- package/dist/test/sourcefiles.test.js +700 -580
- package/dist/test/sourcefiles.test.js.map +1 -1
- package/dist/test/staticmethoddeclaration.test.js +7 -4
- package/dist/test/staticmethoddeclaration.test.js.map +1 -1
- package/dist/test/type-checking-imports.test.js +297 -284
- package/dist/test/type-checking-imports.test.js.map +1 -1
- package/dist/test/typereference.test.js +29 -22
- package/dist/test/typereference.test.js.map +1 -1
- package/dist/test/uniontypeexpression.test.js +124 -88
- package/dist/test/uniontypeexpression.test.js.map +1 -1
- package/dist/test/utils.d.ts +10 -17
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +32 -74
- package/dist/test/utils.js.map +1 -1
- package/dist/test/values.test.js +135 -67
- package/dist/test/values.test.js.map +1 -1
- package/dist/test/variables.test.js +201 -151
- package/dist/test/variables.test.js.map +1 -1
- package/dist/test/vitest.setup.d.ts +2 -0
- package/dist/test/vitest.setup.d.ts.map +1 -0
- package/dist/test/vitest.setup.js +2 -0
- package/dist/test/vitest.setup.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docs/api/components/SourceFile.md +20 -8
- package/package.json +2 -2
- package/src/components/SourceFile.tsx +6 -1
- package/temp/api.json +16 -2
- package/test/callsignatures.test.tsx +309 -283
- package/test/class-method-declaration.test.tsx +3 -4
- package/test/classdeclarations.test.tsx +263 -248
- package/test/classinstantiations.test.tsx +115 -109
- package/test/constructordeclaration.test.tsx +9 -6
- package/test/dataclassdeclarations.test.tsx +243 -361
- package/test/decoratorlist.test.tsx +78 -59
- package/test/dundermethoddeclaration.test.tsx +3 -4
- package/test/enums.test.tsx +65 -81
- package/test/externals.test.tsx +25 -25
- package/test/factories.test.tsx +64 -22
- package/test/functioncallexpressions.test.tsx +123 -109
- package/test/functiondeclaration.test.tsx +209 -148
- package/test/imports.test.tsx +119 -91
- package/test/memberexpressions.test.tsx +265 -207
- package/test/methoddeclaration.test.tsx +84 -63
- package/test/namepolicies.test.tsx +69 -69
- package/test/propertydeclaration.test.tsx +7 -8
- package/test/pydanticclassdeclarations.test.tsx +355 -487
- package/test/pydocs.test.tsx +531 -579
- package/test/references.test.tsx +24 -23
- package/test/sourcefiles.test.tsx +527 -492
- package/test/staticmethoddeclaration.test.tsx +3 -4
- package/test/type-checking-imports.test.tsx +206 -218
- package/test/typereference.test.tsx +15 -12
- package/test/uniontypeexpression.test.tsx +74 -61
- package/test/utils.tsx +26 -110
- package/test/values.test.tsx +82 -32
- package/test/variables.test.tsx +162 -142
- package/test/vitest.setup.ts +1 -0
- 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 {
|
|
5
|
+
import { TestOutput, TestOutputDirectory } from "./utils.js";
|
|
7
6
|
describe("Python Class", () => {
|
|
8
7
|
it("renders class-level decorators above `class`", () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
46
|
-
get
|
|
47
|
-
return
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
79
|
+
expect(_$createComponent(TestOutput, {
|
|
71
80
|
get children() {
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
119
|
-
path: "mod1.py",
|
|
130
|
+
expect(_$createComponent(TestOutputDirectory, {
|
|
120
131
|
get children() {
|
|
121
|
-
return _$createComponent(py.
|
|
122
|
-
|
|
123
|
-
get
|
|
124
|
-
return
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
163
|
-
|
|
172
|
+
`,
|
|
173
|
+
"folder/mod2.py": `
|
|
174
|
+
from mod1 import A
|
|
164
175
|
|
|
165
176
|
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
192
|
+
expect(_$createComponent(TestOutput, {
|
|
188
193
|
get children() {
|
|
189
|
-
return
|
|
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.
|
|
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
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
237
|
+
expect(_$createComponent(TestOutput, {
|
|
232
238
|
get children() {
|
|
233
|
-
return
|
|
234
|
-
name: "A",
|
|
239
|
+
return _$createComponent(py.StatementList, {
|
|
235
240
|
get children() {
|
|
236
|
-
return _$createComponent(py.
|
|
241
|
+
return [_$createComponent(py.ClassDeclaration, {
|
|
242
|
+
name: "A",
|
|
237
243
|
get children() {
|
|
238
|
-
return _$createComponent(py.
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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.
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
})
|
|
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
|
-
|
|
287
|
+
expect(_$createComponent(TestOutput, {
|
|
280
288
|
get children() {
|
|
281
|
-
return
|
|
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.
|
|
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
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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
|
-
|
|
339
|
-
path: "inst.py",
|
|
347
|
+
expect(_$createComponent(TestOutputDirectory, {
|
|
340
348
|
get children() {
|
|
341
|
-
return _$createComponent(py.
|
|
349
|
+
return [_$createComponent(py.SourceFile, {
|
|
350
|
+
path: "inst.py",
|
|
342
351
|
get children() {
|
|
343
|
-
return
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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
|
-
})
|
|
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.
|
|
370
|
+
return _$createComponent(py.ClassDeclaration, {
|
|
371
|
+
name: "Bar",
|
|
372
|
+
refkey: classRk,
|
|
364
373
|
get children() {
|
|
365
|
-
return
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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
|
-
|
|
395
|
+
from decl import Bar
|
|
384
396
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
397
|
+
one: Bar = Bar()
|
|
398
|
+
one.instance_prop
|
|
399
|
+
one.instance_method()
|
|
400
|
+
`,
|
|
389
401
|
"decl.py": `
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
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
|
-
|
|
417
|
+
expect(_$createComponent(TestOutput, {
|
|
406
418
|
get children() {
|
|
407
|
-
return
|
|
408
|
-
name: "MyClass",
|
|
409
|
-
bases: ["BaseClass"],
|
|
419
|
+
return _$createComponent(py.StatementList, {
|
|
410
420
|
get children() {
|
|
411
|
-
return _$createComponent(py.
|
|
421
|
+
return [_$createComponent(py.ClassDeclaration, {
|
|
422
|
+
name: "MyClass",
|
|
423
|
+
bases: ["BaseClass"],
|
|
412
424
|
get children() {
|
|
413
|
-
return
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
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
|
-
})
|
|
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
|