@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,27 +1,28 @@
|
|
|
1
1
|
import { refkey } from "@alloy-js/core";
|
|
2
|
-
import { d } from "@alloy-js/core/testing";
|
|
3
2
|
import { describe, expect, it } from "vitest";
|
|
4
3
|
import * as py from "../src/index.js";
|
|
5
|
-
import {
|
|
6
|
-
assertFileContents,
|
|
7
|
-
toSourceText,
|
|
8
|
-
toSourceTextMultiple,
|
|
9
|
-
} from "./utils.jsx";
|
|
4
|
+
import { TestOutput, TestOutputDirectory } from "./utils.js";
|
|
10
5
|
|
|
11
6
|
describe("UnionTypeExpression", () => {
|
|
12
7
|
it("renders a Python union expression - 1 item", () => {
|
|
13
8
|
expect(
|
|
14
|
-
|
|
9
|
+
<TestOutput>
|
|
10
|
+
<py.UnionTypeExpression children={["int"]} />
|
|
11
|
+
</TestOutput>,
|
|
15
12
|
).toRenderTo("int");
|
|
16
13
|
});
|
|
14
|
+
|
|
17
15
|
it("renders a Python union expression - 2 items", () => {
|
|
18
16
|
expect(
|
|
19
|
-
|
|
17
|
+
<TestOutput>
|
|
18
|
+
<py.UnionTypeExpression children={["int", "str"]} />
|
|
19
|
+
</TestOutput>,
|
|
20
20
|
).toRenderTo("int | str");
|
|
21
21
|
});
|
|
22
|
+
|
|
22
23
|
it("renders a Python union expression - N items", () => {
|
|
23
24
|
expect(
|
|
24
|
-
|
|
25
|
+
<TestOutput>
|
|
25
26
|
<py.UnionTypeExpression
|
|
26
27
|
children={[
|
|
27
28
|
"int",
|
|
@@ -38,9 +39,10 @@ describe("UnionTypeExpression", () => {
|
|
|
38
39
|
"memoryview",
|
|
39
40
|
"complex",
|
|
40
41
|
]}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
).toRenderTo(
|
|
42
|
+
/>
|
|
43
|
+
</TestOutput>,
|
|
44
|
+
).toRenderTo(
|
|
45
|
+
`
|
|
44
46
|
(
|
|
45
47
|
int
|
|
46
48
|
| str
|
|
@@ -55,31 +57,36 @@ describe("UnionTypeExpression", () => {
|
|
|
55
57
|
| bytearray
|
|
56
58
|
| memoryview
|
|
57
59
|
| complex
|
|
58
|
-
)
|
|
60
|
+
)`,
|
|
61
|
+
);
|
|
59
62
|
});
|
|
63
|
+
|
|
60
64
|
it("renders a Python union expression - 2 items again", () => {
|
|
61
65
|
expect(
|
|
62
|
-
|
|
66
|
+
<TestOutput>
|
|
67
|
+
<py.UnionTypeExpression children={["int", "str"]} />
|
|
68
|
+
</TestOutput>,
|
|
63
69
|
).toRenderTo("int | str");
|
|
64
70
|
});
|
|
71
|
+
|
|
65
72
|
it("renders a Python union expression - 2 items with None", () => {
|
|
66
73
|
expect(
|
|
67
|
-
|
|
68
|
-
<py.UnionTypeExpression children={["int", "str", "None"]}
|
|
69
|
-
|
|
74
|
+
<TestOutput>
|
|
75
|
+
<py.UnionTypeExpression children={["int", "str", "None"]} />
|
|
76
|
+
</TestOutput>,
|
|
70
77
|
).toRenderTo("int | str | None");
|
|
71
78
|
});
|
|
72
79
|
|
|
73
80
|
it("renders a Python union with generic types", () => {
|
|
74
81
|
expect(
|
|
75
|
-
|
|
82
|
+
<TestOutput>
|
|
76
83
|
<py.UnionTypeExpression
|
|
77
84
|
children={[
|
|
78
85
|
<py.TypeReference name="list" typeArgs={["int"]} />,
|
|
79
86
|
<py.TypeReference name="dict" typeArgs={["str", "int"]} />,
|
|
80
87
|
]}
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
/>
|
|
89
|
+
</TestOutput>,
|
|
83
90
|
).toRenderTo("list[int] | dict[str, int]");
|
|
84
91
|
});
|
|
85
92
|
|
|
@@ -88,7 +95,7 @@ describe("UnionTypeExpression", () => {
|
|
|
88
95
|
const otherClassRefkey = refkey();
|
|
89
96
|
|
|
90
97
|
expect(
|
|
91
|
-
|
|
98
|
+
<TestOutput>
|
|
92
99
|
<py.StatementList>
|
|
93
100
|
<py.ClassDeclaration
|
|
94
101
|
name="Bar"
|
|
@@ -104,9 +111,10 @@ describe("UnionTypeExpression", () => {
|
|
|
104
111
|
<py.Reference refkey={otherClassRefkey} />,
|
|
105
112
|
]}
|
|
106
113
|
/>
|
|
107
|
-
</py.StatementList
|
|
108
|
-
|
|
109
|
-
).toRenderTo(
|
|
114
|
+
</py.StatementList>
|
|
115
|
+
</TestOutput>,
|
|
116
|
+
).toRenderTo(
|
|
117
|
+
`
|
|
110
118
|
class Bar:
|
|
111
119
|
pass
|
|
112
120
|
|
|
@@ -114,38 +122,40 @@ describe("UnionTypeExpression", () => {
|
|
|
114
122
|
pass
|
|
115
123
|
|
|
116
124
|
Bar | Foo
|
|
117
|
-
|
|
125
|
+
`,
|
|
126
|
+
);
|
|
118
127
|
});
|
|
119
128
|
|
|
120
129
|
it("emits import for TypeReference with refkey and typeArgs across files", () => {
|
|
121
130
|
const classRefkey = refkey();
|
|
122
|
-
|
|
123
|
-
<
|
|
124
|
-
<py.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
<py.
|
|
128
|
-
<py.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
expect(
|
|
132
|
+
<TestOutputDirectory>
|
|
133
|
+
<py.SourceFile path="defs.py">
|
|
134
|
+
<py.ClassDeclaration name="Bar" refkey={classRefkey} />
|
|
135
|
+
</py.SourceFile>
|
|
136
|
+
<py.SourceFile path="use.py">
|
|
137
|
+
<py.StatementList>
|
|
138
|
+
<py.VariableDeclaration
|
|
139
|
+
name="v"
|
|
140
|
+
type={<py.TypeReference refkey={classRefkey} typeArgs={["T"]} />}
|
|
141
|
+
/>
|
|
142
|
+
</py.StatementList>
|
|
143
|
+
</py.SourceFile>
|
|
144
|
+
</TestOutputDirectory>,
|
|
145
|
+
).toRenderTo({
|
|
136
146
|
"defs.py": `
|
|
137
|
-
|
|
138
|
-
|
|
147
|
+
class Bar:
|
|
148
|
+
pass
|
|
139
149
|
|
|
140
|
-
|
|
150
|
+
`,
|
|
141
151
|
"use.py": `
|
|
142
|
-
|
|
152
|
+
from typing import TYPE_CHECKING
|
|
143
153
|
|
|
144
|
-
|
|
145
|
-
|
|
154
|
+
if TYPE_CHECKING:
|
|
155
|
+
from defs import Bar
|
|
146
156
|
|
|
147
|
-
|
|
148
|
-
|
|
157
|
+
v: Bar[T] = None
|
|
158
|
+
`,
|
|
149
159
|
});
|
|
150
160
|
});
|
|
151
161
|
});
|
|
@@ -159,11 +169,11 @@ describe("TypeExpression in different scenarios", () => {
|
|
|
159
169
|
/>
|
|
160
170
|
);
|
|
161
171
|
expect(
|
|
162
|
-
|
|
172
|
+
<TestOutput>
|
|
163
173
|
<py.ClassDeclaration
|
|
164
174
|
name="Foo"
|
|
165
175
|
refkey={classRefkey}
|
|
166
|
-
></py.ClassDeclaration
|
|
176
|
+
></py.ClassDeclaration>
|
|
167
177
|
<py.FunctionDeclaration
|
|
168
178
|
name="fooFunction"
|
|
169
179
|
parameters={[
|
|
@@ -175,9 +185,10 @@ describe("TypeExpression in different scenarios", () => {
|
|
|
175
185
|
args={true}
|
|
176
186
|
kwargs={true}
|
|
177
187
|
returnType={type}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
).toRenderTo(
|
|
188
|
+
/>
|
|
189
|
+
</TestOutput>,
|
|
190
|
+
).toRenderTo(
|
|
191
|
+
`
|
|
181
192
|
class Foo:
|
|
182
193
|
pass
|
|
183
194
|
|
|
@@ -185,9 +196,10 @@ describe("TypeExpression in different scenarios", () => {
|
|
|
185
196
|
def foo_function(x: int | str | Foo, *args, **kwargs) -> int | str | Foo:
|
|
186
197
|
pass
|
|
187
198
|
|
|
188
|
-
|
|
189
|
-
|
|
199
|
+
`,
|
|
200
|
+
);
|
|
190
201
|
});
|
|
202
|
+
|
|
191
203
|
it("renders an UnionTypeExpression as a variable type", () => {
|
|
192
204
|
const classRefkey = refkey();
|
|
193
205
|
const type = (
|
|
@@ -196,20 +208,21 @@ describe("TypeExpression in different scenarios", () => {
|
|
|
196
208
|
/>
|
|
197
209
|
);
|
|
198
210
|
expect(
|
|
199
|
-
|
|
211
|
+
<TestOutput>
|
|
200
212
|
<py.ClassDeclaration
|
|
201
213
|
name="Foo"
|
|
202
214
|
refkey={classRefkey}
|
|
203
|
-
></py.ClassDeclaration
|
|
204
|
-
<py.VariableDeclaration name="fooVariable" type={type}
|
|
205
|
-
|
|
206
|
-
).toRenderTo(
|
|
215
|
+
></py.ClassDeclaration>
|
|
216
|
+
<py.VariableDeclaration name="fooVariable" type={type} />
|
|
217
|
+
</TestOutput>,
|
|
218
|
+
).toRenderTo(
|
|
219
|
+
`
|
|
207
220
|
class Foo:
|
|
208
221
|
pass
|
|
209
222
|
|
|
210
223
|
|
|
211
224
|
foo_variable: int | str | Foo = None
|
|
212
|
-
|
|
213
|
-
|
|
225
|
+
`,
|
|
226
|
+
);
|
|
214
227
|
});
|
|
215
228
|
});
|
package/test/utils.tsx
CHANGED
|
@@ -1,133 +1,49 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Binder,
|
|
3
3
|
Children,
|
|
4
|
-
ContentOutputFile,
|
|
5
4
|
NamePolicy,
|
|
6
5
|
Output,
|
|
7
|
-
OutputDirectory,
|
|
8
|
-
OutputFile,
|
|
9
6
|
OutputScope,
|
|
10
|
-
PrintTreeOptions,
|
|
11
7
|
SymbolCreator,
|
|
12
|
-
render,
|
|
13
8
|
} from "@alloy-js/core";
|
|
14
|
-
import { dedent } from "@alloy-js/core/testing";
|
|
15
|
-
import { expect } from "vitest";
|
|
16
9
|
import * as py from "../src/components/index.js";
|
|
17
10
|
import { pythonNameConflictResolver } from "../src/name-conflict-resolver.js";
|
|
18
11
|
import { createPythonNamePolicy } from "../src/name-policy.js";
|
|
19
12
|
import { PythonModuleScope } from "../src/symbols/index.js";
|
|
20
13
|
|
|
21
|
-
export function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
throw new Error("Expected to find file " + path);
|
|
29
|
-
}
|
|
30
|
-
return result as ContentOutputFile;
|
|
31
|
-
|
|
32
|
-
function findFileWorker(
|
|
33
|
-
res: OutputDirectory,
|
|
34
|
-
path: string,
|
|
35
|
-
): OutputFile | null {
|
|
36
|
-
for (const item of res.contents) {
|
|
37
|
-
if (item.kind === "file") {
|
|
38
|
-
if (item.path === path) {
|
|
39
|
-
return item;
|
|
40
|
-
}
|
|
41
|
-
continue;
|
|
42
|
-
} else {
|
|
43
|
-
const found = findFileWorker(item, path);
|
|
44
|
-
if (found) {
|
|
45
|
-
return found;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function assertFileContents(
|
|
54
|
-
res: OutputDirectory,
|
|
55
|
-
expectedFiles: Record<string, string>,
|
|
56
|
-
) {
|
|
57
|
-
for (const [path, contents] of Object.entries(expectedFiles)) {
|
|
58
|
-
const file = findFile(res, path);
|
|
59
|
-
expect(file.contents).toBe(dedent(contents));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function toSourceTextMultiple(
|
|
64
|
-
sourceFiles: Children[],
|
|
65
|
-
{
|
|
66
|
-
policy,
|
|
67
|
-
externals,
|
|
68
|
-
options,
|
|
69
|
-
printOptions,
|
|
70
|
-
}: {
|
|
71
|
-
policy?: NamePolicy<string>;
|
|
72
|
-
externals?: SymbolCreator[];
|
|
73
|
-
options?: { externals?: SymbolCreator[] };
|
|
74
|
-
printOptions?: PrintTreeOptions;
|
|
75
|
-
} = {},
|
|
76
|
-
): OutputDirectory {
|
|
77
|
-
if (!policy) {
|
|
78
|
-
policy = createPythonNamePolicy();
|
|
79
|
-
}
|
|
80
|
-
const mergedExternals = options?.externals ?? externals;
|
|
81
|
-
if (printOptions === undefined) {
|
|
82
|
-
printOptions = {
|
|
83
|
-
printWidth: 80,
|
|
84
|
-
tabWidth: 4,
|
|
85
|
-
insertFinalNewLine: false,
|
|
86
|
-
};
|
|
87
|
-
} else {
|
|
88
|
-
printOptions.insertFinalNewLine = false;
|
|
89
|
-
printOptions.tabWidth = 4;
|
|
90
|
-
}
|
|
91
|
-
const content = (
|
|
14
|
+
export function TestOutput(props: {
|
|
15
|
+
children?: Children;
|
|
16
|
+
externals?: SymbolCreator[];
|
|
17
|
+
namePolicy?: NamePolicy<string>;
|
|
18
|
+
path?: string;
|
|
19
|
+
}) {
|
|
20
|
+
return (
|
|
92
21
|
<Output
|
|
93
|
-
externals={
|
|
94
|
-
namePolicy={
|
|
22
|
+
externals={props.externals}
|
|
23
|
+
namePolicy={props.namePolicy ?? createPythonNamePolicy()}
|
|
95
24
|
nameConflictResolver={pythonNameConflictResolver}
|
|
96
25
|
>
|
|
97
|
-
{
|
|
26
|
+
<py.SourceFile path={props.path ?? "test.py"} printWidth={80}>
|
|
27
|
+
{props.children}
|
|
28
|
+
</py.SourceFile>
|
|
98
29
|
</Output>
|
|
99
30
|
);
|
|
100
|
-
return render(content, printOptions);
|
|
101
31
|
}
|
|
102
32
|
|
|
103
|
-
export function
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
): string {
|
|
118
|
-
// If content is an array, wrap it in a default SourceFile
|
|
119
|
-
const sourceFile =
|
|
120
|
-
Array.isArray(content) ?
|
|
121
|
-
<py.SourceFile path={path}>{content}</py.SourceFile>
|
|
122
|
-
: content;
|
|
123
|
-
|
|
124
|
-
const res = toSourceTextMultiple([sourceFile], {
|
|
125
|
-
policy,
|
|
126
|
-
externals,
|
|
127
|
-
options,
|
|
128
|
-
printOptions,
|
|
129
|
-
});
|
|
130
|
-
return findFile(res, path).contents;
|
|
33
|
+
export function TestOutputDirectory(props: {
|
|
34
|
+
children: Children;
|
|
35
|
+
externals?: SymbolCreator[];
|
|
36
|
+
namePolicy?: NamePolicy<string>;
|
|
37
|
+
}) {
|
|
38
|
+
return (
|
|
39
|
+
<Output
|
|
40
|
+
externals={props.externals}
|
|
41
|
+
namePolicy={props.namePolicy ?? createPythonNamePolicy()}
|
|
42
|
+
nameConflictResolver={pythonNameConflictResolver}
|
|
43
|
+
>
|
|
44
|
+
{props.children}
|
|
45
|
+
</Output>
|
|
46
|
+
);
|
|
131
47
|
}
|
|
132
48
|
|
|
133
49
|
// Helper function to create a PythonModuleScope to be used in tests
|
package/test/values.test.tsx
CHANGED
|
@@ -1,82 +1,126 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import * as py from "../src/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { TestOutput } from "./utils.js";
|
|
4
4
|
|
|
5
5
|
describe("Atom", () => {
|
|
6
6
|
it("renders string value", () => {
|
|
7
|
-
expect(
|
|
7
|
+
expect(
|
|
8
|
+
<TestOutput>
|
|
9
|
+
<py.Atom jsValue={"Test"} />
|
|
10
|
+
</TestOutput>,
|
|
11
|
+
).toRenderTo('"Test"');
|
|
8
12
|
});
|
|
9
13
|
|
|
10
14
|
it("renders null/undefined object", () => {
|
|
11
|
-
expect(
|
|
15
|
+
expect(
|
|
16
|
+
<TestOutput>
|
|
17
|
+
<py.Atom jsValue={undefined} />
|
|
18
|
+
</TestOutput>,
|
|
19
|
+
).toRenderTo("None");
|
|
12
20
|
});
|
|
13
21
|
|
|
14
22
|
it("renders number", () => {
|
|
15
|
-
expect(
|
|
23
|
+
expect(
|
|
24
|
+
<TestOutput>
|
|
25
|
+
<py.Atom jsValue={123} />
|
|
26
|
+
</TestOutput>,
|
|
27
|
+
).toRenderTo("123");
|
|
16
28
|
});
|
|
17
29
|
|
|
18
30
|
it("renders floating point number", () => {
|
|
19
|
-
expect(
|
|
31
|
+
expect(
|
|
32
|
+
<TestOutput>
|
|
33
|
+
<py.Atom jsValue={123.456} />
|
|
34
|
+
</TestOutput>,
|
|
35
|
+
).toRenderTo("123.456");
|
|
20
36
|
});
|
|
21
37
|
|
|
22
38
|
it("renders floating point number when hinted", () => {
|
|
23
|
-
expect(
|
|
24
|
-
|
|
25
|
-
|
|
39
|
+
expect(
|
|
40
|
+
<TestOutput>
|
|
41
|
+
<py.Atom jsValue={123.456} asFloat />
|
|
42
|
+
</TestOutput>,
|
|
43
|
+
).toRenderTo("123.456");
|
|
26
44
|
});
|
|
27
45
|
|
|
28
46
|
it("renders floating point number with decimal point zero when hinted", () => {
|
|
29
|
-
expect(
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
expect(
|
|
48
|
+
<TestOutput>
|
|
49
|
+
<py.Atom jsValue={123.0} asFloat />
|
|
50
|
+
</TestOutput>,
|
|
51
|
+
).toRenderTo("123.0");
|
|
32
52
|
});
|
|
33
53
|
|
|
34
54
|
it("renders integer as float when hinted", () => {
|
|
35
|
-
expect(
|
|
36
|
-
|
|
37
|
-
|
|
55
|
+
expect(
|
|
56
|
+
<TestOutput>
|
|
57
|
+
<py.Atom jsValue={123} asFloat />
|
|
58
|
+
</TestOutput>,
|
|
59
|
+
).toRenderTo("123.0");
|
|
38
60
|
});
|
|
39
61
|
|
|
40
62
|
it("renders small positive float when hinted", () => {
|
|
41
|
-
expect(
|
|
42
|
-
|
|
43
|
-
|
|
63
|
+
expect(
|
|
64
|
+
<TestOutput>
|
|
65
|
+
<py.Atom jsValue={0.07} asFloat />
|
|
66
|
+
</TestOutput>,
|
|
67
|
+
).toRenderTo("0.07");
|
|
44
68
|
});
|
|
45
69
|
|
|
46
70
|
it("renders large positive numbers as float when hinted", () => {
|
|
47
|
-
expect(
|
|
48
|
-
|
|
49
|
-
|
|
71
|
+
expect(
|
|
72
|
+
<TestOutput>
|
|
73
|
+
<py.Atom jsValue={2 ** 64} asFloat />
|
|
74
|
+
</TestOutput>,
|
|
75
|
+
).toRenderTo("18446744073709551616.0");
|
|
50
76
|
});
|
|
51
77
|
|
|
52
78
|
it("renders boolean - True", () => {
|
|
53
|
-
expect(
|
|
79
|
+
expect(
|
|
80
|
+
<TestOutput>
|
|
81
|
+
<py.Atom jsValue={true} />
|
|
82
|
+
</TestOutput>,
|
|
83
|
+
).toRenderTo("True");
|
|
54
84
|
});
|
|
55
85
|
|
|
56
86
|
it("renders boolean - False", () => {
|
|
57
|
-
expect(
|
|
87
|
+
expect(
|
|
88
|
+
<TestOutput>
|
|
89
|
+
<py.Atom jsValue={false} />
|
|
90
|
+
</TestOutput>,
|
|
91
|
+
).toRenderTo("False");
|
|
58
92
|
});
|
|
59
93
|
|
|
60
94
|
it("renders array", () => {
|
|
61
|
-
expect(
|
|
62
|
-
|
|
63
|
-
|
|
95
|
+
expect(
|
|
96
|
+
<TestOutput>
|
|
97
|
+
<py.Atom jsValue={[1, 2, 3]} />
|
|
98
|
+
</TestOutput>,
|
|
99
|
+
).toRenderTo("[1, 2, 3]");
|
|
64
100
|
});
|
|
65
101
|
|
|
66
102
|
it("renders object", () => {
|
|
67
|
-
expect(
|
|
68
|
-
|
|
69
|
-
|
|
103
|
+
expect(
|
|
104
|
+
<TestOutput>
|
|
105
|
+
<py.Atom jsValue={{ a: 1, b: 2 }} />
|
|
106
|
+
</TestOutput>,
|
|
107
|
+
).toRenderTo('{"a": 1, "b": 2}');
|
|
70
108
|
});
|
|
71
109
|
|
|
72
110
|
it("renders more complex object", () => {
|
|
73
111
|
expect(
|
|
74
|
-
|
|
112
|
+
<TestOutput>
|
|
113
|
+
<py.Atom jsValue={{ a: "1", b: 2, c: true }} />
|
|
114
|
+
</TestOutput>,
|
|
75
115
|
).toRenderTo('{"a": "1", "b": 2, "c": True}');
|
|
76
116
|
});
|
|
77
117
|
|
|
78
118
|
it("renders empty object", () => {
|
|
79
|
-
expect(
|
|
119
|
+
expect(
|
|
120
|
+
<TestOutput>
|
|
121
|
+
<py.Atom jsValue={{}} />
|
|
122
|
+
</TestOutput>,
|
|
123
|
+
).toRenderTo("{}");
|
|
80
124
|
});
|
|
81
125
|
|
|
82
126
|
it("renders function", () => {
|
|
@@ -84,12 +128,18 @@ describe("Atom", () => {
|
|
|
84
128
|
return <>Test</>;
|
|
85
129
|
}
|
|
86
130
|
|
|
87
|
-
expect(
|
|
131
|
+
expect(
|
|
132
|
+
<TestOutput>
|
|
133
|
+
<py.Atom jsValue={Test} />
|
|
134
|
+
</TestOutput>,
|
|
135
|
+
).toRenderTo("Test");
|
|
88
136
|
});
|
|
89
137
|
|
|
90
138
|
it("renders nested object", () => {
|
|
91
139
|
expect(
|
|
92
|
-
|
|
140
|
+
<TestOutput>
|
|
141
|
+
<py.Atom jsValue={{ a: { b: { c: 1 } }, d: 2 }} />
|
|
142
|
+
</TestOutput>,
|
|
93
143
|
).toRenderTo('{"a": {"b": {"c": 1}}, "d": 2}');
|
|
94
144
|
});
|
|
95
145
|
});
|