@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
package/dist/test/pydocs.test.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { Prose } from "@alloy-js/core";
|
|
3
|
-
import { d } from "@alloy-js/core/testing";
|
|
4
3
|
import { describe, expect, it } from "vitest";
|
|
5
4
|
import { enumModule } from "../src/builtins/python.js";
|
|
6
5
|
import * as py from "../src/index.js";
|
|
7
|
-
import {
|
|
6
|
+
import { TestOutput, TestOutputDirectory } from "./utils.js";
|
|
8
7
|
describe("PyDoc", () => {
|
|
9
8
|
it("formats properly", () => {
|
|
10
|
-
|
|
9
|
+
expect(_$createComponent(TestOutput, {
|
|
11
10
|
get children() {
|
|
12
|
-
return
|
|
13
|
-
children
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
return _$createComponent(py.PyDoc, {
|
|
12
|
+
get children() {
|
|
13
|
+
return [_$createComponent(Prose, {
|
|
14
|
+
children: "This is an example of a long docstring that will be broken in lines. We will also render another paragraph after this one."
|
|
15
|
+
}), _$createComponent(Prose, {
|
|
16
|
+
children: "This is another paragraph, and there's a line break before it."
|
|
17
|
+
})];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
21
20
|
}
|
|
22
|
-
})
|
|
23
|
-
expect(res).toRenderTo(d`
|
|
21
|
+
})).toRenderTo(`
|
|
24
22
|
"""
|
|
25
23
|
This is an example of a long docstring
|
|
26
24
|
that will be broken in lines. We will
|
|
@@ -31,26 +29,27 @@ describe("PyDoc", () => {
|
|
|
31
29
|
line break before it.
|
|
32
30
|
"""
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
`, {
|
|
33
|
+
tabWidth: 4,
|
|
34
|
+
printWidth: 40
|
|
35
|
+
});
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
describe("PyDocExample", () => {
|
|
39
39
|
it("creates docstring with a code sample", () => {
|
|
40
|
-
|
|
40
|
+
expect(_$createComponent(TestOutput, {
|
|
41
41
|
get children() {
|
|
42
|
-
return
|
|
43
|
-
children
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
return _$createComponent(py.PyDoc, {
|
|
43
|
+
get children() {
|
|
44
|
+
return [_$createComponent(Prose, {
|
|
45
|
+
children: "This is an example of a docstring with a code sample."
|
|
46
|
+
}), _$createComponent(py.PyDocExample, {
|
|
47
|
+
children: "print(\"Hello world!\")"
|
|
48
|
+
})];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
51
|
}
|
|
52
|
-
})
|
|
53
|
-
expect(res).toRenderTo(d`
|
|
52
|
+
})).toRenderTo(`
|
|
54
53
|
"""
|
|
55
54
|
This is an example of a docstring with a
|
|
56
55
|
code sample.
|
|
@@ -58,26 +57,27 @@ describe("PyDocExample", () => {
|
|
|
58
57
|
>> print("Hello world!")
|
|
59
58
|
"""
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
`, {
|
|
61
|
+
tabWidth: 4,
|
|
62
|
+
printWidth: 40
|
|
63
|
+
});
|
|
63
64
|
});
|
|
64
65
|
it("creates docstring with more than one code sample", () => {
|
|
65
|
-
|
|
66
|
+
expect(_$createComponent(TestOutput, {
|
|
66
67
|
get children() {
|
|
67
|
-
return
|
|
68
|
-
children
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
return _$createComponent(py.PyDoc, {
|
|
69
|
+
get children() {
|
|
70
|
+
return [_$createComponent(Prose, {
|
|
71
|
+
children: "This is an example of a docstring with a code sample."
|
|
72
|
+
}), _$createComponent(py.PyDocExample, {
|
|
73
|
+
children: "print(\"Hello world!\")"
|
|
74
|
+
}), _$createComponent(py.PyDocExample, {
|
|
75
|
+
children: "print(\"Hello world again!\")"
|
|
76
|
+
})];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
78
79
|
}
|
|
79
|
-
})
|
|
80
|
-
expect(res).toRenderTo(d`
|
|
80
|
+
})).toRenderTo(`
|
|
81
81
|
"""
|
|
82
82
|
This is an example of a docstring with a
|
|
83
83
|
code sample.
|
|
@@ -87,24 +87,25 @@ describe("PyDocExample", () => {
|
|
|
87
87
|
>> print("Hello world again!")
|
|
88
88
|
"""
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
`, {
|
|
91
|
+
tabWidth: 4,
|
|
92
|
+
printWidth: 40
|
|
93
|
+
});
|
|
92
94
|
});
|
|
93
95
|
it("creates docstring with a multiline code sample", () => {
|
|
94
|
-
|
|
96
|
+
expect(_$createComponent(TestOutput, {
|
|
95
97
|
get children() {
|
|
96
|
-
return
|
|
97
|
-
children
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
return _$createComponent(py.PyDoc, {
|
|
99
|
+
get children() {
|
|
100
|
+
return [_$createComponent(Prose, {
|
|
101
|
+
children: "This is an example of a docstring with a code sample."
|
|
102
|
+
}), _$createComponent(py.PyDocExample, {
|
|
103
|
+
children: `print("Hello world!")\nx = "Hello"\nprint(x)`
|
|
104
|
+
})];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
105
107
|
}
|
|
106
|
-
})
|
|
107
|
-
expect(res).toRenderTo(d`
|
|
108
|
+
})).toRenderTo(`
|
|
108
109
|
"""
|
|
109
110
|
This is an example of a docstring with a
|
|
110
111
|
code sample.
|
|
@@ -114,74 +115,85 @@ describe("PyDocExample", () => {
|
|
|
114
115
|
>> print(x)
|
|
115
116
|
"""
|
|
116
117
|
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
`, {
|
|
119
|
+
tabWidth: 4,
|
|
120
|
+
printWidth: 40
|
|
121
|
+
});
|
|
119
122
|
});
|
|
120
123
|
});
|
|
121
124
|
describe("SimpleCommentBlock", () => {
|
|
122
125
|
it("renders simple comment block", () => {
|
|
123
|
-
|
|
124
|
-
children
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
expect(_$createComponent(TestOutput, {
|
|
127
|
+
get children() {
|
|
128
|
+
return _$createComponent(py.SimpleCommentBlock, {
|
|
129
|
+
children: "This is a simple comment block that spans multiple lines and should be split automatically."
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
})).toRenderTo(`
|
|
127
133
|
# This is a simple comment block that spans multiple lines and should be split
|
|
128
134
|
# automatically.
|
|
129
|
-
|
|
130
135
|
`);
|
|
131
136
|
});
|
|
132
137
|
it("renders comment block with line breaks", () => {
|
|
133
|
-
|
|
134
|
-
children
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
expect(_$createComponent(TestOutput, {
|
|
139
|
+
get children() {
|
|
140
|
+
return _$createComponent(py.SimpleCommentBlock, {
|
|
141
|
+
children: "First line of comment.\\nSecond line of comment."
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
})).toRenderTo(`
|
|
137
145
|
# First line of comment.
|
|
138
146
|
# Second line of comment.
|
|
139
|
-
|
|
140
147
|
`);
|
|
141
148
|
});
|
|
142
149
|
});
|
|
143
150
|
describe("SimpleInlineComment", () => {
|
|
144
151
|
it("renders inline comment", () => {
|
|
145
|
-
|
|
146
|
-
children
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
expect(_$createComponent(TestOutput, {
|
|
153
|
+
get children() {
|
|
154
|
+
return [["x = 42", _$createComponent(py.SimpleInlineComment, {
|
|
155
|
+
children: "This is an inline comment"
|
|
156
|
+
})]];
|
|
157
|
+
}
|
|
158
|
+
})).toRenderTo(`x = 42 # This is an inline comment`);
|
|
151
159
|
});
|
|
152
160
|
it("renders inline comment with complex text", () => {
|
|
153
|
-
|
|
154
|
-
children
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
161
|
+
expect(_$createComponent(TestOutput, {
|
|
162
|
+
get children() {
|
|
163
|
+
return [["result = calculate()", _$createComponent(py.SimpleInlineComment, {
|
|
164
|
+
children: "TODO: Add error handling here"
|
|
165
|
+
})]];
|
|
166
|
+
}
|
|
167
|
+
})).toRenderTo(`result = calculate() # TODO: Add error handling here`);
|
|
159
168
|
});
|
|
160
169
|
});
|
|
161
170
|
describe("New Documentation Components", () => {
|
|
162
171
|
it("ModuleDoc renders correctly", () => {
|
|
163
|
-
|
|
164
|
-
get
|
|
165
|
-
return
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
172
|
+
expect(_$createComponent(TestOutput, {
|
|
173
|
+
get children() {
|
|
174
|
+
return _$createComponent(py.ModuleDoc, {
|
|
175
|
+
get description() {
|
|
176
|
+
return [_$createComponent(Prose, {
|
|
177
|
+
children: "This module demonstrates documentation as specified by the Google Python Style Guide."
|
|
178
|
+
})];
|
|
179
|
+
},
|
|
180
|
+
attributes: [{
|
|
181
|
+
name: "module_level_variable1",
|
|
182
|
+
type: "int",
|
|
183
|
+
children: "Module level variables may be documented."
|
|
184
|
+
}],
|
|
185
|
+
get examples() {
|
|
186
|
+
return [_$createComponent(py.PyDocExample, {
|
|
187
|
+
children: "print(\"mod\")"
|
|
188
|
+
})];
|
|
189
|
+
},
|
|
190
|
+
seeAlso: ["another_module.func", "RelatedClass"],
|
|
191
|
+
warning: "Internal API.",
|
|
192
|
+
deprecated: "Use new_module instead.",
|
|
193
|
+
todo: ["For module TODOs", "You have to also use sphinx.ext.todo extension"]
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
})).toRenderTo(`
|
|
185
197
|
"""
|
|
186
198
|
This module demonstrates documentation as specified by the Google Python Style
|
|
187
199
|
Guide.
|
|
@@ -207,28 +219,30 @@ describe("New Documentation Components", () => {
|
|
|
207
219
|
* You have to also use sphinx.ext.todo extension
|
|
208
220
|
"""
|
|
209
221
|
|
|
210
|
-
|
|
211
222
|
`);
|
|
212
223
|
});
|
|
213
224
|
it("PropertyDoc renders correctly", () => {
|
|
214
|
-
|
|
215
|
-
get
|
|
216
|
-
return
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
225
|
+
expect(_$createComponent(TestOutput, {
|
|
226
|
+
get children() {
|
|
227
|
+
return _$createComponent(py.PropertyDoc, {
|
|
228
|
+
get description() {
|
|
229
|
+
return [_$createComponent(Prose, {
|
|
230
|
+
children: "Properties should be documented in their getter method."
|
|
231
|
+
})];
|
|
232
|
+
},
|
|
233
|
+
returns: "str: The readonly property value.",
|
|
234
|
+
get examples() {
|
|
235
|
+
return [_$createComponent(py.PyDocExample, {
|
|
236
|
+
children: "print(obj.name)"
|
|
237
|
+
})];
|
|
238
|
+
},
|
|
239
|
+
seeAlso: ["other_property"],
|
|
240
|
+
warning: "Access may be slow.",
|
|
241
|
+
deprecated: "Use full_name instead.",
|
|
242
|
+
note: "If the setter method contains notable behavior, it should be mentioned here."
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
})).toRenderTo(`
|
|
232
246
|
"""
|
|
233
247
|
Properties should be documented in their getter method.
|
|
234
248
|
|
|
@@ -251,33 +265,35 @@ describe("New Documentation Components", () => {
|
|
|
251
265
|
If the setter method contains notable behavior, it should be mentioned here.
|
|
252
266
|
"""
|
|
253
267
|
|
|
254
|
-
|
|
255
268
|
`);
|
|
256
269
|
});
|
|
257
270
|
it("GeneratorDoc renders correctly", () => {
|
|
258
|
-
|
|
259
|
-
get
|
|
260
|
-
return
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
271
|
+
expect(_$createComponent(TestOutput, {
|
|
272
|
+
get children() {
|
|
273
|
+
return _$createComponent(py.GeneratorDoc, {
|
|
274
|
+
get description() {
|
|
275
|
+
return [_$createComponent(Prose, {
|
|
276
|
+
children: "Generators have a Yields section instead of a Returns section."
|
|
277
|
+
})];
|
|
278
|
+
},
|
|
279
|
+
parameters: [{
|
|
280
|
+
name: "n",
|
|
281
|
+
type: "int",
|
|
282
|
+
doc: "The upper limit of the range to generate, from 0 to n - 1."
|
|
283
|
+
}],
|
|
284
|
+
yields: "int: The next number in the range of 0 to n - 1.",
|
|
285
|
+
get examples() {
|
|
286
|
+
return [_$createComponent(py.PyDocExample, {
|
|
287
|
+
children: "print(next(gen))"
|
|
288
|
+
})];
|
|
289
|
+
},
|
|
290
|
+
seeAlso: ["make_generator"],
|
|
291
|
+
warning: "Do not consume in tight loops without sleep.",
|
|
292
|
+
deprecated: "Use new_generator instead.",
|
|
293
|
+
note: "Examples should be written in doctest format."
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
})).toRenderTo(`
|
|
281
297
|
"""
|
|
282
298
|
Generators have a Yields section instead of a Returns section.
|
|
283
299
|
|
|
@@ -303,40 +319,42 @@ describe("New Documentation Components", () => {
|
|
|
303
319
|
Examples should be written in doctest format.
|
|
304
320
|
"""
|
|
305
321
|
|
|
306
|
-
|
|
307
322
|
`);
|
|
308
323
|
});
|
|
309
324
|
it("ExceptionDoc renders correctly", () => {
|
|
310
|
-
|
|
311
|
-
get
|
|
312
|
-
return
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
325
|
+
expect(_$createComponent(TestOutput, {
|
|
326
|
+
get children() {
|
|
327
|
+
return _$createComponent(py.ExceptionDoc, {
|
|
328
|
+
get description() {
|
|
329
|
+
return [_$createComponent(Prose, {
|
|
330
|
+
children: "Exceptions are documented in the same way as classes."
|
|
331
|
+
})];
|
|
332
|
+
},
|
|
333
|
+
parameters: [{
|
|
334
|
+
name: "msg",
|
|
335
|
+
type: "str",
|
|
336
|
+
doc: "Human readable string describing the exception."
|
|
337
|
+
}, {
|
|
338
|
+
name: "code",
|
|
339
|
+
type: "int",
|
|
340
|
+
default: undefined,
|
|
341
|
+
doc: "Error code."
|
|
342
|
+
}],
|
|
343
|
+
attributes: [{
|
|
344
|
+
name: "msg",
|
|
345
|
+
type: "str",
|
|
346
|
+
children: "Human readable string describing the exception."
|
|
347
|
+
}, {
|
|
348
|
+
name: "code",
|
|
349
|
+
type: "int",
|
|
350
|
+
children: "Exception error code."
|
|
351
|
+
}],
|
|
352
|
+
seeAlso: ["BaseException"],
|
|
353
|
+
deprecated: "Use NewException instead.",
|
|
354
|
+
note: "Do not include the 'self' parameter in the Args section."
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
})).toRenderTo(`
|
|
340
358
|
"""
|
|
341
359
|
Exceptions are documented in the same way as classes.
|
|
342
360
|
|
|
@@ -360,27 +378,29 @@ describe("New Documentation Components", () => {
|
|
|
360
378
|
Do not include the 'self' parameter in the Args section.
|
|
361
379
|
"""
|
|
362
380
|
|
|
363
|
-
|
|
364
381
|
`);
|
|
365
382
|
});
|
|
366
383
|
it("MethodDoc renders correctly without default note", () => {
|
|
367
|
-
|
|
368
|
-
get
|
|
369
|
-
return
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
+
expect(_$createComponent(TestOutput, {
|
|
385
|
+
get children() {
|
|
386
|
+
return _$createComponent(py.MethodDoc, {
|
|
387
|
+
get description() {
|
|
388
|
+
return [_$createComponent(Prose, {
|
|
389
|
+
children: "Class methods are similar to regular functions."
|
|
390
|
+
})];
|
|
391
|
+
},
|
|
392
|
+
parameters: [{
|
|
393
|
+
name: "param1",
|
|
394
|
+
doc: "The first parameter."
|
|
395
|
+
}, {
|
|
396
|
+
name: "param2",
|
|
397
|
+
doc: "The second parameter."
|
|
398
|
+
}],
|
|
399
|
+
returns: "True if successful, False otherwise.",
|
|
400
|
+
overrides: "Base.method"
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
})).toRenderTo(`
|
|
384
404
|
"""
|
|
385
405
|
Class methods are similar to regular functions.
|
|
386
406
|
|
|
@@ -396,24 +416,26 @@ describe("New Documentation Components", () => {
|
|
|
396
416
|
Base.method
|
|
397
417
|
"""
|
|
398
418
|
|
|
399
|
-
|
|
400
419
|
`);
|
|
401
420
|
});
|
|
402
421
|
it("MethodDoc renders correctly with custom note", () => {
|
|
403
|
-
|
|
404
|
-
get
|
|
405
|
-
return
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
422
|
+
expect(_$createComponent(TestOutput, {
|
|
423
|
+
get children() {
|
|
424
|
+
return _$createComponent(py.MethodDoc, {
|
|
425
|
+
get description() {
|
|
426
|
+
return [_$createComponent(Prose, {
|
|
427
|
+
children: "Class methods are similar to regular functions."
|
|
428
|
+
})];
|
|
429
|
+
},
|
|
430
|
+
parameters: [{
|
|
431
|
+
name: "param1",
|
|
432
|
+
doc: "The first parameter."
|
|
433
|
+
}],
|
|
434
|
+
returns: "True if successful, False otherwise.",
|
|
435
|
+
note: "This method has special behavior when called multiple times."
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
})).toRenderTo(`
|
|
417
439
|
"""
|
|
418
440
|
Class methods are similar to regular functions.
|
|
419
441
|
|
|
@@ -427,35 +449,39 @@ describe("New Documentation Components", () => {
|
|
|
427
449
|
This method has special behavior when called multiple times.
|
|
428
450
|
"""
|
|
429
451
|
|
|
430
|
-
|
|
431
452
|
`);
|
|
432
453
|
});
|
|
433
454
|
it("ModuleDoc with minimal content", () => {
|
|
434
|
-
|
|
435
|
-
get
|
|
436
|
-
return
|
|
437
|
-
|
|
438
|
-
|
|
455
|
+
expect(_$createComponent(TestOutput, {
|
|
456
|
+
get children() {
|
|
457
|
+
return _$createComponent(py.ModuleDoc, {
|
|
458
|
+
get description() {
|
|
459
|
+
return [_$createComponent(Prose, {
|
|
460
|
+
children: "Simple module description."
|
|
461
|
+
})];
|
|
462
|
+
}
|
|
463
|
+
});
|
|
439
464
|
}
|
|
440
|
-
})
|
|
441
|
-
expect(res).toRenderTo(d`
|
|
465
|
+
})).toRenderTo(`
|
|
442
466
|
"""
|
|
443
467
|
Simple module description.
|
|
444
468
|
"""
|
|
445
469
|
|
|
446
|
-
|
|
447
470
|
`);
|
|
448
471
|
});
|
|
449
472
|
it("ModuleDoc with only todo items", () => {
|
|
450
|
-
|
|
451
|
-
get
|
|
452
|
-
return
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
473
|
+
expect(_$createComponent(TestOutput, {
|
|
474
|
+
get children() {
|
|
475
|
+
return _$createComponent(py.ModuleDoc, {
|
|
476
|
+
get description() {
|
|
477
|
+
return [_$createComponent(Prose, {
|
|
478
|
+
children: "Module with pending tasks."
|
|
479
|
+
})];
|
|
480
|
+
},
|
|
481
|
+
todo: ["Implement feature X", "Add more tests", "Update documentation"]
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
})).toRenderTo(`
|
|
459
485
|
"""
|
|
460
486
|
Module with pending tasks.
|
|
461
487
|
|
|
@@ -465,36 +491,40 @@ describe("New Documentation Components", () => {
|
|
|
465
491
|
* Update documentation
|
|
466
492
|
"""
|
|
467
493
|
|
|
468
|
-
|
|
469
494
|
`);
|
|
470
495
|
});
|
|
471
496
|
it("PropertyDoc minimal (description only)", () => {
|
|
472
|
-
|
|
473
|
-
get
|
|
474
|
-
return
|
|
475
|
-
|
|
476
|
-
|
|
497
|
+
expect(_$createComponent(TestOutput, {
|
|
498
|
+
get children() {
|
|
499
|
+
return _$createComponent(py.PropertyDoc, {
|
|
500
|
+
get description() {
|
|
501
|
+
return [_$createComponent(Prose, {
|
|
502
|
+
children: "A simple readonly property."
|
|
503
|
+
})];
|
|
504
|
+
}
|
|
505
|
+
});
|
|
477
506
|
}
|
|
478
|
-
})
|
|
479
|
-
expect(res).toRenderTo(d`
|
|
507
|
+
})).toRenderTo(`
|
|
480
508
|
"""
|
|
481
509
|
A simple readonly property.
|
|
482
510
|
"""
|
|
483
511
|
|
|
484
|
-
|
|
485
512
|
`);
|
|
486
513
|
});
|
|
487
514
|
it("PropertyDoc with getter and setter info", () => {
|
|
488
|
-
|
|
489
|
-
get
|
|
490
|
-
return
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
515
|
+
expect(_$createComponent(TestOutput, {
|
|
516
|
+
get children() {
|
|
517
|
+
return _$createComponent(py.PropertyDoc, {
|
|
518
|
+
get description() {
|
|
519
|
+
return [_$createComponent(Prose, {
|
|
520
|
+
children: "Properties with both a getter and setter should only be documented in their getter method."
|
|
521
|
+
})];
|
|
522
|
+
},
|
|
523
|
+
returns: ":obj:`list` of :obj:`str`: The property value.",
|
|
524
|
+
note: "If the setter method contains notable behavior, it should be mentioned here."
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
})).toRenderTo(`
|
|
498
528
|
"""
|
|
499
529
|
Properties with both a getter and setter should only be documented in their
|
|
500
530
|
getter method.
|
|
@@ -506,35 +536,37 @@ describe("New Documentation Components", () => {
|
|
|
506
536
|
If the setter method contains notable behavior, it should be mentioned here.
|
|
507
537
|
"""
|
|
508
538
|
|
|
509
|
-
|
|
510
539
|
`);
|
|
511
540
|
});
|
|
512
541
|
it("GeneratorDoc with complex parameters", () => {
|
|
513
|
-
|
|
514
|
-
get
|
|
515
|
-
return
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
542
|
+
expect(_$createComponent(TestOutput, {
|
|
543
|
+
get children() {
|
|
544
|
+
return _$createComponent(py.GeneratorDoc, {
|
|
545
|
+
get description() {
|
|
546
|
+
return [_$createComponent(Prose, {
|
|
547
|
+
children: "A more complex generator example with multiple parameters."
|
|
548
|
+
})];
|
|
549
|
+
},
|
|
550
|
+
parameters: [{
|
|
551
|
+
name: "start",
|
|
552
|
+
type: "int",
|
|
553
|
+
default: "0",
|
|
554
|
+
doc: "Starting value for the sequence."
|
|
555
|
+
}, {
|
|
556
|
+
name: "stop",
|
|
557
|
+
type: "int",
|
|
558
|
+
doc: "Ending value for the sequence (exclusive)."
|
|
559
|
+
}, {
|
|
560
|
+
name: "step",
|
|
561
|
+
type: "int",
|
|
562
|
+
default: "1",
|
|
563
|
+
doc: "Step size between values."
|
|
564
|
+
}],
|
|
565
|
+
yields: "int: The next number in the sequence.",
|
|
566
|
+
raises: ["ValueError: If step is zero.", "TypeError: If parameters are not integers."]
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
})).toRenderTo(`
|
|
538
570
|
"""
|
|
539
571
|
A more complex generator example with multiple parameters.
|
|
540
572
|
|
|
@@ -555,49 +587,51 @@ describe("New Documentation Components", () => {
|
|
|
555
587
|
TypeError: If parameters are not integers.
|
|
556
588
|
"""
|
|
557
589
|
|
|
558
|
-
|
|
559
590
|
`);
|
|
560
591
|
});
|
|
561
592
|
it("ExceptionDoc with comprehensive documentation", () => {
|
|
562
|
-
|
|
563
|
-
get
|
|
564
|
-
return
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
593
|
+
expect(_$createComponent(TestOutput, {
|
|
594
|
+
get children() {
|
|
595
|
+
return _$createComponent(py.ExceptionDoc, {
|
|
596
|
+
get description() {
|
|
597
|
+
return [_$createComponent(Prose, {
|
|
598
|
+
children: "A custom exception for authentication failures."
|
|
599
|
+
}), _$createComponent(Prose, {
|
|
600
|
+
children: "This exception is raised when authentication credentials are invalid or when authentication tokens have expired."
|
|
601
|
+
})];
|
|
602
|
+
},
|
|
603
|
+
parameters: [{
|
|
604
|
+
name: "message",
|
|
605
|
+
type: "str",
|
|
606
|
+
doc: "Human readable error message describing the authentication failure."
|
|
607
|
+
}, {
|
|
608
|
+
name: "error_code",
|
|
609
|
+
type: "int",
|
|
610
|
+
default: "401",
|
|
611
|
+
doc: "HTTP error code associated with the authentication failure."
|
|
612
|
+
}, {
|
|
613
|
+
name: "retry_after",
|
|
614
|
+
type: "int",
|
|
615
|
+
default: undefined,
|
|
616
|
+
doc: "Number of seconds to wait before retrying authentication."
|
|
617
|
+
}],
|
|
618
|
+
attributes: [{
|
|
619
|
+
name: "message",
|
|
620
|
+
type: "str",
|
|
621
|
+
children: "The error message."
|
|
622
|
+
}, {
|
|
623
|
+
name: "error_code",
|
|
624
|
+
type: "int",
|
|
625
|
+
children: "HTTP status code."
|
|
626
|
+
}, {
|
|
627
|
+
name: "retry_after",
|
|
628
|
+
type: "int",
|
|
629
|
+
children: "Retry delay in seconds, if applicable."
|
|
630
|
+
}],
|
|
631
|
+
note: "This exception should be caught and handled gracefully in production code."
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
})).toRenderTo(`
|
|
601
635
|
"""
|
|
602
636
|
A custom exception for authentication failures.
|
|
603
637
|
|
|
@@ -624,24 +658,26 @@ describe("New Documentation Components", () => {
|
|
|
624
658
|
This exception should be caught and handled gracefully in production code.
|
|
625
659
|
"""
|
|
626
660
|
|
|
627
|
-
|
|
628
661
|
`);
|
|
629
662
|
});
|
|
630
663
|
it("MethodDoc with raises but no returns", () => {
|
|
631
|
-
|
|
632
|
-
get
|
|
633
|
-
return
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
664
|
+
expect(_$createComponent(TestOutput, {
|
|
665
|
+
get children() {
|
|
666
|
+
return _$createComponent(py.MethodDoc, {
|
|
667
|
+
get description() {
|
|
668
|
+
return [_$createComponent(Prose, {
|
|
669
|
+
children: "A method that performs an action but doesn't return a value."
|
|
670
|
+
})];
|
|
671
|
+
},
|
|
672
|
+
parameters: [{
|
|
673
|
+
name: "data",
|
|
674
|
+
type: "bytes",
|
|
675
|
+
doc: "Raw data to process."
|
|
676
|
+
}],
|
|
677
|
+
raises: ["ValueError: If data is empty or invalid.", "IOError: If processing fails due to I/O issues."]
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
})).toRenderTo(`
|
|
645
681
|
"""
|
|
646
682
|
A method that performs an action but doesn't return a value.
|
|
647
683
|
|
|
@@ -655,20 +691,22 @@ describe("New Documentation Components", () => {
|
|
|
655
691
|
IOError: If processing fails due to I/O issues.
|
|
656
692
|
"""
|
|
657
693
|
|
|
658
|
-
|
|
659
694
|
`);
|
|
660
695
|
});
|
|
661
696
|
it("MethodDoc with no parameters", () => {
|
|
662
|
-
|
|
663
|
-
get
|
|
664
|
-
return
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
697
|
+
expect(_$createComponent(TestOutput, {
|
|
698
|
+
get children() {
|
|
699
|
+
return _$createComponent(py.MethodDoc, {
|
|
700
|
+
get description() {
|
|
701
|
+
return [_$createComponent(Prose, {
|
|
702
|
+
children: "A simple method with no parameters (except self)."
|
|
703
|
+
})];
|
|
704
|
+
},
|
|
705
|
+
returns: "bool: True if the operation was successful.",
|
|
706
|
+
note: "This is a parameterless method that only operates on instance state."
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
})).toRenderTo(`
|
|
672
710
|
"""
|
|
673
711
|
A simple method with no parameters (except self).
|
|
674
712
|
|
|
@@ -679,46 +717,50 @@ describe("New Documentation Components", () => {
|
|
|
679
717
|
This is a parameterless method that only operates on instance state.
|
|
680
718
|
"""
|
|
681
719
|
|
|
682
|
-
|
|
683
720
|
`);
|
|
684
721
|
});
|
|
685
722
|
it("AttributeDoc standalone usage", () => {
|
|
686
|
-
|
|
723
|
+
expect(_$createComponent(TestOutput, {
|
|
687
724
|
get children() {
|
|
688
|
-
return _$createComponent(py.
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
725
|
+
return _$createComponent(py.PyDoc, {
|
|
726
|
+
get children() {
|
|
727
|
+
return _$createComponent(py.AttributeDoc, {
|
|
728
|
+
name: "connection_timeout",
|
|
729
|
+
type: "float",
|
|
730
|
+
children: "Maximum time in seconds to wait for a connection to be established."
|
|
731
|
+
});
|
|
732
|
+
}
|
|
692
733
|
});
|
|
693
734
|
}
|
|
694
|
-
})
|
|
695
|
-
expect(res).toRenderTo(d`
|
|
735
|
+
})).toRenderTo(`
|
|
696
736
|
"""
|
|
697
737
|
connection_timeout (float): Maximum time in seconds to wait for a connection to
|
|
698
738
|
be established.
|
|
699
739
|
"""
|
|
700
740
|
|
|
701
|
-
|
|
702
741
|
`);
|
|
703
742
|
});
|
|
704
743
|
it("GeneratorDoc with examples in description", () => {
|
|
705
|
-
|
|
706
|
-
get
|
|
707
|
-
return
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
744
|
+
expect(_$createComponent(TestOutput, {
|
|
745
|
+
get children() {
|
|
746
|
+
return _$createComponent(py.GeneratorDoc, {
|
|
747
|
+
get description() {
|
|
748
|
+
return [_$createComponent(Prose, {
|
|
749
|
+
children: "Generators have a Yields section instead of a Returns section."
|
|
750
|
+
}), _$createComponent(py.PyDocExample, {
|
|
751
|
+
children: `print([i for i in example_generator(4)])\n[0, 1, 2, 3]`
|
|
752
|
+
})];
|
|
753
|
+
},
|
|
754
|
+
parameters: [{
|
|
755
|
+
name: "n",
|
|
756
|
+
type: "int",
|
|
757
|
+
doc: "The upper limit of the range to generate, from 0 to n - 1."
|
|
758
|
+
}],
|
|
759
|
+
yields: "int: The next number in the range of 0 to n - 1.",
|
|
760
|
+
note: "Examples should be written in doctest format, and should illustrate how to use the function."
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
})).toRenderTo(`
|
|
722
764
|
"""
|
|
723
765
|
Generators have a Yields section instead of a Returns section.
|
|
724
766
|
|
|
@@ -735,7 +777,6 @@ describe("New Documentation Components", () => {
|
|
|
735
777
|
Examples should be written in doctest format, and should illustrate how to use the function.
|
|
736
778
|
"""
|
|
737
779
|
|
|
738
|
-
|
|
739
780
|
`);
|
|
740
781
|
});
|
|
741
782
|
});
|
|
@@ -779,32 +820,30 @@ describe("Full example", () => {
|
|
|
779
820
|
note: "Do not include the 'self' parameter in the Args section.",
|
|
780
821
|
style: "google"
|
|
781
822
|
});
|
|
782
|
-
|
|
783
|
-
name: "A",
|
|
784
|
-
doc: doc,
|
|
823
|
+
expect(_$createComponent(TestOutput, {
|
|
785
824
|
get children() {
|
|
786
|
-
return _$createComponent(py.
|
|
825
|
+
return _$createComponent(py.ClassDeclaration, {
|
|
826
|
+
name: "A",
|
|
827
|
+
doc: doc,
|
|
787
828
|
get children() {
|
|
788
|
-
return
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
829
|
+
return _$createComponent(py.StatementList, {
|
|
830
|
+
get children() {
|
|
831
|
+
return [_$createComponent(py.VariableDeclaration, {
|
|
832
|
+
name: "just_name"
|
|
833
|
+
}), _$createComponent(py.VariableDeclaration, {
|
|
834
|
+
name: "name_and_type",
|
|
835
|
+
type: "int"
|
|
836
|
+
}), _$createComponent(py.VariableDeclaration, {
|
|
837
|
+
name: "name_type_and_value",
|
|
838
|
+
type: "int",
|
|
839
|
+
initializer: 12
|
|
840
|
+
})];
|
|
841
|
+
}
|
|
842
|
+
});
|
|
798
843
|
}
|
|
799
844
|
});
|
|
800
845
|
}
|
|
801
|
-
})
|
|
802
|
-
printOptions: {
|
|
803
|
-
printWidth: 80,
|
|
804
|
-
tabWidth: 4
|
|
805
|
-
}
|
|
806
|
-
});
|
|
807
|
-
expect(res).toRenderTo(d`
|
|
846
|
+
})).toRenderTo(`
|
|
808
847
|
class A:
|
|
809
848
|
"""
|
|
810
849
|
This is an example of a long docstring that will be broken in lines. We will
|
|
@@ -825,7 +864,7 @@ describe("Full example", () => {
|
|
|
825
864
|
nickname, or even a codename (e.g., 'Agent X'). It's used primarily
|
|
826
865
|
for display purposes, logging, or greeting messages and is not
|
|
827
866
|
required to be unique or validated unless specified by the caller.
|
|
828
|
-
Defaults to
|
|
867
|
+
Defaults to "John Doe".
|
|
829
868
|
|
|
830
869
|
somebody2 (str): Somebody's name. This can be any string representing a
|
|
831
870
|
person, whether it's a first name, full name, nickname, or even a
|
|
@@ -854,7 +893,6 @@ describe("Full example", () => {
|
|
|
854
893
|
name_and_type: int = None
|
|
855
894
|
name_type_and_value: int = 12
|
|
856
895
|
|
|
857
|
-
|
|
858
896
|
`);
|
|
859
897
|
});
|
|
860
898
|
it("renders correctly in a Function", () => {
|
|
@@ -882,32 +920,30 @@ describe("Full example", () => {
|
|
|
882
920
|
note: "This function can be used as both a regular function and a generator.",
|
|
883
921
|
style: "google"
|
|
884
922
|
});
|
|
885
|
-
|
|
886
|
-
name: "some_function",
|
|
887
|
-
doc: doc,
|
|
923
|
+
expect(_$createComponent(TestOutput, {
|
|
888
924
|
get children() {
|
|
889
|
-
return _$createComponent(py.
|
|
925
|
+
return _$createComponent(py.FunctionDeclaration, {
|
|
926
|
+
name: "some_function",
|
|
927
|
+
doc: doc,
|
|
890
928
|
get children() {
|
|
891
|
-
return
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
929
|
+
return _$createComponent(py.StatementList, {
|
|
930
|
+
get children() {
|
|
931
|
+
return [_$createComponent(py.VariableDeclaration, {
|
|
932
|
+
name: "just_name"
|
|
933
|
+
}), _$createComponent(py.VariableDeclaration, {
|
|
934
|
+
name: "name_and_type",
|
|
935
|
+
type: "number"
|
|
936
|
+
}), _$createComponent(py.VariableDeclaration, {
|
|
937
|
+
name: "name_type_and_value",
|
|
938
|
+
type: "number",
|
|
939
|
+
initializer: 12
|
|
940
|
+
})];
|
|
941
|
+
}
|
|
942
|
+
});
|
|
901
943
|
}
|
|
902
944
|
});
|
|
903
945
|
}
|
|
904
|
-
})
|
|
905
|
-
printOptions: {
|
|
906
|
-
printWidth: 80,
|
|
907
|
-
tabWidth: 4
|
|
908
|
-
}
|
|
909
|
-
});
|
|
910
|
-
expect(res).toRenderTo(d`
|
|
946
|
+
})).toRenderTo(`
|
|
911
947
|
def some_function():
|
|
912
948
|
"""
|
|
913
949
|
This is an example of a long docstring that will be broken in lines. We will
|
|
@@ -923,7 +959,7 @@ describe("Full example", () => {
|
|
|
923
959
|
nickname, or even a codename (e.g., 'Agent X'). It's used primarily
|
|
924
960
|
for display purposes, logging, or greeting messages and is not
|
|
925
961
|
required to be unique or validated unless specified by the caller.
|
|
926
|
-
Defaults to
|
|
962
|
+
Defaults to "John Doe".
|
|
927
963
|
|
|
928
964
|
somebody2 (str): Somebody's name. This can be any string representing a
|
|
929
965
|
person, whether it's a first name, full name, nickname, or even a
|
|
@@ -947,21 +983,18 @@ describe("Full example", () => {
|
|
|
947
983
|
name_and_type: number = None
|
|
948
984
|
name_type_and_value: number = 12
|
|
949
985
|
|
|
950
|
-
|
|
951
986
|
`);
|
|
952
987
|
});
|
|
953
988
|
it("renders correctly in a Variable", () => {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
tabWidth: 4
|
|
989
|
+
expect(_$createComponent(TestOutput, {
|
|
990
|
+
get children() {
|
|
991
|
+
return _$createComponent(py.VariableDeclaration, {
|
|
992
|
+
name: "myVar",
|
|
993
|
+
initializer: 42,
|
|
994
|
+
doc: "This is a very long docstring that will be broken in two lines when rendered. This part of the docstring will be in the second line."
|
|
995
|
+
});
|
|
962
996
|
}
|
|
963
|
-
})
|
|
964
|
-
expect(res).toRenderTo(d`
|
|
997
|
+
})).toRenderTo(`
|
|
965
998
|
# This is a very long docstring that will be broken in two lines when rendered.
|
|
966
999
|
# This part of the docstring will be in the second line.
|
|
967
1000
|
my_var = 42
|
|
@@ -975,27 +1008,29 @@ describe("Full example", () => {
|
|
|
975
1008
|
})];
|
|
976
1009
|
}
|
|
977
1010
|
});
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1011
|
+
expect(_$createComponent(TestOutput, {
|
|
1012
|
+
externals: [enumModule],
|
|
1013
|
+
get children() {
|
|
1014
|
+
return _$createComponent(py.ClassEnumDeclaration, {
|
|
1015
|
+
name: "Color",
|
|
1016
|
+
baseType: "IntEnum",
|
|
1017
|
+
members: [{
|
|
1018
|
+
name: "RED",
|
|
1019
|
+
value: "1",
|
|
1020
|
+
doc: "The color red."
|
|
1021
|
+
}, {
|
|
1022
|
+
name: "GREEN",
|
|
1023
|
+
value: "2",
|
|
1024
|
+
doc: "The color green."
|
|
1025
|
+
}, {
|
|
1026
|
+
name: "BLUE",
|
|
1027
|
+
value: "3",
|
|
1028
|
+
doc: "The color blue."
|
|
1029
|
+
}],
|
|
1030
|
+
doc: doc
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
})).toRenderTo(`
|
|
999
1034
|
from enum import IntEnum
|
|
1000
1035
|
|
|
1001
1036
|
|
|
@@ -1017,9 +1052,7 @@ describe("Full example", () => {
|
|
|
1017
1052
|
The color blue.
|
|
1018
1053
|
"""
|
|
1019
1054
|
|
|
1020
|
-
|
|
1021
|
-
`;
|
|
1022
|
-
expect(result).toRenderTo(expected);
|
|
1055
|
+
`);
|
|
1023
1056
|
});
|
|
1024
1057
|
it("ModuleDoc with SourceFile integration", () => {
|
|
1025
1058
|
const moduleDoc = _$createComponent(py.ModuleDoc, {
|
|
@@ -1040,50 +1073,49 @@ describe("Full example", () => {
|
|
|
1040
1073
|
todo: ["Add caching functionality", "Improve error messages"],
|
|
1041
1074
|
style: "google"
|
|
1042
1075
|
});
|
|
1043
|
-
|
|
1044
|
-
path: "utils.py",
|
|
1045
|
-
doc: moduleDoc,
|
|
1076
|
+
expect(_$createComponent(TestOutputDirectory, {
|
|
1046
1077
|
get children() {
|
|
1047
|
-
return
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1078
|
+
return _$createComponent(py.SourceFile, {
|
|
1079
|
+
path: "utils.py",
|
|
1080
|
+
doc: moduleDoc,
|
|
1081
|
+
get children() {
|
|
1082
|
+
return [_$createComponent(py.VariableDeclaration, {
|
|
1083
|
+
name: "DEFAULT_TIMEOUT",
|
|
1084
|
+
initializer: 30
|
|
1085
|
+
}), _$createComponent(py.VariableDeclaration, {
|
|
1086
|
+
name: "MAX_RETRIES",
|
|
1087
|
+
initializer: 3
|
|
1088
|
+
}), _$createComponent(py.FunctionDeclaration, {
|
|
1089
|
+
name: "process_data",
|
|
1090
|
+
children: "pass"
|
|
1091
|
+
})];
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1057
1094
|
}
|
|
1058
|
-
})
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
"utils.py": d`
|
|
1064
|
-
"""
|
|
1065
|
-
This module provides utility functions for data processing. It includes
|
|
1066
|
-
functions for validation, transformation, and analysis.
|
|
1067
|
-
|
|
1068
|
-
Attributes:
|
|
1069
|
-
DEFAULT_TIMEOUT (int): Default timeout value in seconds.
|
|
1095
|
+
})).toRenderTo({
|
|
1096
|
+
"utils.py": `
|
|
1097
|
+
"""
|
|
1098
|
+
This module provides utility functions for data processing. It includes
|
|
1099
|
+
functions for validation, transformation, and analysis.
|
|
1070
1100
|
|
|
1071
|
-
|
|
1101
|
+
Attributes:
|
|
1102
|
+
DEFAULT_TIMEOUT (int): Default timeout value in seconds.
|
|
1072
1103
|
|
|
1073
|
-
|
|
1074
|
-
* Add caching functionality
|
|
1075
|
-
* Improve error messages
|
|
1076
|
-
"""
|
|
1104
|
+
MAX_RETRIES (int): Maximum number of retry attempts.
|
|
1077
1105
|
|
|
1078
|
-
|
|
1106
|
+
Todo:
|
|
1107
|
+
* Add caching functionality
|
|
1108
|
+
* Improve error messages
|
|
1109
|
+
"""
|
|
1079
1110
|
|
|
1080
|
-
|
|
1111
|
+
default_timeout = 30
|
|
1081
1112
|
|
|
1082
|
-
|
|
1083
|
-
pass
|
|
1113
|
+
max_retries = 3
|
|
1084
1114
|
|
|
1115
|
+
def process_data():
|
|
1116
|
+
pass
|
|
1085
1117
|
|
|
1086
|
-
|
|
1118
|
+
`
|
|
1087
1119
|
});
|
|
1088
1120
|
});
|
|
1089
1121
|
it("GeneratorDoc with FunctionDeclaration integration", () => {
|
|
@@ -1101,12 +1133,15 @@ describe("Full example", () => {
|
|
|
1101
1133
|
yields: "int: The next fibonacci number in the sequence.",
|
|
1102
1134
|
style: "google"
|
|
1103
1135
|
});
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1136
|
+
expect(_$createComponent(TestOutput, {
|
|
1137
|
+
get children() {
|
|
1138
|
+
return _$createComponent(py.FunctionDeclaration, {
|
|
1139
|
+
name: "fibonacci_generator",
|
|
1140
|
+
doc: generatorDoc,
|
|
1141
|
+
children: "yield 0"
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
})).toRenderTo(`
|
|
1110
1145
|
def fibonacci_generator():
|
|
1111
1146
|
"""
|
|
1112
1147
|
A generator function that yields fibonacci numbers. This is an efficient way
|
|
@@ -1120,7 +1155,6 @@ describe("Full example", () => {
|
|
|
1120
1155
|
"""
|
|
1121
1156
|
yield 0
|
|
1122
1157
|
|
|
1123
|
-
|
|
1124
1158
|
`);
|
|
1125
1159
|
});
|
|
1126
1160
|
it("ExceptionDoc with ClassDeclaration integration", () => {
|
|
@@ -1141,25 +1175,28 @@ describe("Full example", () => {
|
|
|
1141
1175
|
}],
|
|
1142
1176
|
style: "google"
|
|
1143
1177
|
});
|
|
1144
|
-
|
|
1145
|
-
name: "ValidationError",
|
|
1146
|
-
bases: ["Exception"],
|
|
1147
|
-
doc: exceptionDoc,
|
|
1178
|
+
expect(_$createComponent(TestOutput, {
|
|
1148
1179
|
get children() {
|
|
1149
|
-
return _$createComponent(py.
|
|
1180
|
+
return _$createComponent(py.ClassDeclaration, {
|
|
1181
|
+
name: "ValidationError",
|
|
1182
|
+
bases: ["Exception"],
|
|
1183
|
+
doc: exceptionDoc,
|
|
1150
1184
|
get children() {
|
|
1151
|
-
return
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1185
|
+
return _$createComponent(py.StatementList, {
|
|
1186
|
+
get children() {
|
|
1187
|
+
return [_$createComponent(py.VariableDeclaration, {
|
|
1188
|
+
name: "field_name",
|
|
1189
|
+
type: "str"
|
|
1190
|
+
}), _$createComponent(py.VariableDeclaration, {
|
|
1191
|
+
name: "error_code",
|
|
1192
|
+
type: "int"
|
|
1193
|
+
})];
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1158
1196
|
}
|
|
1159
1197
|
});
|
|
1160
1198
|
}
|
|
1161
|
-
})
|
|
1162
|
-
expect(result).toRenderTo(d`
|
|
1199
|
+
})).toRenderTo(`
|
|
1163
1200
|
class ValidationError(Exception):
|
|
1164
1201
|
"""
|
|
1165
1202
|
Custom exception raised when data validation fails. This exception includes
|
|
@@ -1174,7 +1211,6 @@ describe("Full example", () => {
|
|
|
1174
1211
|
field_name: str = None
|
|
1175
1212
|
error_code: int = None
|
|
1176
1213
|
|
|
1177
|
-
|
|
1178
1214
|
`);
|
|
1179
1215
|
});
|
|
1180
1216
|
it("PropertyDoc with FunctionDeclaration (as property method) integration", () => {
|
|
@@ -1186,18 +1222,21 @@ describe("Full example", () => {
|
|
|
1186
1222
|
},
|
|
1187
1223
|
style: "google"
|
|
1188
1224
|
});
|
|
1189
|
-
|
|
1190
|
-
name: "Person",
|
|
1225
|
+
expect(_$createComponent(TestOutput, {
|
|
1191
1226
|
get children() {
|
|
1192
|
-
return _$createComponent(py.
|
|
1193
|
-
name: "
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1227
|
+
return _$createComponent(py.ClassDeclaration, {
|
|
1228
|
+
name: "Person",
|
|
1229
|
+
get children() {
|
|
1230
|
+
return _$createComponent(py.PropertyDeclaration, {
|
|
1231
|
+
name: "full_name",
|
|
1232
|
+
doc: propertyDoc,
|
|
1233
|
+
type: "str",
|
|
1234
|
+
children: "return \"John Doe\""
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1197
1237
|
});
|
|
1198
1238
|
}
|
|
1199
|
-
})
|
|
1200
|
-
expect(result).toRenderTo(`
|
|
1239
|
+
})).toRenderTo(`
|
|
1201
1240
|
class Person:
|
|
1202
1241
|
@property
|
|
1203
1242
|
def full_name(self) -> str:
|
|
@@ -1232,26 +1271,29 @@ describe("Full example", () => {
|
|
|
1232
1271
|
note: "This method modifies the internal validation state.",
|
|
1233
1272
|
style: "google"
|
|
1234
1273
|
});
|
|
1235
|
-
|
|
1236
|
-
name: "DataValidator",
|
|
1274
|
+
expect(_$createComponent(TestOutput, {
|
|
1237
1275
|
get children() {
|
|
1238
|
-
return _$createComponent(py.
|
|
1239
|
-
name: "
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1276
|
+
return _$createComponent(py.ClassDeclaration, {
|
|
1277
|
+
name: "DataValidator",
|
|
1278
|
+
get children() {
|
|
1279
|
+
return _$createComponent(py.MethodDeclaration, {
|
|
1280
|
+
name: "validate",
|
|
1281
|
+
doc: methodDoc,
|
|
1282
|
+
parameters: [{
|
|
1283
|
+
name: "data",
|
|
1284
|
+
type: "dict"
|
|
1285
|
+
}, {
|
|
1286
|
+
name: "strict",
|
|
1287
|
+
type: "bool",
|
|
1288
|
+
default: true
|
|
1289
|
+
}],
|
|
1290
|
+
returnType: "bool",
|
|
1291
|
+
children: "return self.validate(data, strict)"
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1251
1294
|
});
|
|
1252
1295
|
}
|
|
1253
|
-
})
|
|
1254
|
-
expect(result).toRenderTo(d`
|
|
1296
|
+
})).toRenderTo(`
|
|
1255
1297
|
class DataValidator:
|
|
1256
1298
|
def validate(self, data: dict, strict: bool = True) -> bool:
|
|
1257
1299
|
"""
|
|
@@ -1276,7 +1318,6 @@ describe("Full example", () => {
|
|
|
1276
1318
|
return self.validate(data, strict)
|
|
1277
1319
|
|
|
1278
1320
|
|
|
1279
|
-
|
|
1280
1321
|
`);
|
|
1281
1322
|
});
|
|
1282
1323
|
});
|