@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,101 +1,102 @@
|
|
|
1
1
|
import { Prose } from "@alloy-js/core";
|
|
2
|
-
import { d } from "@alloy-js/core/testing";
|
|
3
2
|
import { expect, it } from "vitest";
|
|
4
3
|
import * as py from "../src/index.js";
|
|
5
4
|
import { dataclassesModule } from "../src/index.js";
|
|
6
|
-
import {
|
|
5
|
+
import { TestOutput, TestOutputDirectory } from "./utils.jsx";
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* TestOutputDirectory wraps content in an Output component without a default
|
|
9
|
+
* SourceFile, so SourceFile components with their own path/props can be used.
|
|
11
10
|
*/
|
|
12
11
|
it("renders an empty source file", () => {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
expect(<TestOutput></TestOutput>).toRenderTo(
|
|
13
|
+
`
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
`,
|
|
16
|
+
);
|
|
18
17
|
});
|
|
19
18
|
|
|
20
19
|
it("correct formatting of source file", () => {
|
|
21
|
-
|
|
22
|
-
<
|
|
23
|
-
<py.
|
|
24
|
-
<py.
|
|
25
|
-
<py.
|
|
26
|
-
<py.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<py.MemberExpression
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
<py.
|
|
64
|
-
<py.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
<py.MemberExpression
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
<py.
|
|
89
|
-
<py.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
<py.MemberExpression
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
20
|
+
expect(
|
|
21
|
+
<TestOutput>
|
|
22
|
+
<py.ClassDeclaration name="someClass">
|
|
23
|
+
<py.StatementList>
|
|
24
|
+
<py.FunctionDeclaration name="someMethod" returnType="str">
|
|
25
|
+
<py.StatementList>
|
|
26
|
+
<py.VariableDeclaration
|
|
27
|
+
name="x"
|
|
28
|
+
type="int"
|
|
29
|
+
initializer={<py.Atom jsValue={42} />}
|
|
30
|
+
/>
|
|
31
|
+
<py.VariableDeclaration
|
|
32
|
+
name="y"
|
|
33
|
+
type="int"
|
|
34
|
+
initializer={<py.Atom jsValue={42} />}
|
|
35
|
+
/>
|
|
36
|
+
<py.FunctionCallExpression target="foo" args={["a", "b"]} />
|
|
37
|
+
<py.MemberExpression>
|
|
38
|
+
<py.MemberExpression.Part id="a" />
|
|
39
|
+
<py.MemberExpression.Part id="b" />
|
|
40
|
+
<py.MemberExpression.Part key={"special-prop"} />
|
|
41
|
+
</py.MemberExpression>
|
|
42
|
+
<py.VariableDeclaration
|
|
43
|
+
name="z"
|
|
44
|
+
type="int"
|
|
45
|
+
initializer={<py.Atom jsValue={42} />}
|
|
46
|
+
/>
|
|
47
|
+
</py.StatementList>
|
|
48
|
+
</py.FunctionDeclaration>
|
|
49
|
+
<py.VariableDeclaration
|
|
50
|
+
name="someVar"
|
|
51
|
+
type="int"
|
|
52
|
+
initializer={<py.Atom jsValue={42} />}
|
|
53
|
+
/>
|
|
54
|
+
<py.FunctionDeclaration name="someOtherMethod" returnType="str" />
|
|
55
|
+
<py.VariableDeclaration
|
|
56
|
+
name="someOtherVar"
|
|
57
|
+
type="int"
|
|
58
|
+
initializer={<py.Atom jsValue={42} />}
|
|
59
|
+
/>
|
|
60
|
+
</py.StatementList>
|
|
61
|
+
</py.ClassDeclaration>
|
|
62
|
+
<py.FunctionDeclaration name="someFunction">
|
|
63
|
+
<py.StatementList>
|
|
64
|
+
<py.VariableDeclaration
|
|
65
|
+
name="x"
|
|
66
|
+
type="int"
|
|
67
|
+
initializer={<py.Atom jsValue={42} />}
|
|
68
|
+
/>
|
|
69
|
+
<py.VariableDeclaration
|
|
70
|
+
name="y"
|
|
71
|
+
type="int"
|
|
72
|
+
initializer={<py.Atom jsValue={42} />}
|
|
73
|
+
/>
|
|
74
|
+
<py.FunctionCallExpression target="foo" args={["a", "b"]} />
|
|
75
|
+
<py.MemberExpression>
|
|
76
|
+
<py.MemberExpression.Part id="a" />
|
|
77
|
+
<py.MemberExpression.Part id="b" />
|
|
78
|
+
<py.MemberExpression.Part key={"special-prop"} />
|
|
79
|
+
</py.MemberExpression>
|
|
80
|
+
<py.VariableDeclaration
|
|
81
|
+
name="z"
|
|
82
|
+
type="int"
|
|
83
|
+
initializer={<py.Atom jsValue={42} />}
|
|
84
|
+
/>
|
|
85
|
+
</py.StatementList>
|
|
86
|
+
</py.FunctionDeclaration>
|
|
87
|
+
<py.ClassDeclaration name="someOtherClass">
|
|
88
|
+
<py.StatementList>
|
|
89
|
+
<py.FunctionDeclaration name="someMethod" returnType="str" />
|
|
90
|
+
</py.StatementList>
|
|
91
|
+
</py.ClassDeclaration>
|
|
92
|
+
<py.MemberExpression>
|
|
93
|
+
<py.MemberExpression.Part id="a" />
|
|
94
|
+
<py.MemberExpression.Part id="b" />
|
|
95
|
+
<py.MemberExpression.Part key={"special-prop"} />
|
|
96
|
+
</py.MemberExpression>
|
|
97
|
+
</TestOutput>,
|
|
98
|
+
).toRenderTo(
|
|
99
|
+
`
|
|
99
100
|
class SomeClass:
|
|
100
101
|
def some_method() -> str:
|
|
101
102
|
x: int = 42
|
|
@@ -126,8 +127,8 @@ it("correct formatting of source file", () => {
|
|
|
126
127
|
|
|
127
128
|
|
|
128
129
|
a.b["special-prop"]
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
`,
|
|
131
|
+
);
|
|
131
132
|
});
|
|
132
133
|
|
|
133
134
|
it("renders module documentation correctly", () => {
|
|
@@ -156,15 +157,18 @@ it("renders module documentation correctly", () => {
|
|
|
156
157
|
/>
|
|
157
158
|
);
|
|
158
159
|
|
|
159
|
-
|
|
160
|
-
<
|
|
161
|
-
<py.
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
160
|
+
expect(
|
|
161
|
+
<TestOutputDirectory>
|
|
162
|
+
<py.SourceFile path="test.py" doc={moduleDoc}>
|
|
163
|
+
<py.VariableDeclaration name="DEFAULT_TIMEOUT" initializer={30} />
|
|
164
|
+
<py.VariableDeclaration name="MAX_RETRIES" initializer={3} />
|
|
165
|
+
<py.FunctionDeclaration name="process_data">
|
|
166
|
+
pass
|
|
167
|
+
</py.FunctionDeclaration>
|
|
168
|
+
</py.SourceFile>
|
|
169
|
+
</TestOutputDirectory>,
|
|
170
|
+
).toRenderTo({
|
|
171
|
+
"test.py": `
|
|
168
172
|
"""
|
|
169
173
|
This module provides utility functions for data processing. It includes
|
|
170
174
|
functions for validation, transformation, and analysis.
|
|
@@ -186,50 +190,52 @@ it("renders module documentation correctly", () => {
|
|
|
186
190
|
def process_data():
|
|
187
191
|
pass
|
|
188
192
|
|
|
189
|
-
|
|
190
|
-
|
|
193
|
+
`,
|
|
194
|
+
});
|
|
191
195
|
});
|
|
192
196
|
|
|
193
197
|
it("renders source file without documentation correctly", () => {
|
|
194
|
-
|
|
195
|
-
<
|
|
196
|
-
<py.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
198
|
+
expect(
|
|
199
|
+
<TestOutputDirectory>
|
|
200
|
+
<py.SourceFile path="test.py">
|
|
201
|
+
<py.FunctionDeclaration name="hello_world">
|
|
202
|
+
print("Hello, World!")
|
|
203
|
+
</py.FunctionDeclaration>
|
|
204
|
+
</py.SourceFile>
|
|
205
|
+
</TestOutputDirectory>,
|
|
206
|
+
).toRenderTo({
|
|
207
|
+
"test.py": `
|
|
203
208
|
def hello_world():
|
|
204
209
|
print("Hello, World!")
|
|
205
210
|
|
|
206
|
-
|
|
207
|
-
|
|
211
|
+
`,
|
|
212
|
+
});
|
|
208
213
|
});
|
|
209
214
|
|
|
210
215
|
it("nothing before top-level definition", () => {
|
|
211
|
-
|
|
212
|
-
<
|
|
213
|
-
<py.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
expect(
|
|
217
|
+
<TestOutputDirectory>
|
|
218
|
+
<py.SourceFile path="test.py">
|
|
219
|
+
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
220
|
+
</py.SourceFile>
|
|
221
|
+
</TestOutputDirectory>,
|
|
222
|
+
).toRenderTo({
|
|
223
|
+
"test.py": `
|
|
218
224
|
def hello():
|
|
219
225
|
pass
|
|
220
226
|
|
|
221
|
-
|
|
222
|
-
|
|
227
|
+
`,
|
|
228
|
+
});
|
|
223
229
|
});
|
|
224
230
|
|
|
225
231
|
it("nothing before non-definition", () => {
|
|
226
|
-
|
|
227
|
-
<
|
|
228
|
-
<py.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
232
|
+
expect(
|
|
233
|
+
<TestOutputDirectory>
|
|
234
|
+
<py.SourceFile path="test.py">
|
|
235
|
+
<py.VariableDeclaration name="x" initializer={42} />
|
|
236
|
+
</py.SourceFile>
|
|
237
|
+
</TestOutputDirectory>,
|
|
238
|
+
).toRenderTo({ "test.py": "x = 42" });
|
|
233
239
|
});
|
|
234
240
|
|
|
235
241
|
it("only doc before definition", () => {
|
|
@@ -237,13 +243,14 @@ it("only doc before definition", () => {
|
|
|
237
243
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
238
244
|
);
|
|
239
245
|
|
|
240
|
-
|
|
241
|
-
<
|
|
242
|
-
<py.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
246
|
+
expect(
|
|
247
|
+
<TestOutputDirectory>
|
|
248
|
+
<py.SourceFile path="test.py" doc={moduleDoc}>
|
|
249
|
+
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
250
|
+
</py.SourceFile>
|
|
251
|
+
</TestOutputDirectory>,
|
|
252
|
+
).toRenderTo({
|
|
253
|
+
"test.py": `
|
|
247
254
|
"""
|
|
248
255
|
Module description.
|
|
249
256
|
"""
|
|
@@ -252,8 +259,8 @@ it("only doc before definition", () => {
|
|
|
252
259
|
def hello():
|
|
253
260
|
pass
|
|
254
261
|
|
|
255
|
-
|
|
256
|
-
|
|
262
|
+
`,
|
|
263
|
+
});
|
|
257
264
|
});
|
|
258
265
|
|
|
259
266
|
it("only doc before non-definition", () => {
|
|
@@ -261,101 +268,107 @@ it("only doc before non-definition", () => {
|
|
|
261
268
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
262
269
|
);
|
|
263
270
|
|
|
264
|
-
|
|
265
|
-
<
|
|
266
|
-
<py.
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
+
expect(
|
|
272
|
+
<TestOutputDirectory>
|
|
273
|
+
<py.SourceFile path="test.py" doc={moduleDoc}>
|
|
274
|
+
<py.VariableDeclaration name="x" initializer={42} />
|
|
275
|
+
</py.SourceFile>
|
|
276
|
+
</TestOutputDirectory>,
|
|
277
|
+
).toRenderTo({
|
|
278
|
+
"test.py": `
|
|
271
279
|
"""
|
|
272
280
|
Module description.
|
|
273
281
|
"""
|
|
274
282
|
|
|
275
|
-
x = 42
|
|
283
|
+
x = 42`,
|
|
284
|
+
});
|
|
276
285
|
});
|
|
277
286
|
|
|
278
287
|
it("only header before definition", () => {
|
|
279
|
-
|
|
280
|
-
<
|
|
281
|
-
<py.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
288
|
+
expect(
|
|
289
|
+
<TestOutputDirectory>
|
|
290
|
+
<py.SourceFile path="test.py" header="#!/usr/bin/env python3">
|
|
291
|
+
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
292
|
+
</py.SourceFile>
|
|
293
|
+
</TestOutputDirectory>,
|
|
294
|
+
).toRenderTo({
|
|
295
|
+
"test.py": `
|
|
287
296
|
#!/usr/bin/env python3
|
|
288
297
|
|
|
289
298
|
|
|
290
299
|
def hello():
|
|
291
300
|
pass
|
|
292
301
|
|
|
293
|
-
|
|
294
|
-
|
|
302
|
+
`,
|
|
303
|
+
});
|
|
295
304
|
});
|
|
296
305
|
|
|
297
306
|
it("only header before non-definition", () => {
|
|
298
|
-
|
|
299
|
-
<
|
|
300
|
-
<py.
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
307
|
+
expect(
|
|
308
|
+
<TestOutputDirectory>
|
|
309
|
+
<py.SourceFile path="test.py" header="#!/usr/bin/env python3">
|
|
310
|
+
<py.VariableDeclaration name="x" initializer={42} />
|
|
311
|
+
</py.SourceFile>
|
|
312
|
+
</TestOutputDirectory>,
|
|
313
|
+
).toRenderTo({
|
|
314
|
+
"test.py": `
|
|
306
315
|
#!/usr/bin/env python3
|
|
307
316
|
|
|
308
|
-
x = 42
|
|
317
|
+
x = 42`,
|
|
318
|
+
});
|
|
309
319
|
});
|
|
310
320
|
|
|
311
321
|
it("only futureImports before definition", () => {
|
|
312
|
-
|
|
313
|
-
<
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
+
expect(
|
|
323
|
+
<TestOutputDirectory>
|
|
324
|
+
<py.SourceFile
|
|
325
|
+
path="test.py"
|
|
326
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
327
|
+
>
|
|
328
|
+
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
329
|
+
</py.SourceFile>
|
|
330
|
+
</TestOutputDirectory>,
|
|
331
|
+
).toRenderTo({
|
|
332
|
+
"test.py": `
|
|
322
333
|
from __future__ import annotations
|
|
323
334
|
|
|
324
335
|
|
|
325
336
|
def hello():
|
|
326
337
|
pass
|
|
327
338
|
|
|
328
|
-
|
|
329
|
-
|
|
339
|
+
`,
|
|
340
|
+
});
|
|
330
341
|
});
|
|
331
342
|
|
|
332
343
|
it("only futureImports before non-definition", () => {
|
|
333
|
-
|
|
334
|
-
<
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
344
|
+
expect(
|
|
345
|
+
<TestOutputDirectory>
|
|
346
|
+
<py.SourceFile
|
|
347
|
+
path="test.py"
|
|
348
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
349
|
+
>
|
|
350
|
+
<py.VariableDeclaration name="x" initializer={42} />
|
|
351
|
+
</py.SourceFile>
|
|
352
|
+
</TestOutputDirectory>,
|
|
353
|
+
).toRenderTo({
|
|
354
|
+
"test.py": `
|
|
343
355
|
from __future__ import annotations
|
|
344
356
|
|
|
345
|
-
x = 42
|
|
357
|
+
x = 42`,
|
|
358
|
+
});
|
|
346
359
|
});
|
|
347
360
|
|
|
348
361
|
it("only imports before definition", () => {
|
|
349
|
-
|
|
350
|
-
<
|
|
351
|
-
<py.
|
|
352
|
-
<py.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
.
|
|
362
|
+
expect(
|
|
363
|
+
<TestOutputDirectory externals={[dataclassesModule]}>
|
|
364
|
+
<py.SourceFile path="test.py">
|
|
365
|
+
<py.DataclassDeclaration name="User">
|
|
366
|
+
<py.VariableDeclaration name="name" type="str" />
|
|
367
|
+
</py.DataclassDeclaration>
|
|
368
|
+
</py.SourceFile>
|
|
369
|
+
</TestOutputDirectory>,
|
|
370
|
+
).toRenderTo({
|
|
371
|
+
"test.py": `
|
|
359
372
|
from dataclasses import dataclass
|
|
360
373
|
|
|
361
374
|
|
|
@@ -363,25 +376,28 @@ it("only imports before definition", () => {
|
|
|
363
376
|
class User:
|
|
364
377
|
name: str = None
|
|
365
378
|
|
|
366
|
-
|
|
367
|
-
|
|
379
|
+
`,
|
|
380
|
+
});
|
|
368
381
|
});
|
|
369
382
|
|
|
370
383
|
it("only imports before non-definition", () => {
|
|
371
|
-
|
|
372
|
-
<
|
|
373
|
-
<py.
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
384
|
+
expect(
|
|
385
|
+
<TestOutputDirectory externals={[dataclassesModule]}>
|
|
386
|
+
<py.SourceFile path="test.py">
|
|
387
|
+
<py.VariableDeclaration
|
|
388
|
+
name="x"
|
|
389
|
+
initializer={
|
|
390
|
+
<py.Reference refkey={dataclassesModule["."].dataclass} />
|
|
391
|
+
}
|
|
392
|
+
/>
|
|
393
|
+
</py.SourceFile>
|
|
394
|
+
</TestOutputDirectory>,
|
|
395
|
+
).toRenderTo({
|
|
396
|
+
"test.py": `
|
|
382
397
|
from dataclasses import dataclass
|
|
383
398
|
|
|
384
|
-
x = dataclass
|
|
399
|
+
x = dataclass`,
|
|
400
|
+
});
|
|
385
401
|
});
|
|
386
402
|
|
|
387
403
|
it("doc + futureImports before definition", () => {
|
|
@@ -389,17 +405,18 @@ it("doc + futureImports before definition", () => {
|
|
|
389
405
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
390
406
|
);
|
|
391
407
|
|
|
392
|
-
|
|
393
|
-
<
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
408
|
+
expect(
|
|
409
|
+
<TestOutputDirectory>
|
|
410
|
+
<py.SourceFile
|
|
411
|
+
path="test.py"
|
|
412
|
+
doc={moduleDoc}
|
|
413
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
414
|
+
>
|
|
415
|
+
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
416
|
+
</py.SourceFile>
|
|
417
|
+
</TestOutputDirectory>,
|
|
418
|
+
).toRenderTo({
|
|
419
|
+
"test.py": `
|
|
403
420
|
"""
|
|
404
421
|
Module description.
|
|
405
422
|
"""
|
|
@@ -410,8 +427,8 @@ it("doc + futureImports before definition", () => {
|
|
|
410
427
|
def hello():
|
|
411
428
|
pass
|
|
412
429
|
|
|
413
|
-
|
|
414
|
-
|
|
430
|
+
`,
|
|
431
|
+
});
|
|
415
432
|
});
|
|
416
433
|
|
|
417
434
|
it("doc + futureImports before non-definition", () => {
|
|
@@ -419,24 +436,26 @@ it("doc + futureImports before non-definition", () => {
|
|
|
419
436
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
420
437
|
);
|
|
421
438
|
|
|
422
|
-
|
|
423
|
-
<
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
439
|
+
expect(
|
|
440
|
+
<TestOutputDirectory>
|
|
441
|
+
<py.SourceFile
|
|
442
|
+
path="test.py"
|
|
443
|
+
doc={moduleDoc}
|
|
444
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
445
|
+
>
|
|
446
|
+
<py.VariableDeclaration name="x" initializer={42} />
|
|
447
|
+
</py.SourceFile>
|
|
448
|
+
</TestOutputDirectory>,
|
|
449
|
+
).toRenderTo({
|
|
450
|
+
"test.py": `
|
|
433
451
|
"""
|
|
434
452
|
Module description.
|
|
435
453
|
"""
|
|
436
454
|
|
|
437
455
|
from __future__ import annotations
|
|
438
456
|
|
|
439
|
-
x = 42
|
|
457
|
+
x = 42`,
|
|
458
|
+
});
|
|
440
459
|
});
|
|
441
460
|
|
|
442
461
|
it("doc + imports before definition", () => {
|
|
@@ -444,16 +463,16 @@ it("doc + imports before definition", () => {
|
|
|
444
463
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
445
464
|
);
|
|
446
465
|
|
|
447
|
-
|
|
448
|
-
<
|
|
449
|
-
<py.
|
|
450
|
-
<py.
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
.
|
|
466
|
+
expect(
|
|
467
|
+
<TestOutputDirectory externals={[dataclassesModule]}>
|
|
468
|
+
<py.SourceFile path="test.py" doc={moduleDoc}>
|
|
469
|
+
<py.DataclassDeclaration name="User">
|
|
470
|
+
<py.VariableDeclaration name="name" type="str" />
|
|
471
|
+
</py.DataclassDeclaration>
|
|
472
|
+
</py.SourceFile>
|
|
473
|
+
</TestOutputDirectory>,
|
|
474
|
+
).toRenderTo({
|
|
475
|
+
"test.py": `
|
|
457
476
|
"""
|
|
458
477
|
Module description.
|
|
459
478
|
"""
|
|
@@ -465,8 +484,8 @@ it("doc + imports before definition", () => {
|
|
|
465
484
|
class User:
|
|
466
485
|
name: str = None
|
|
467
486
|
|
|
468
|
-
|
|
469
|
-
|
|
487
|
+
`,
|
|
488
|
+
});
|
|
470
489
|
});
|
|
471
490
|
|
|
472
491
|
it("doc + imports before non-definition", () => {
|
|
@@ -474,40 +493,43 @@ it("doc + imports before non-definition", () => {
|
|
|
474
493
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
475
494
|
);
|
|
476
495
|
|
|
477
|
-
|
|
478
|
-
<
|
|
479
|
-
<py.
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
496
|
+
expect(
|
|
497
|
+
<TestOutputDirectory externals={[dataclassesModule]}>
|
|
498
|
+
<py.SourceFile path="test.py" doc={moduleDoc}>
|
|
499
|
+
<py.VariableDeclaration
|
|
500
|
+
name="x"
|
|
501
|
+
initializer={
|
|
502
|
+
<py.Reference refkey={dataclassesModule["."].dataclass} />
|
|
503
|
+
}
|
|
504
|
+
/>
|
|
505
|
+
</py.SourceFile>
|
|
506
|
+
</TestOutputDirectory>,
|
|
507
|
+
).toRenderTo({
|
|
508
|
+
"test.py": `
|
|
488
509
|
"""
|
|
489
510
|
Module description.
|
|
490
511
|
"""
|
|
491
512
|
|
|
492
513
|
from dataclasses import dataclass
|
|
493
514
|
|
|
494
|
-
x = dataclass
|
|
515
|
+
x = dataclass`,
|
|
516
|
+
});
|
|
495
517
|
});
|
|
496
518
|
|
|
497
519
|
it("futureImports + imports before definition", () => {
|
|
498
|
-
|
|
499
|
-
<
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
<py.
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
.
|
|
520
|
+
expect(
|
|
521
|
+
<TestOutputDirectory externals={[dataclassesModule]}>
|
|
522
|
+
<py.SourceFile
|
|
523
|
+
path="test.py"
|
|
524
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
525
|
+
>
|
|
526
|
+
<py.DataclassDeclaration name="User">
|
|
527
|
+
<py.VariableDeclaration name="name" type="str" />
|
|
528
|
+
</py.DataclassDeclaration>
|
|
529
|
+
</py.SourceFile>
|
|
530
|
+
</TestOutputDirectory>,
|
|
531
|
+
).toRenderTo({
|
|
532
|
+
"test.py": `
|
|
511
533
|
from __future__ import annotations
|
|
512
534
|
|
|
513
535
|
from dataclasses import dataclass
|
|
@@ -517,30 +539,33 @@ it("futureImports + imports before definition", () => {
|
|
|
517
539
|
class User:
|
|
518
540
|
name: str = None
|
|
519
541
|
|
|
520
|
-
|
|
521
|
-
|
|
542
|
+
`,
|
|
543
|
+
});
|
|
522
544
|
});
|
|
523
545
|
|
|
524
546
|
it("futureImports + imports before non-definition", () => {
|
|
525
|
-
|
|
526
|
-
<
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
547
|
+
expect(
|
|
548
|
+
<TestOutputDirectory externals={[dataclassesModule]}>
|
|
549
|
+
<py.SourceFile
|
|
550
|
+
path="test.py"
|
|
551
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
552
|
+
>
|
|
553
|
+
<py.VariableDeclaration
|
|
554
|
+
name="x"
|
|
555
|
+
initializer={
|
|
556
|
+
<py.Reference refkey={dataclassesModule["."].dataclass} />
|
|
557
|
+
}
|
|
558
|
+
/>
|
|
559
|
+
</py.SourceFile>
|
|
560
|
+
</TestOutputDirectory>,
|
|
561
|
+
).toRenderTo({
|
|
562
|
+
"test.py": `
|
|
539
563
|
from __future__ import annotations
|
|
540
564
|
|
|
541
565
|
from dataclasses import dataclass
|
|
542
566
|
|
|
543
|
-
x = dataclass
|
|
567
|
+
x = dataclass`,
|
|
568
|
+
});
|
|
544
569
|
});
|
|
545
570
|
|
|
546
571
|
it("doc + futureImports + imports before definition", () => {
|
|
@@ -548,20 +573,20 @@ it("doc + futureImports + imports before definition", () => {
|
|
|
548
573
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
549
574
|
);
|
|
550
575
|
|
|
551
|
-
|
|
552
|
-
<
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
<py.
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
.
|
|
576
|
+
expect(
|
|
577
|
+
<TestOutputDirectory externals={[dataclassesModule]}>
|
|
578
|
+
<py.SourceFile
|
|
579
|
+
path="test.py"
|
|
580
|
+
doc={moduleDoc}
|
|
581
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
582
|
+
>
|
|
583
|
+
<py.DataclassDeclaration name="User">
|
|
584
|
+
<py.VariableDeclaration name="name" type="str" />
|
|
585
|
+
</py.DataclassDeclaration>
|
|
586
|
+
</py.SourceFile>
|
|
587
|
+
</TestOutputDirectory>,
|
|
588
|
+
).toRenderTo({
|
|
589
|
+
"test.py": `
|
|
565
590
|
"""
|
|
566
591
|
Module description.
|
|
567
592
|
"""
|
|
@@ -575,8 +600,8 @@ it("doc + futureImports + imports before definition", () => {
|
|
|
575
600
|
class User:
|
|
576
601
|
name: str = None
|
|
577
602
|
|
|
578
|
-
|
|
579
|
-
|
|
603
|
+
`,
|
|
604
|
+
});
|
|
580
605
|
});
|
|
581
606
|
|
|
582
607
|
it("doc + futureImports + imports before non-definition", () => {
|
|
@@ -584,21 +609,23 @@ it("doc + futureImports + imports before non-definition", () => {
|
|
|
584
609
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
585
610
|
);
|
|
586
611
|
|
|
587
|
-
|
|
588
|
-
<
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
612
|
+
expect(
|
|
613
|
+
<TestOutputDirectory externals={[dataclassesModule]}>
|
|
614
|
+
<py.SourceFile
|
|
615
|
+
path="test.py"
|
|
616
|
+
doc={moduleDoc}
|
|
617
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
618
|
+
>
|
|
619
|
+
<py.VariableDeclaration
|
|
620
|
+
name="x"
|
|
621
|
+
initializer={
|
|
622
|
+
<py.Reference refkey={dataclassesModule["."].dataclass} />
|
|
623
|
+
}
|
|
624
|
+
/>
|
|
625
|
+
</py.SourceFile>
|
|
626
|
+
</TestOutputDirectory>,
|
|
627
|
+
).toRenderTo({
|
|
628
|
+
"test.py": `
|
|
602
629
|
"""
|
|
603
630
|
Module description.
|
|
604
631
|
"""
|
|
@@ -607,7 +634,8 @@ it("doc + futureImports + imports before non-definition", () => {
|
|
|
607
634
|
|
|
608
635
|
from dataclasses import dataclass
|
|
609
636
|
|
|
610
|
-
x = dataclass
|
|
637
|
+
x = dataclass`,
|
|
638
|
+
});
|
|
611
639
|
});
|
|
612
640
|
|
|
613
641
|
it("only doc in file (no children)", () => {
|
|
@@ -615,41 +643,44 @@ it("only doc in file (no children)", () => {
|
|
|
615
643
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
616
644
|
);
|
|
617
645
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
646
|
+
expect(
|
|
647
|
+
<TestOutputDirectory>
|
|
648
|
+
<py.SourceFile path="test.py" doc={moduleDoc} />
|
|
649
|
+
</TestOutputDirectory>,
|
|
650
|
+
).toRenderTo({
|
|
651
|
+
"test.py": `
|
|
621
652
|
"""
|
|
622
653
|
Module description.
|
|
623
654
|
"""
|
|
624
655
|
|
|
625
|
-
|
|
626
|
-
|
|
656
|
+
`,
|
|
657
|
+
});
|
|
627
658
|
});
|
|
628
659
|
|
|
629
660
|
it("only header in file (no children)", () => {
|
|
630
|
-
|
|
631
|
-
<
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
661
|
+
expect(
|
|
662
|
+
<TestOutputDirectory>
|
|
663
|
+
<py.SourceFile path="test.py" header="#!/usr/bin/env python3" />
|
|
664
|
+
</TestOutputDirectory>,
|
|
665
|
+
).toRenderTo({
|
|
666
|
+
"test.py": `
|
|
635
667
|
#!/usr/bin/env python3
|
|
636
668
|
|
|
637
|
-
|
|
638
|
-
|
|
669
|
+
`,
|
|
670
|
+
});
|
|
639
671
|
});
|
|
640
672
|
|
|
641
673
|
it("only futureImports in file (no children)", () => {
|
|
642
|
-
|
|
643
|
-
<
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
from __future__ import annotations
|
|
651
|
-
|
|
652
|
-
`);
|
|
674
|
+
expect(
|
|
675
|
+
<TestOutputDirectory>
|
|
676
|
+
<py.SourceFile
|
|
677
|
+
path="test.py"
|
|
678
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
679
|
+
/>
|
|
680
|
+
</TestOutputDirectory>,
|
|
681
|
+
).toRenderTo({
|
|
682
|
+
"test.py": "from __future__ import annotations",
|
|
683
|
+
});
|
|
653
684
|
});
|
|
654
685
|
|
|
655
686
|
it("doc + futureImports in file (no children)", () => {
|
|
@@ -657,55 +688,58 @@ it("doc + futureImports in file (no children)", () => {
|
|
|
657
688
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
658
689
|
);
|
|
659
690
|
|
|
660
|
-
|
|
661
|
-
<
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
691
|
+
expect(
|
|
692
|
+
<TestOutputDirectory>
|
|
693
|
+
<py.SourceFile
|
|
694
|
+
path="test.py"
|
|
695
|
+
doc={moduleDoc}
|
|
696
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
697
|
+
/>
|
|
698
|
+
</TestOutputDirectory>,
|
|
699
|
+
).toRenderTo({
|
|
700
|
+
"test.py": `
|
|
669
701
|
"""
|
|
670
702
|
Module description.
|
|
671
703
|
"""
|
|
672
704
|
|
|
673
705
|
from __future__ import annotations
|
|
674
|
-
|
|
675
|
-
|
|
706
|
+
`,
|
|
707
|
+
});
|
|
676
708
|
});
|
|
677
709
|
|
|
678
710
|
// headerComment tests
|
|
679
711
|
it("only headerComment before definition", () => {
|
|
680
|
-
|
|
681
|
-
<
|
|
682
|
-
<py.
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
712
|
+
expect(
|
|
713
|
+
<TestOutputDirectory>
|
|
714
|
+
<py.SourceFile path="test.py" headerComment="Copyright 2024 My Company">
|
|
715
|
+
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
716
|
+
</py.SourceFile>
|
|
717
|
+
</TestOutputDirectory>,
|
|
718
|
+
).toRenderTo({
|
|
719
|
+
"test.py": `
|
|
688
720
|
# Copyright 2024 My Company
|
|
689
721
|
|
|
690
722
|
|
|
691
723
|
def hello():
|
|
692
724
|
pass
|
|
693
725
|
|
|
694
|
-
|
|
695
|
-
|
|
726
|
+
`,
|
|
727
|
+
});
|
|
696
728
|
});
|
|
697
729
|
|
|
698
730
|
it("only headerComment before non-definition", () => {
|
|
699
|
-
|
|
700
|
-
<
|
|
701
|
-
<py.
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
731
|
+
expect(
|
|
732
|
+
<TestOutputDirectory>
|
|
733
|
+
<py.SourceFile path="test.py" headerComment="Copyright 2024 My Company">
|
|
734
|
+
<py.VariableDeclaration name="x" initializer={42} />
|
|
735
|
+
</py.SourceFile>
|
|
736
|
+
</TestOutputDirectory>,
|
|
737
|
+
).toRenderTo({
|
|
738
|
+
"test.py": `
|
|
706
739
|
# Copyright 2024 My Company
|
|
707
740
|
|
|
708
|
-
x = 42
|
|
741
|
+
x = 42`,
|
|
742
|
+
});
|
|
709
743
|
});
|
|
710
744
|
|
|
711
745
|
it("headerComment + doc before definition", () => {
|
|
@@ -713,18 +747,18 @@ it("headerComment + doc before definition", () => {
|
|
|
713
747
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
714
748
|
);
|
|
715
749
|
|
|
716
|
-
|
|
717
|
-
<
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
750
|
+
expect(
|
|
751
|
+
<TestOutputDirectory>
|
|
752
|
+
<py.SourceFile
|
|
753
|
+
path="test.py"
|
|
754
|
+
headerComment="Copyright 2024 My Company"
|
|
755
|
+
doc={moduleDoc}
|
|
756
|
+
>
|
|
757
|
+
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
758
|
+
</py.SourceFile>
|
|
759
|
+
</TestOutputDirectory>,
|
|
760
|
+
).toRenderTo({
|
|
761
|
+
"test.py": `
|
|
728
762
|
# Copyright 2024 My Company
|
|
729
763
|
"""
|
|
730
764
|
Module description.
|
|
@@ -734,23 +768,23 @@ it("headerComment + doc before definition", () => {
|
|
|
734
768
|
def hello():
|
|
735
769
|
pass
|
|
736
770
|
|
|
737
|
-
|
|
738
|
-
|
|
771
|
+
`,
|
|
772
|
+
});
|
|
739
773
|
});
|
|
740
774
|
|
|
741
775
|
it("headerComment + futureImports before definition", () => {
|
|
742
|
-
|
|
743
|
-
<
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
776
|
+
expect(
|
|
777
|
+
<TestOutputDirectory>
|
|
778
|
+
<py.SourceFile
|
|
779
|
+
path="test.py"
|
|
780
|
+
headerComment="Copyright 2024 My Company"
|
|
781
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
782
|
+
>
|
|
783
|
+
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
784
|
+
</py.SourceFile>
|
|
785
|
+
</TestOutputDirectory>,
|
|
786
|
+
).toRenderTo({
|
|
787
|
+
"test.py": `
|
|
754
788
|
# Copyright 2024 My Company
|
|
755
789
|
|
|
756
790
|
from __future__ import annotations
|
|
@@ -759,21 +793,21 @@ it("headerComment + futureImports before definition", () => {
|
|
|
759
793
|
def hello():
|
|
760
794
|
pass
|
|
761
795
|
|
|
762
|
-
|
|
763
|
-
|
|
796
|
+
`,
|
|
797
|
+
});
|
|
764
798
|
});
|
|
765
799
|
|
|
766
800
|
it("headerComment + imports before definition", () => {
|
|
767
|
-
|
|
768
|
-
<
|
|
769
|
-
<py.
|
|
770
|
-
<py.
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
.
|
|
801
|
+
expect(
|
|
802
|
+
<TestOutputDirectory externals={[dataclassesModule]}>
|
|
803
|
+
<py.SourceFile path="test.py" headerComment="Copyright 2024 My Company">
|
|
804
|
+
<py.DataclassDeclaration name="User">
|
|
805
|
+
<py.VariableDeclaration name="name" type="str" />
|
|
806
|
+
</py.DataclassDeclaration>
|
|
807
|
+
</py.SourceFile>
|
|
808
|
+
</TestOutputDirectory>,
|
|
809
|
+
).toRenderTo({
|
|
810
|
+
"test.py": `
|
|
777
811
|
# Copyright 2024 My Company
|
|
778
812
|
|
|
779
813
|
from dataclasses import dataclass
|
|
@@ -783,8 +817,8 @@ it("headerComment + imports before definition", () => {
|
|
|
783
817
|
class User:
|
|
784
818
|
name: str = None
|
|
785
819
|
|
|
786
|
-
|
|
787
|
-
|
|
820
|
+
`,
|
|
821
|
+
});
|
|
788
822
|
});
|
|
789
823
|
|
|
790
824
|
it("headerComment + doc + futureImports before definition", () => {
|
|
@@ -792,18 +826,19 @@ it("headerComment + doc + futureImports before definition", () => {
|
|
|
792
826
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
793
827
|
);
|
|
794
828
|
|
|
795
|
-
|
|
796
|
-
<
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
829
|
+
expect(
|
|
830
|
+
<TestOutputDirectory>
|
|
831
|
+
<py.SourceFile
|
|
832
|
+
path="test.py"
|
|
833
|
+
headerComment="Copyright 2024 My Company"
|
|
834
|
+
doc={moduleDoc}
|
|
835
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
836
|
+
>
|
|
837
|
+
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
838
|
+
</py.SourceFile>
|
|
839
|
+
</TestOutputDirectory>,
|
|
840
|
+
).toRenderTo({
|
|
841
|
+
"test.py": `
|
|
807
842
|
# Copyright 2024 My Company
|
|
808
843
|
"""
|
|
809
844
|
Module description.
|
|
@@ -815,8 +850,8 @@ it("headerComment + doc + futureImports before definition", () => {
|
|
|
815
850
|
def hello():
|
|
816
851
|
pass
|
|
817
852
|
|
|
818
|
-
|
|
819
|
-
|
|
853
|
+
`,
|
|
854
|
+
});
|
|
820
855
|
});
|
|
821
856
|
|
|
822
857
|
it("headerComment + doc + futureImports + imports before definition", () => {
|
|
@@ -824,21 +859,21 @@ it("headerComment + doc + futureImports + imports before definition", () => {
|
|
|
824
859
|
<py.ModuleDoc description={[<Prose>Module description.</Prose>]} />
|
|
825
860
|
);
|
|
826
861
|
|
|
827
|
-
|
|
828
|
-
<
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
<py.
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
.
|
|
862
|
+
expect(
|
|
863
|
+
<TestOutputDirectory externals={[dataclassesModule]}>
|
|
864
|
+
<py.SourceFile
|
|
865
|
+
path="test.py"
|
|
866
|
+
headerComment="Copyright 2024 My Company"
|
|
867
|
+
doc={moduleDoc}
|
|
868
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
869
|
+
>
|
|
870
|
+
<py.DataclassDeclaration name="User">
|
|
871
|
+
<py.VariableDeclaration name="name" type="str" />
|
|
872
|
+
</py.DataclassDeclaration>
|
|
873
|
+
</py.SourceFile>
|
|
874
|
+
</TestOutputDirectory>,
|
|
875
|
+
).toRenderTo({
|
|
876
|
+
"test.py": `
|
|
842
877
|
# Copyright 2024 My Company
|
|
843
878
|
"""
|
|
844
879
|
Module description.
|
|
@@ -853,34 +888,33 @@ it("headerComment + doc + futureImports + imports before definition", () => {
|
|
|
853
888
|
class User:
|
|
854
889
|
name: str = None
|
|
855
890
|
|
|
856
|
-
|
|
857
|
-
|
|
891
|
+
`,
|
|
892
|
+
});
|
|
858
893
|
});
|
|
859
894
|
|
|
860
895
|
it("only headerComment in file (no children)", () => {
|
|
861
|
-
|
|
862
|
-
<
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
# Copyright 2024 My Company
|
|
867
|
-
|
|
868
|
-
`);
|
|
896
|
+
expect(
|
|
897
|
+
<TestOutputDirectory>
|
|
898
|
+
<py.SourceFile path="test.py" headerComment="Copyright 2024 My Company" />
|
|
899
|
+
</TestOutputDirectory>,
|
|
900
|
+
).toRenderTo({
|
|
901
|
+
"test.py": "# Copyright 2024 My Company",
|
|
902
|
+
});
|
|
869
903
|
});
|
|
870
904
|
|
|
871
905
|
it("header + headerComment before definition", () => {
|
|
872
|
-
|
|
873
|
-
<
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
906
|
+
expect(
|
|
907
|
+
<TestOutputDirectory>
|
|
908
|
+
<py.SourceFile
|
|
909
|
+
path="test.py"
|
|
910
|
+
header="#!/usr/bin/env python3"
|
|
911
|
+
headerComment="Copyright 2024 My Company"
|
|
912
|
+
>
|
|
913
|
+
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
914
|
+
</py.SourceFile>
|
|
915
|
+
</TestOutputDirectory>,
|
|
916
|
+
).toRenderTo({
|
|
917
|
+
"test.py": `
|
|
884
918
|
#!/usr/bin/env python3
|
|
885
919
|
# Copyright 2024 My Company
|
|
886
920
|
|
|
@@ -888,23 +922,23 @@ it("header + headerComment before definition", () => {
|
|
|
888
922
|
def hello():
|
|
889
923
|
pass
|
|
890
924
|
|
|
891
|
-
|
|
892
|
-
|
|
925
|
+
`,
|
|
926
|
+
});
|
|
893
927
|
});
|
|
894
928
|
|
|
895
929
|
it("header + headerComment before class definition", () => {
|
|
896
|
-
|
|
897
|
-
<
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
930
|
+
expect(
|
|
931
|
+
<TestOutputDirectory>
|
|
932
|
+
<py.SourceFile
|
|
933
|
+
path="test.py"
|
|
934
|
+
header="#!/usr/bin/env python3"
|
|
935
|
+
headerComment="Copyright 2024 My Company"
|
|
936
|
+
>
|
|
937
|
+
<py.ClassDeclaration name="MyClass">pass</py.ClassDeclaration>
|
|
938
|
+
</py.SourceFile>
|
|
939
|
+
</TestOutputDirectory>,
|
|
940
|
+
).toRenderTo({
|
|
941
|
+
"test.py": `
|
|
908
942
|
#!/usr/bin/env python3
|
|
909
943
|
# Copyright 2024 My Company
|
|
910
944
|
|
|
@@ -912,25 +946,26 @@ it("header + headerComment before class definition", () => {
|
|
|
912
946
|
class MyClass:
|
|
913
947
|
pass
|
|
914
948
|
|
|
915
|
-
|
|
916
|
-
|
|
949
|
+
`,
|
|
950
|
+
});
|
|
917
951
|
});
|
|
918
952
|
|
|
919
953
|
it("header + headerComment before non-definition", () => {
|
|
920
|
-
|
|
921
|
-
<
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
954
|
+
expect(
|
|
955
|
+
<TestOutputDirectory>
|
|
956
|
+
<py.SourceFile
|
|
957
|
+
path="test.py"
|
|
958
|
+
header="#!/usr/bin/env python3"
|
|
959
|
+
headerComment="Copyright 2024 My Company"
|
|
960
|
+
>
|
|
961
|
+
<py.VariableDeclaration name="x" initializer={42} />
|
|
962
|
+
</py.SourceFile>
|
|
963
|
+
</TestOutputDirectory>,
|
|
964
|
+
).toRenderTo({
|
|
965
|
+
"test.py": `
|
|
932
966
|
#!/usr/bin/env python3
|
|
933
967
|
# Copyright 2024 My Company
|
|
934
968
|
|
|
935
|
-
x = 42
|
|
969
|
+
x = 42`,
|
|
970
|
+
});
|
|
936
971
|
});
|