@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 +1 @@
|
|
|
1
|
-
{"version":3,"names":["refkey","
|
|
1
|
+
{"version":3,"names":["refkey","describe","expect","it","py","TestOutput","_$createComponent","children","FunctionCallExpression","target","toRenderTo","args","methodRef","StatementList","FunctionDeclaration","name","Atom","jsValue","returnType","parameters","type","VariableDeclaration","initializer","callStatementVar"],"sources":["../../test/functioncallexpressions.test.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,MAAM,QAAQ,gBAAgB;AACvC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,OAAO,KAAKC,EAAE,MAAM,iBAAiB;AACrC,SAASC,UAAU,QAAQ,YAAY;AAEvCJ,QAAQ,CAAC,wBAAwB,EAAE,MAAM;EACvCE,EAAE,CAAC,SAAS,EAAE,MAAM;IAClBD,MAAM,CAAAI,iBAAA,CACHD,UAAU;MAAA,IAAAE,SAAA;QAAA,OAAAD,iBAAA,CACRF,EAAE,CAACI,sBAAsB;UAACC,MAAM;QAAA;MAAA;IAAA,EAErC,CAAC,CAACC,UAAU,CACV;AACN;AACA,KACI,CAAC;EACH,CAAC,CAAC;EAEFP,EAAE,CAAC,mBAAmB,EAAE,MAAM;IAC5BD,MAAM,CAAAI,iBAAA,CACHD,UAAU;MAAA,IAAAE,SAAA;QAAA,OAAAD,iBAAA,CACRF,EAAE,CAACI,sBAAsB;UAACC,MAAM;UAAOE,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG;QAAC;MAAA;IAAA,EAE5D,CAAC,CAACD,UAAU,CACV;AACN;AACA,KACI,CAAC;EACH,CAAC,CAAC;EAEFP,EAAE,CAAC,8BAA8B,EAAE,MAAM;IACvC,MAAMS,SAAS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EAAE,CAAC,+DAA+D,EAAE,MAAM;IACxED,MAAM,CAAAI,iBAAA,CACHD,UAAU;MAAA,IAAAE,SAAA;QAAA,OAAAD,iBAAA,CACRF,EAAE,CAACS,aAAa;UAAA,IAAAN,SAAA;YAAA,OAAAD,iBAAA,CACdF,EAAE,CAACI,sBAAsB;cACxBC,MAAM,EAAE,gBAAgB;cAAA,IACxBE,IAAIA,CAAA;gBAAA,OAAE,CAAAL,iBAAA,CACHF,EAAE,CAACY,IAAI;kBAACC,OAAO,EAAE;gBAAQ,IAAAX,iBAAA,CACzBF,EAAE,CAACiB,mBAAmB;kBACrBN,IAAI;kBACJO,WAAW,EAAE,EAAE;kBACfC,gBAAgB;gBAAA,IAAAjB,iBAAA,CAEjBF,EAAE,CAACiB,mBAAmB;kBACrBN,IAAI;kBACJO,WAAW,EAAE,IAAI;kBACjBC,gBAAgB;gBAAA,GAEnB;cAAA;YAAA;UAAA;QAAA;MAAA;IAAA,EAIT,CAAC,CAACb,UAAU,CACV;AACN;AACA,KACI,CAAC;EACH,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,183 +1,208 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { code, namekey, refkey } from "@alloy-js/core";
|
|
3
|
-
import { d } from "@alloy-js/core/testing";
|
|
2
|
+
import { code, namekey, refkey, render } from "@alloy-js/core";
|
|
4
3
|
import { describe, expect, it } from "vitest";
|
|
5
4
|
import * as py from "../src/index.js";
|
|
6
5
|
import { abcModule } from "../src/index.js";
|
|
7
|
-
import {
|
|
6
|
+
import { TestOutput, TestOutputDirectory } from "./utils.js";
|
|
8
7
|
describe("Function Declaration", () => {
|
|
9
8
|
it("renders multiple decorators above def without blank lines", () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
expect(_$createComponent(TestOutput, {
|
|
10
|
+
get children() {
|
|
11
|
+
return _$createComponent(py.FunctionDeclaration, {
|
|
12
|
+
name: "f",
|
|
13
|
+
decorators: ["@a", "@b", "@c"],
|
|
14
|
+
children: "pass"
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
})).toRenderTo(`
|
|
16
18
|
@a
|
|
17
19
|
@b
|
|
18
20
|
@c
|
|
19
21
|
def f():
|
|
20
22
|
pass
|
|
21
23
|
|
|
22
|
-
|
|
23
24
|
`);
|
|
24
25
|
});
|
|
25
26
|
it("renders a function with no body as 'pass'", () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
expect(_$createComponent(TestOutput, {
|
|
28
|
+
get children() {
|
|
29
|
+
return _$createComponent(py.FunctionDeclaration, {
|
|
30
|
+
name: "foo"
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
})).toRenderTo(`
|
|
30
34
|
def foo():
|
|
31
35
|
pass
|
|
32
36
|
|
|
33
|
-
|
|
34
37
|
`);
|
|
35
38
|
});
|
|
36
39
|
it("takes a namekey", () => {
|
|
37
|
-
|
|
38
|
-
get
|
|
39
|
-
return
|
|
40
|
+
expect(_$createComponent(TestOutput, {
|
|
41
|
+
get children() {
|
|
42
|
+
return _$createComponent(py.FunctionDeclaration, {
|
|
43
|
+
get name() {
|
|
44
|
+
return namekey("foo-bar");
|
|
45
|
+
}
|
|
46
|
+
});
|
|
40
47
|
}
|
|
41
|
-
})
|
|
42
|
-
expect(result).toRenderTo(d`
|
|
48
|
+
})).toRenderTo(`
|
|
43
49
|
def foo_bar():
|
|
44
50
|
pass
|
|
45
51
|
|
|
46
|
-
|
|
47
52
|
`);
|
|
48
53
|
});
|
|
49
54
|
it("renders a function with no body as 'pass' with return type", () => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
expect(_$createComponent(TestOutput, {
|
|
56
|
+
get children() {
|
|
57
|
+
return _$createComponent(py.FunctionDeclaration, {
|
|
58
|
+
name: "foo",
|
|
59
|
+
returnType: "int"
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
})).toRenderTo(`
|
|
55
63
|
def foo() -> int:
|
|
56
64
|
pass
|
|
57
65
|
|
|
58
|
-
|
|
59
66
|
`);
|
|
60
67
|
});
|
|
61
68
|
it("renders a function that calls another function", () => {
|
|
62
69
|
const refkeyFoo = refkey();
|
|
63
|
-
|
|
70
|
+
expect(_$createComponent(TestOutput, {
|
|
64
71
|
get children() {
|
|
65
|
-
return
|
|
66
|
-
name: "foo",
|
|
67
|
-
returnType: "int",
|
|
68
|
-
refkey: refkeyFoo
|
|
69
|
-
}), _$createComponent(py.FunctionDeclaration, {
|
|
70
|
-
name: "bar",
|
|
71
|
-
returnType: "int",
|
|
72
|
+
return _$createComponent(py.StatementList, {
|
|
72
73
|
get children() {
|
|
73
|
-
return _$createComponent(py.
|
|
74
|
-
name: "
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
return [_$createComponent(py.FunctionDeclaration, {
|
|
75
|
+
name: "foo",
|
|
76
|
+
returnType: "int",
|
|
77
|
+
refkey: refkeyFoo
|
|
78
|
+
}), _$createComponent(py.FunctionDeclaration, {
|
|
79
|
+
name: "bar",
|
|
80
|
+
returnType: "int",
|
|
81
|
+
get children() {
|
|
82
|
+
return _$createComponent(py.VariableDeclaration, {
|
|
83
|
+
name: "result",
|
|
84
|
+
type: "int",
|
|
85
|
+
get initializer() {
|
|
86
|
+
return _$createComponent(py.FunctionCallExpression, {
|
|
87
|
+
target: refkeyFoo,
|
|
88
|
+
args: []
|
|
89
|
+
});
|
|
90
|
+
}
|
|
80
91
|
});
|
|
81
92
|
}
|
|
82
|
-
});
|
|
93
|
+
})];
|
|
83
94
|
}
|
|
84
|
-
})
|
|
95
|
+
});
|
|
85
96
|
}
|
|
86
|
-
})
|
|
87
|
-
expect(result).toRenderTo(d`
|
|
97
|
+
})).toRenderTo(`
|
|
88
98
|
def foo() -> int:
|
|
89
99
|
pass
|
|
90
100
|
|
|
91
101
|
def bar() -> int:
|
|
92
102
|
result: int = foo()
|
|
93
103
|
|
|
94
|
-
|
|
95
104
|
`);
|
|
96
105
|
});
|
|
97
106
|
it("renders a function with parameters", () => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
107
|
+
expect(_$createComponent(TestOutput, {
|
|
108
|
+
get children() {
|
|
109
|
+
return _$createComponent(py.FunctionDeclaration, {
|
|
110
|
+
name: "baz",
|
|
111
|
+
parameters: [{
|
|
112
|
+
name: "x",
|
|
113
|
+
type: "int"
|
|
114
|
+
}, {
|
|
115
|
+
name: "y",
|
|
116
|
+
default: 0
|
|
117
|
+
}, {
|
|
118
|
+
name: "z",
|
|
119
|
+
type: "int",
|
|
120
|
+
default: 42
|
|
121
|
+
}],
|
|
122
|
+
args: true,
|
|
123
|
+
kwargs: true,
|
|
124
|
+
children: "print(x, y)"
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
})).toRenderTo(`
|
|
116
128
|
def baz(x: int, y=0, z: int = 42, *args, **kwargs):
|
|
117
129
|
print(x, y)
|
|
118
130
|
|
|
119
|
-
|
|
120
131
|
`);
|
|
121
132
|
});
|
|
122
133
|
it("renders an __init__ function with no body as 'pass'", () => {
|
|
123
|
-
|
|
124
|
-
name: "MyClass",
|
|
134
|
+
expect(_$createComponent(TestOutput, {
|
|
125
135
|
get children() {
|
|
126
|
-
return _$createComponent(py.
|
|
127
|
-
name: "
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
136
|
+
return _$createComponent(py.ClassDeclaration, {
|
|
137
|
+
name: "MyClass",
|
|
138
|
+
get children() {
|
|
139
|
+
return _$createComponent(py.DunderMethodDeclaration, {
|
|
140
|
+
name: "__init__",
|
|
141
|
+
parameters: [{
|
|
142
|
+
name: "x"
|
|
143
|
+
}]
|
|
144
|
+
});
|
|
145
|
+
}
|
|
131
146
|
});
|
|
132
147
|
}
|
|
133
|
-
})
|
|
134
|
-
expect(result).toRenderTo(d`
|
|
148
|
+
})).toRenderTo(`
|
|
135
149
|
class MyClass:
|
|
136
150
|
def __init__(self, x):
|
|
137
151
|
pass
|
|
138
152
|
|
|
139
|
-
|
|
140
|
-
|
|
153
|
+
|
|
141
154
|
`);
|
|
142
155
|
});
|
|
143
156
|
it("can be an async function", () => {
|
|
144
|
-
expect(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
157
|
+
expect(_$createComponent(TestOutput, {
|
|
158
|
+
get children() {
|
|
159
|
+
return _$createComponent(py.FunctionDeclaration, {
|
|
160
|
+
async: true,
|
|
161
|
+
name: "foo"
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
})).toRenderTo(`
|
|
148
165
|
async def foo():
|
|
149
166
|
pass
|
|
150
167
|
|
|
151
168
|
`);
|
|
152
169
|
});
|
|
153
170
|
it("can be an async function with returnType", () => {
|
|
154
|
-
expect(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
171
|
+
expect(_$createComponent(TestOutput, {
|
|
172
|
+
get children() {
|
|
173
|
+
return _$createComponent(py.FunctionDeclaration, {
|
|
174
|
+
async: true,
|
|
175
|
+
name: "foo",
|
|
176
|
+
returnType: "Foo"
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
})).toRenderTo(`
|
|
159
180
|
async def foo() -> Foo:
|
|
160
181
|
pass
|
|
161
182
|
|
|
162
183
|
`);
|
|
163
184
|
});
|
|
164
185
|
it("can be an async function with returnType element with Reference", () => {
|
|
165
|
-
expect(
|
|
186
|
+
expect(_$createComponent(TestOutput, {
|
|
166
187
|
get children() {
|
|
167
|
-
return
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
188
|
+
return _$createComponent(py.StatementList, {
|
|
189
|
+
get children() {
|
|
190
|
+
return [_$createComponent(py.ClassDeclaration, {
|
|
191
|
+
name: "Foo",
|
|
192
|
+
get refkey() {
|
|
193
|
+
return refkey("Foo");
|
|
194
|
+
}
|
|
195
|
+
}), _$createComponent(py.FunctionDeclaration, {
|
|
196
|
+
async: true,
|
|
197
|
+
name: "foo",
|
|
198
|
+
get returnType() {
|
|
199
|
+
return refkey("Foo");
|
|
200
|
+
}
|
|
201
|
+
})];
|
|
177
202
|
}
|
|
178
|
-
})
|
|
203
|
+
});
|
|
179
204
|
}
|
|
180
|
-
})
|
|
205
|
+
})).toRenderTo(`
|
|
181
206
|
class Foo:
|
|
182
207
|
pass
|
|
183
208
|
|
|
@@ -187,22 +212,26 @@ describe("Function Declaration", () => {
|
|
|
187
212
|
`);
|
|
188
213
|
});
|
|
189
214
|
it("can be an async function with returnType element with list of References", () => {
|
|
190
|
-
expect(
|
|
215
|
+
expect(_$createComponent(TestOutput, {
|
|
191
216
|
get children() {
|
|
192
|
-
return
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
217
|
+
return _$createComponent(py.StatementList, {
|
|
218
|
+
get children() {
|
|
219
|
+
return [_$createComponent(py.ClassDeclaration, {
|
|
220
|
+
name: "Foo",
|
|
221
|
+
get refkey() {
|
|
222
|
+
return refkey("Foo");
|
|
223
|
+
}
|
|
224
|
+
}), _$createComponent(py.FunctionDeclaration, {
|
|
225
|
+
async: true,
|
|
226
|
+
name: "foo",
|
|
227
|
+
get returnType() {
|
|
228
|
+
return code`list[${refkey("Foo")}]`;
|
|
229
|
+
}
|
|
230
|
+
})];
|
|
202
231
|
}
|
|
203
|
-
})
|
|
232
|
+
});
|
|
204
233
|
}
|
|
205
|
-
})
|
|
234
|
+
})).toRenderTo(`
|
|
206
235
|
class Foo:
|
|
207
236
|
pass
|
|
208
237
|
|
|
@@ -231,7 +260,9 @@ describe("Function Declaration", () => {
|
|
|
231
260
|
});
|
|
232
261
|
}
|
|
233
262
|
});
|
|
234
|
-
expect(
|
|
263
|
+
expect(_$createComponent(TestOutput, {
|
|
264
|
+
children: decl
|
|
265
|
+
})).toRenderTo(`
|
|
235
266
|
class MyClass:
|
|
236
267
|
async def __aenter__(self) -> MyClass:
|
|
237
268
|
return self
|
|
@@ -258,7 +289,9 @@ describe("Function Declaration", () => {
|
|
|
258
289
|
});
|
|
259
290
|
}
|
|
260
291
|
});
|
|
261
|
-
expect(
|
|
292
|
+
expect(_$createComponent(TestOutput, {
|
|
293
|
+
children: decl
|
|
294
|
+
})).toRenderTo(`
|
|
262
295
|
class MyClass:
|
|
263
296
|
async def __new__(cls) -> MyClass:
|
|
264
297
|
return super().__new__(cls)
|
|
@@ -276,7 +309,9 @@ describe("Function Declaration", () => {
|
|
|
276
309
|
}],
|
|
277
310
|
children: "return a + b"
|
|
278
311
|
});
|
|
279
|
-
expect(
|
|
312
|
+
expect(_$createComponent(TestOutput, {
|
|
313
|
+
children: decl
|
|
314
|
+
})).toRenderTo(`
|
|
280
315
|
def foo(a, b):
|
|
281
316
|
return a + b
|
|
282
317
|
|
|
@@ -293,7 +328,9 @@ describe("Function Declaration", () => {
|
|
|
293
328
|
typeParameters: ["T", "U"],
|
|
294
329
|
children: "return a + b"
|
|
295
330
|
});
|
|
296
|
-
expect(
|
|
331
|
+
expect(_$createComponent(TestOutput, {
|
|
332
|
+
children: decl
|
|
333
|
+
})).toRenderTo(`
|
|
297
334
|
def foo[T, U](a, b):
|
|
298
335
|
return a + b
|
|
299
336
|
|
|
@@ -330,9 +367,10 @@ describe("Function Declaration", () => {
|
|
|
330
367
|
});
|
|
331
368
|
}
|
|
332
369
|
});
|
|
333
|
-
expect(
|
|
334
|
-
externals: [abcModule]
|
|
335
|
-
|
|
370
|
+
expect(_$createComponent(TestOutput, {
|
|
371
|
+
externals: [abcModule],
|
|
372
|
+
children: decl
|
|
373
|
+
})).toRenderTo(`
|
|
336
374
|
from abc import abstractmethod
|
|
337
375
|
|
|
338
376
|
|
|
@@ -377,7 +415,9 @@ describe("Function Declaration", () => {
|
|
|
377
415
|
});
|
|
378
416
|
}
|
|
379
417
|
});
|
|
380
|
-
expect(
|
|
418
|
+
expect(_$createComponent(TestOutput, {
|
|
419
|
+
children: decl
|
|
420
|
+
})).toRenderTo(`
|
|
381
421
|
class MyClass:
|
|
382
422
|
def __init__(self, x: int):
|
|
383
423
|
self.attribute = "value"
|
|
@@ -403,7 +443,9 @@ describe("Function Declaration", () => {
|
|
|
403
443
|
});
|
|
404
444
|
}
|
|
405
445
|
});
|
|
406
|
-
expect(
|
|
446
|
+
expect(_$createComponent(TestOutput, {
|
|
447
|
+
children: decl
|
|
448
|
+
})).toRenderTo(`
|
|
407
449
|
class MyClass:
|
|
408
450
|
def __new__(cls, *args, **kwargs):
|
|
409
451
|
pass
|
|
@@ -461,7 +503,9 @@ describe("Function Declaration", () => {
|
|
|
461
503
|
})];
|
|
462
504
|
}
|
|
463
505
|
});
|
|
464
|
-
expect(
|
|
506
|
+
expect(_$createComponent(TestOutput, {
|
|
507
|
+
children: decl
|
|
508
|
+
})).toRenderTo(`
|
|
465
509
|
def foo(x: int):
|
|
466
510
|
def bar(y: int):
|
|
467
511
|
def foobar(z: int):
|
|
@@ -472,55 +516,58 @@ describe("Function Declaration", () => {
|
|
|
472
516
|
`);
|
|
473
517
|
});
|
|
474
518
|
it("renders complex typing structure", () => {
|
|
475
|
-
|
|
476
|
-
path: "mod1.py",
|
|
519
|
+
expect(_$createComponent(TestOutputDirectory, {
|
|
477
520
|
get children() {
|
|
478
|
-
return _$createComponent(py.
|
|
479
|
-
|
|
480
|
-
get
|
|
481
|
-
return
|
|
521
|
+
return [_$createComponent(py.SourceFile, {
|
|
522
|
+
path: "mod1.py",
|
|
523
|
+
get children() {
|
|
524
|
+
return _$createComponent(py.ClassDeclaration, {
|
|
525
|
+
name: "Foo",
|
|
526
|
+
get refkey() {
|
|
527
|
+
return refkey("Foo");
|
|
528
|
+
}
|
|
529
|
+
});
|
|
482
530
|
}
|
|
483
|
-
})
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
531
|
+
}), _$createComponent(py.SourceFile, {
|
|
532
|
+
path: "mod2.py",
|
|
533
|
+
get children() {
|
|
534
|
+
return [_$createComponent(py.ClassDeclaration, {
|
|
535
|
+
name: "A",
|
|
536
|
+
get refkey() {
|
|
537
|
+
return refkey("A");
|
|
538
|
+
}
|
|
539
|
+
}), _$createComponent(py.ClassDeclaration, {
|
|
540
|
+
name: "B",
|
|
541
|
+
get refkey() {
|
|
542
|
+
return refkey("B");
|
|
543
|
+
}
|
|
544
|
+
})];
|
|
492
545
|
}
|
|
493
|
-
}), _$createComponent(py.
|
|
494
|
-
|
|
495
|
-
get
|
|
496
|
-
return
|
|
546
|
+
}), _$createComponent(py.SourceFile, {
|
|
547
|
+
path: "usage.py",
|
|
548
|
+
get children() {
|
|
549
|
+
return _$createComponent(py.FunctionDeclaration, {
|
|
550
|
+
async: true,
|
|
551
|
+
name: "foo",
|
|
552
|
+
get parameters() {
|
|
553
|
+
return [{
|
|
554
|
+
name: "x",
|
|
555
|
+
type: refkey("A")
|
|
556
|
+
}, {
|
|
557
|
+
name: "y",
|
|
558
|
+
type: refkey("B")
|
|
559
|
+
}];
|
|
560
|
+
},
|
|
561
|
+
args: true,
|
|
562
|
+
kwargs: true,
|
|
563
|
+
get returnType() {
|
|
564
|
+
return refkey("Foo");
|
|
565
|
+
}
|
|
566
|
+
});
|
|
497
567
|
}
|
|
498
568
|
})];
|
|
499
569
|
}
|
|
500
|
-
})
|
|
501
|
-
path: "usage.py",
|
|
502
|
-
get children() {
|
|
503
|
-
return _$createComponent(py.FunctionDeclaration, {
|
|
504
|
-
async: true,
|
|
505
|
-
name: "foo",
|
|
506
|
-
get parameters() {
|
|
507
|
-
return [{
|
|
508
|
-
name: "x",
|
|
509
|
-
type: refkey("A")
|
|
510
|
-
}, {
|
|
511
|
-
name: "y",
|
|
512
|
-
type: refkey("B")
|
|
513
|
-
}];
|
|
514
|
-
},
|
|
515
|
-
args: true,
|
|
516
|
-
kwargs: true,
|
|
517
|
-
get returnType() {
|
|
518
|
-
return refkey("Foo");
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
})]);
|
|
523
|
-
assertFileContents(res, {
|
|
570
|
+
})).toRenderTo({
|
|
524
571
|
"mod1.py": `
|
|
525
572
|
class Foo:
|
|
526
573
|
pass
|
|
@@ -552,37 +599,57 @@ describe("Function Declaration", () => {
|
|
|
552
599
|
});
|
|
553
600
|
it("throws error when PropertyDeclaration is used outside of a class", () => {
|
|
554
601
|
expect(() => {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
602
|
+
render(_$createComponent(TestOutput, {
|
|
603
|
+
get children() {
|
|
604
|
+
return _$createComponent(py.PropertyDeclaration, {
|
|
605
|
+
name: "x"
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
}));
|
|
558
609
|
}).toThrow('Method "x" must be declared inside a class (member scope)');
|
|
559
610
|
});
|
|
560
611
|
it("throws error when MethodDeclaration is used outside of a class", () => {
|
|
561
612
|
expect(() => {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
613
|
+
render(_$createComponent(TestOutput, {
|
|
614
|
+
get children() {
|
|
615
|
+
return _$createComponent(py.MethodDeclaration, {
|
|
616
|
+
name: "my_method"
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
}));
|
|
565
620
|
}).toThrow('Method "my_method" must be declared inside a class (member scope)');
|
|
566
621
|
});
|
|
567
622
|
it("throws error when ClassMethodDeclaration is used outside of a class", () => {
|
|
568
623
|
expect(() => {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
624
|
+
render(_$createComponent(TestOutput, {
|
|
625
|
+
get children() {
|
|
626
|
+
return _$createComponent(py.ClassMethodDeclaration, {
|
|
627
|
+
name: "my_class_method"
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
}));
|
|
572
631
|
}).toThrow('Method "my_class_method" must be declared inside a class (member scope)');
|
|
573
632
|
});
|
|
574
633
|
it("throws error when StaticMethodDeclaration is used outside of a class", () => {
|
|
575
634
|
expect(() => {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
635
|
+
render(_$createComponent(TestOutput, {
|
|
636
|
+
get children() {
|
|
637
|
+
return _$createComponent(py.StaticMethodDeclaration, {
|
|
638
|
+
name: "my_static_method"
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
}));
|
|
579
642
|
}).toThrow('Method "my_static_method" must be declared inside a class (member scope)');
|
|
580
643
|
});
|
|
581
644
|
it("throws error when DunderMethodDeclaration is used outside of a class", () => {
|
|
582
645
|
expect(() => {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
646
|
+
render(_$createComponent(TestOutput, {
|
|
647
|
+
get children() {
|
|
648
|
+
return _$createComponent(py.DunderMethodDeclaration, {
|
|
649
|
+
name: "__init__"
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
}));
|
|
586
653
|
}).toThrow('Method "__init__" must be declared inside a class (member scope)');
|
|
587
654
|
});
|
|
588
655
|
});
|