@alloy-js/python 0.5.0-dev.1 → 0.5.0

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.
Files changed (217) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/dev/src/components/CallSignature.js +2 -2
  3. package/dist/dev/src/components/CallSignature.js.map +1 -1
  4. package/dist/dev/src/components/ConstructorDeclaration.js +1 -1
  5. package/dist/dev/src/components/ConstructorDeclaration.js.map +1 -1
  6. package/dist/dev/src/components/DataclassDeclaration.js +5 -5
  7. package/dist/dev/src/components/DataclassDeclaration.js.map +1 -1
  8. package/dist/dev/src/components/FunctionBase.js +9 -9
  9. package/dist/dev/src/components/FunctionBase.js.map +1 -1
  10. package/dist/dev/src/components/PropertyDeclaration.js +8 -8
  11. package/dist/dev/src/components/PropertyDeclaration.js.map +1 -1
  12. package/dist/dev/src/components/PyDoc.js +64 -64
  13. package/dist/dev/src/components/PyDoc.js.map +1 -1
  14. package/dist/dev/src/components/PydanticClassDeclaration.js +5 -5
  15. package/dist/dev/src/components/PydanticClassDeclaration.js.map +1 -1
  16. package/dist/dev/src/components/SourceFile.js +44 -32
  17. package/dist/dev/src/components/SourceFile.js.map +1 -1
  18. package/dist/dev/src/symbols/python-output-symbol.js.map +1 -1
  19. package/dist/dev/test/callsignatures.test.js +471 -297
  20. package/dist/dev/test/callsignatures.test.js.map +1 -1
  21. package/dist/dev/test/class-method-declaration.test.js +21 -10
  22. package/dist/dev/test/class-method-declaration.test.js.map +1 -1
  23. package/dist/dev/test/classdeclarations.test.js +459 -393
  24. package/dist/dev/test/classdeclarations.test.js.map +1 -1
  25. package/dist/dev/test/classinstantiations.test.js +201 -168
  26. package/dist/dev/test/classinstantiations.test.js.map +1 -1
  27. package/dist/dev/test/constructordeclaration.test.js +22 -11
  28. package/dist/dev/test/constructordeclaration.test.js.map +1 -1
  29. package/dist/dev/test/dataclassdeclarations.test.js +322 -368
  30. package/dist/dev/test/dataclassdeclarations.test.js.map +1 -1
  31. package/dist/dev/test/decoratorlist.test.js +96 -49
  32. package/dist/dev/test/decoratorlist.test.js.map +1 -1
  33. package/dist/dev/test/dundermethoddeclaration.test.js +22 -11
  34. package/dist/dev/test/dundermethoddeclaration.test.js.map +1 -1
  35. package/dist/dev/test/enums.test.js +218 -184
  36. package/dist/dev/test/enums.test.js.map +1 -1
  37. package/dist/dev/test/externals.test.js +57 -45
  38. package/dist/dev/test/externals.test.js.map +1 -1
  39. package/dist/dev/test/factories.test.js +124 -50
  40. package/dist/dev/test/factories.test.js.map +1 -1
  41. package/dist/dev/test/functioncallexpressions.test.js +199 -164
  42. package/dist/dev/test/functioncallexpressions.test.js.map +1 -1
  43. package/dist/dev/test/functiondeclaration.test.js +439 -272
  44. package/dist/dev/test/functiondeclaration.test.js.map +1 -1
  45. package/dist/dev/test/imports.test.js +273 -221
  46. package/dist/dev/test/imports.test.js.map +1 -1
  47. package/dist/dev/test/memberexpressions.test.js +1237 -972
  48. package/dist/dev/test/memberexpressions.test.js.map +1 -1
  49. package/dist/dev/test/methoddeclaration.test.js +142 -78
  50. package/dist/dev/test/methoddeclaration.test.js.map +1 -1
  51. package/dist/dev/test/namepolicies.test.js +130 -94
  52. package/dist/dev/test/namepolicies.test.js.map +1 -1
  53. package/dist/dev/test/propertydeclaration.test.js +88 -59
  54. package/dist/dev/test/propertydeclaration.test.js.map +1 -1
  55. package/dist/dev/test/pydanticclassdeclarations.test.js +299 -347
  56. package/dist/dev/test/pydanticclassdeclarations.test.js.map +1 -1
  57. package/dist/dev/test/pydocs.test.js +888 -715
  58. package/dist/dev/test/pydocs.test.js.map +1 -1
  59. package/dist/dev/test/references.test.js +42 -35
  60. package/dist/dev/test/references.test.js.map +1 -1
  61. package/dist/dev/test/sourcefiles.test.js +1109 -841
  62. package/dist/dev/test/sourcefiles.test.js.map +1 -1
  63. package/dist/dev/test/staticmethoddeclaration.test.js +21 -10
  64. package/dist/dev/test/staticmethoddeclaration.test.js.map +1 -1
  65. package/dist/dev/test/type-checking-imports.test.js +408 -359
  66. package/dist/dev/test/type-checking-imports.test.js.map +1 -1
  67. package/dist/dev/test/typereference.test.js +55 -40
  68. package/dist/dev/test/typereference.test.js.map +1 -1
  69. package/dist/dev/test/uniontypeexpression.test.js +222 -146
  70. package/dist/dev/test/uniontypeexpression.test.js.map +1 -1
  71. package/dist/dev/test/utils.js +39 -77
  72. package/dist/dev/test/utils.js.map +1 -1
  73. package/dist/dev/test/values.test.js +237 -101
  74. package/dist/dev/test/values.test.js.map +1 -1
  75. package/dist/dev/test/variables.test.js +321 -203
  76. package/dist/dev/test/variables.test.js.map +1 -1
  77. package/dist/dev/test/vitest.setup.js +2 -0
  78. package/dist/dev/test/vitest.setup.js.map +1 -0
  79. package/dist/src/components/CallSignature.d.ts.map +1 -1
  80. package/dist/src/components/CallSignature.js.map +1 -1
  81. package/dist/src/components/ConstructorDeclaration.d.ts.map +1 -1
  82. package/dist/src/components/ConstructorDeclaration.js.map +1 -1
  83. package/dist/src/components/DataclassDeclaration.d.ts.map +1 -1
  84. package/dist/src/components/DataclassDeclaration.js.map +1 -1
  85. package/dist/src/components/FunctionBase.d.ts.map +1 -1
  86. package/dist/src/components/FunctionBase.js.map +1 -1
  87. package/dist/src/components/PropertyDeclaration.d.ts.map +1 -1
  88. package/dist/src/components/PropertyDeclaration.js.map +1 -1
  89. package/dist/src/components/PyDoc.d.ts.map +1 -1
  90. package/dist/src/components/PyDoc.js.map +1 -1
  91. package/dist/src/components/PydanticClassDeclaration.d.ts.map +1 -1
  92. package/dist/src/components/PydanticClassDeclaration.js.map +1 -1
  93. package/dist/src/components/SourceFile.d.ts +2 -2
  94. package/dist/src/components/SourceFile.d.ts.map +1 -1
  95. package/dist/src/components/SourceFile.js +12 -0
  96. package/dist/src/components/SourceFile.js.map +1 -1
  97. package/dist/src/symbols/python-output-symbol.d.ts.map +1 -1
  98. package/dist/src/symbols/python-output-symbol.js.map +1 -1
  99. package/dist/test/callsignatures.test.js +346 -272
  100. package/dist/test/callsignatures.test.js.map +1 -1
  101. package/dist/test/class-method-declaration.test.js +7 -4
  102. package/dist/test/class-method-declaration.test.js.map +1 -1
  103. package/dist/test/classdeclarations.test.js +302 -288
  104. package/dist/test/classdeclarations.test.js.map +1 -1
  105. package/dist/test/classinstantiations.test.js +112 -103
  106. package/dist/test/classinstantiations.test.js.map +1 -1
  107. package/dist/test/constructordeclaration.test.js +7 -4
  108. package/dist/test/constructordeclaration.test.js.map +1 -1
  109. package/dist/test/dataclassdeclarations.test.js +134 -184
  110. package/dist/test/dataclassdeclarations.test.js.map +1 -1
  111. package/dist/test/decoratorlist.test.js +59 -36
  112. package/dist/test/decoratorlist.test.js.map +1 -1
  113. package/dist/test/dundermethoddeclaration.test.js +7 -4
  114. package/dist/test/dundermethoddeclaration.test.js.map +1 -1
  115. package/dist/test/enums.test.js +161 -159
  116. package/dist/test/enums.test.js.map +1 -1
  117. package/dist/test/externals.test.js +24 -24
  118. package/dist/test/externals.test.js.map +1 -1
  119. package/dist/test/factories.test.js +75 -33
  120. package/dist/test/factories.test.js.map +1 -1
  121. package/dist/test/functioncallexpressions.test.js +117 -106
  122. package/dist/test/functioncallexpressions.test.js.map +1 -1
  123. package/dist/test/functiondeclaration.test.js +247 -180
  124. package/dist/test/functiondeclaration.test.js.map +1 -1
  125. package/dist/test/imports.test.js +171 -143
  126. package/dist/test/imports.test.js.map +1 -1
  127. package/dist/test/memberexpressions.test.js +582 -453
  128. package/dist/test/memberexpressions.test.js.map +1 -1
  129. package/dist/test/methoddeclaration.test.js +66 -46
  130. package/dist/test/methoddeclaration.test.js.map +1 -1
  131. package/dist/test/namepolicies.test.js +90 -78
  132. package/dist/test/namepolicies.test.js.map +1 -1
  133. package/dist/test/propertydeclaration.test.js +25 -20
  134. package/dist/test/propertydeclaration.test.js.map +1 -1
  135. package/dist/test/pydanticclassdeclarations.test.js +134 -190
  136. package/dist/test/pydanticclassdeclarations.test.js.map +1 -1
  137. package/dist/test/pydocs.test.js +573 -532
  138. package/dist/test/pydocs.test.js.map +1 -1
  139. package/dist/test/references.test.js +31 -28
  140. package/dist/test/references.test.js.map +1 -1
  141. package/dist/test/sourcefiles.test.js +700 -580
  142. package/dist/test/sourcefiles.test.js.map +1 -1
  143. package/dist/test/staticmethoddeclaration.test.js +7 -4
  144. package/dist/test/staticmethoddeclaration.test.js.map +1 -1
  145. package/dist/test/type-checking-imports.test.js +297 -284
  146. package/dist/test/type-checking-imports.test.js.map +1 -1
  147. package/dist/test/typereference.test.js +29 -22
  148. package/dist/test/typereference.test.js.map +1 -1
  149. package/dist/test/uniontypeexpression.test.js +124 -88
  150. package/dist/test/uniontypeexpression.test.js.map +1 -1
  151. package/dist/test/utils.d.ts +10 -17
  152. package/dist/test/utils.d.ts.map +1 -1
  153. package/dist/test/utils.js +32 -74
  154. package/dist/test/utils.js.map +1 -1
  155. package/dist/test/values.test.js +135 -67
  156. package/dist/test/values.test.js.map +1 -1
  157. package/dist/test/variables.test.js +201 -151
  158. package/dist/test/variables.test.js.map +1 -1
  159. package/dist/test/vitest.setup.d.ts +2 -0
  160. package/dist/test/vitest.setup.d.ts.map +1 -0
  161. package/dist/test/vitest.setup.js +2 -0
  162. package/dist/test/vitest.setup.js.map +1 -0
  163. package/dist/tsconfig.tsbuildinfo +1 -1
  164. package/docs/api/components/FunctionalEnumDeclaration.md +3 -6
  165. package/docs/api/components/MemberExpression.md +1 -5
  166. package/docs/api/components/SourceFile.md +20 -8
  167. package/docs/api/components/index.md +0 -2
  168. package/docs/api/functions/isTypeRefContext.md +1 -1
  169. package/docs/api/index.md +2 -2
  170. package/docs/api/types/ReferenceProps.md +7 -0
  171. package/docs/api/types/TypeRefContextProps.md +7 -0
  172. package/docs/api/types/index.md +2 -0
  173. package/package.json +11 -10
  174. package/src/components/CallSignature.tsx +4 -2
  175. package/src/components/ConstructorDeclaration.tsx +4 -2
  176. package/src/components/DataclassDeclaration.tsx +1 -2
  177. package/src/components/FunctionBase.tsx +1 -2
  178. package/src/components/PropertyDeclaration.tsx +8 -4
  179. package/src/components/PyDoc.tsx +12 -6
  180. package/src/components/PydanticClassDeclaration.tsx +1 -2
  181. package/src/components/SourceFile.tsx +6 -1
  182. package/src/symbols/python-output-symbol.ts +1 -2
  183. package/temp/api.json +107 -61
  184. package/test/callsignatures.test.tsx +309 -283
  185. package/test/class-method-declaration.test.tsx +3 -4
  186. package/test/classdeclarations.test.tsx +263 -248
  187. package/test/classinstantiations.test.tsx +115 -109
  188. package/test/constructordeclaration.test.tsx +9 -6
  189. package/test/dataclassdeclarations.test.tsx +243 -361
  190. package/test/decoratorlist.test.tsx +78 -59
  191. package/test/dundermethoddeclaration.test.tsx +3 -4
  192. package/test/enums.test.tsx +65 -81
  193. package/test/externals.test.tsx +25 -25
  194. package/test/factories.test.tsx +64 -22
  195. package/test/functioncallexpressions.test.tsx +123 -109
  196. package/test/functiondeclaration.test.tsx +209 -148
  197. package/test/imports.test.tsx +119 -91
  198. package/test/memberexpressions.test.tsx +265 -207
  199. package/test/methoddeclaration.test.tsx +84 -63
  200. package/test/namepolicies.test.tsx +69 -69
  201. package/test/propertydeclaration.test.tsx +7 -8
  202. package/test/pydanticclassdeclarations.test.tsx +355 -487
  203. package/test/pydocs.test.tsx +531 -579
  204. package/test/references.test.tsx +24 -23
  205. package/test/sourcefiles.test.tsx +527 -492
  206. package/test/staticmethoddeclaration.test.tsx +3 -4
  207. package/test/type-checking-imports.test.tsx +206 -218
  208. package/test/typereference.test.tsx +15 -12
  209. package/test/uniontypeexpression.test.tsx +74 -61
  210. package/test/utils.tsx +26 -110
  211. package/test/values.test.tsx +82 -32
  212. package/test/variables.test.tsx +162 -142
  213. package/test/vitest.setup.ts +1 -0
  214. package/tsdoc-metadata.json +1 -1
  215. package/vitest.config.ts +4 -0
  216. package/docs/api/components/Reference.md +0 -31
  217. package/docs/api/components/TypeRefContext.md +0 -41
@@ -1,210 +1,230 @@
1
1
  import { namekey, refkey } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
3
2
  import { describe, expect, it } from "vitest";
4
3
  import * as py from "../src/index.js";
5
- import {
6
- assertFileContents,
7
- toSourceText,
8
- toSourceTextMultiple,
9
- } from "./utils.jsx";
4
+ import { TestOutput, TestOutputDirectory } from "./utils.js";
10
5
 
11
6
  describe("Python Variable", () => {
12
7
  it("declares a python variable", () => {
13
- const res = toSourceText([
14
- <py.VariableDeclaration name="myVar" type="int" initializer={42} />,
15
- ]);
16
- expect(res).toBe(`my_var: int = 42`);
8
+ expect(
9
+ <TestOutput>
10
+ <py.VariableDeclaration name="myVar" type="int" initializer={42} />
11
+ </TestOutput>,
12
+ ).toRenderTo("my_var: int = 42");
17
13
  });
18
14
 
19
15
  it("takes a namekey", () => {
20
- const res = toSourceText([
21
- <py.VariableDeclaration
22
- name={namekey("my-var")}
23
- type="int"
24
- initializer={42}
25
- />,
26
- ]);
27
- expect(res).toBe(`my_var: int = 42`);
16
+ expect(
17
+ <TestOutput>
18
+ <py.VariableDeclaration
19
+ name={namekey("my-var")}
20
+ type="int"
21
+ initializer={42}
22
+ />
23
+ </TestOutput>,
24
+ ).toRenderTo("my_var: int = 42");
28
25
  });
29
26
 
30
27
  it("takes a namekey", () => {
31
- const res = toSourceText([
32
- <py.VariableDeclaration
33
- name={namekey("my-var")}
34
- type="int"
35
- initializer={42}
36
- />,
37
- ]);
38
- expect(res).toBe(`my_var: int = 42`);
28
+ expect(
29
+ <TestOutput>
30
+ <py.VariableDeclaration
31
+ name={namekey("my-var")}
32
+ type="int"
33
+ initializer={42}
34
+ />
35
+ </TestOutput>,
36
+ ).toRenderTo("my_var: int = 42");
39
37
  });
40
38
 
41
39
  it("declares a python variable without value", () => {
42
- const res = toSourceText([
43
- <py.VariableDeclaration name="myVar" type="int" omitNone />,
44
- ]);
45
- expect(res).toBe(`my_var: int`);
40
+ expect(
41
+ <TestOutput>
42
+ <py.VariableDeclaration name="myVar" type="int" omitNone />
43
+ </TestOutput>,
44
+ ).toRenderTo("my_var: int");
46
45
  });
47
46
 
48
47
  it("declares a python variable without typeAnnotations", () => {
49
- const res = toSourceText([
50
- <py.VariableDeclaration name="myVar" initializer={42} />,
51
- ]);
52
- expect(res).toBe(`my_var = 42`);
48
+ expect(
49
+ <TestOutput>
50
+ <py.VariableDeclaration name="myVar" initializer={42} />
51
+ </TestOutput>,
52
+ ).toRenderTo("my_var = 42");
53
53
  });
54
54
 
55
55
  it("declares a python variable as None when undefined", () => {
56
- const res = toSourceText([<py.VariableDeclaration name="myVar" />]);
57
- expect(res).toBe(`my_var = None`);
56
+ expect(
57
+ <TestOutput>
58
+ <py.VariableDeclaration name="myVar" />
59
+ </TestOutput>,
60
+ ).toRenderTo("my_var = None");
58
61
  });
59
62
 
60
63
  it("declares a python variable as None when null", () => {
61
- const res = toSourceText([
62
- <py.VariableDeclaration
63
- name="myVar"
64
- initializer={<py.Atom jsValue={null} />}
65
- />,
66
- ]);
67
- expect(res).toBe(`my_var = None`);
64
+ expect(
65
+ <TestOutput>
66
+ <py.VariableDeclaration
67
+ name="myVar"
68
+ initializer={<py.Atom jsValue={null} />}
69
+ />
70
+ </TestOutput>,
71
+ ).toRenderTo("my_var = None");
68
72
  });
69
73
 
70
74
  it("declares a python variable that's an array", () => {
71
- const res = toSourceText([
72
- <py.VariableDeclaration
73
- name="numbers"
74
- type={<py.TypeReference name="list" typeArgs={["int"]} />}
75
- initializer={<py.Atom jsValue={[1, 2, 3]} />}
76
- />,
77
- ]);
78
- expect(res).toBe(`numbers: list[int] = [1, 2, 3]`);
75
+ expect(
76
+ <TestOutput>
77
+ <py.VariableDeclaration
78
+ name="numbers"
79
+ type={<py.TypeReference name="list" typeArgs={["int"]} />}
80
+ initializer={<py.Atom jsValue={[1, 2, 3]} />}
81
+ />
82
+ </TestOutput>,
83
+ ).toRenderTo("numbers: list[int] = [1, 2, 3]");
79
84
  });
80
85
 
81
86
  it("declares a python variable with a python value", () => {
82
- const res = toSourceText([
83
- <py.VariableDeclaration
84
- name="nameIdPairs"
85
- initializer={<py.Atom jsValue={{ John: 123, Doe: 234 }} />}
86
- />,
87
- ]);
88
- expect(res).toBe(`name_id_pairs = {"John": 123, "Doe": 234}`);
87
+ expect(
88
+ <TestOutput>
89
+ <py.VariableDeclaration
90
+ name="nameIdPairs"
91
+ initializer={<py.Atom jsValue={{ John: 123, Doe: 234 }} />}
92
+ />
93
+ </TestOutput>,
94
+ ).toRenderTo(`name_id_pairs = {"John": 123, "Doe": 234}`);
89
95
  });
90
96
 
91
97
  it("declares a python variable with omitNone", () => {
92
- const res = toSourceText([
93
- <py.VariableDeclaration name="omitNoneVar" type="int" omitNone={true} />,
94
- ]);
95
- expect(res).toBe(`omit_none_var: int`);
98
+ expect(
99
+ <TestOutput>
100
+ <py.VariableDeclaration name="omitNoneVar" type="int" omitNone={true} />
101
+ </TestOutput>,
102
+ ).toRenderTo("omit_none_var: int");
96
103
  });
97
104
 
98
105
  it("declares a call statement python variable", () => {
99
- const res = toSourceText([
100
- <py.VariableDeclaration
101
- name="callStmtVar"
102
- initializer={12}
103
- callStatementVar={true}
104
- />,
105
- ]);
106
- expect(res).toBe(`call_stmt_var=12`);
106
+ expect(
107
+ <TestOutput>
108
+ <py.VariableDeclaration
109
+ name="callStmtVar"
110
+ initializer={12}
111
+ callStatementVar={true}
112
+ />
113
+ </TestOutput>,
114
+ ).toRenderTo("call_stmt_var=12");
107
115
  });
108
116
 
109
117
  it("declares a call statement python variable without name", () => {
110
- const res = toSourceText([
111
- <py.VariableDeclaration
112
- name=""
113
- initializer={12}
114
- callStatementVar={true}
115
- />,
116
- ]);
117
- expect(res).toBe(`12`);
118
+ expect(
119
+ <TestOutput>
120
+ <py.VariableDeclaration
121
+ name=""
122
+ initializer={12}
123
+ callStatementVar={true}
124
+ />
125
+ </TestOutput>,
126
+ ).toRenderTo("12");
118
127
  });
119
128
 
120
129
  it("declares a python variable with an optional type", () => {
121
- const res = toSourceText([
122
- <py.StatementList>
123
- <py.VariableDeclaration
124
- name="my_var"
125
- type={
126
- <py.UnionTypeExpression>{["int", "None"]}</py.UnionTypeExpression>
127
- }
128
- />
129
- </py.StatementList>,
130
- ]);
131
- expect(res).toBe(d`
132
- my_var: int | None = None`);
130
+ expect(
131
+ <TestOutput>
132
+ <py.StatementList>
133
+ <py.VariableDeclaration
134
+ name="my_var"
135
+ type={
136
+ <py.UnionTypeExpression>{["int", "None"]}</py.UnionTypeExpression>
137
+ }
138
+ />
139
+ </py.StatementList>
140
+ </TestOutput>,
141
+ ).toRenderTo(
142
+ `
143
+ my_var: int | None = None`,
144
+ );
133
145
  });
134
146
 
135
147
  it("declares a python variable with an optional type omitting none", () => {
136
- const res = toSourceText([
137
- <py.StatementList>
138
- <py.VariableDeclaration
139
- name="my_var"
140
- type={
141
- <py.UnionTypeExpression>{["int", "None"]}</py.UnionTypeExpression>
142
- }
143
- omitNone
144
- />
145
- </py.StatementList>,
146
- ]);
147
- expect(res).toBe(d`
148
- my_var: int | None`);
148
+ expect(
149
+ <TestOutput>
150
+ <py.StatementList>
151
+ <py.VariableDeclaration
152
+ name="my_var"
153
+ type={
154
+ <py.UnionTypeExpression>{["int", "None"]}</py.UnionTypeExpression>
155
+ }
156
+ omitNone
157
+ />
158
+ </py.StatementList>
159
+ </TestOutput>,
160
+ ).toRenderTo(
161
+ `
162
+ my_var: int | None`,
163
+ );
149
164
  });
150
165
 
151
166
  it("declares a python variable with a class type", () => {
152
167
  const classKey = refkey();
153
- const res = toSourceText([
154
- <py.StatementList>
155
- <py.ClassDeclaration name="MyClass" refkey={classKey} />
156
- <py.VariableDeclaration
157
- name="my_var"
158
- type={<py.Reference refkey={classKey} />}
159
- />
160
- </py.StatementList>,
161
- ]);
162
- expect(res).toBe(d`
168
+ expect(
169
+ <TestOutput>
170
+ <py.StatementList>
171
+ <py.ClassDeclaration name="MyClass" refkey={classKey} />
172
+ <py.VariableDeclaration
173
+ name="my_var"
174
+ type={<py.Reference refkey={classKey} />}
175
+ />
176
+ </py.StatementList>
177
+ </TestOutput>,
178
+ ).toRenderTo(
179
+ `
163
180
  class MyClass:
164
181
  pass
165
182
 
166
- my_var: MyClass = None`);
183
+ my_var: MyClass = None`,
184
+ );
167
185
  });
168
186
 
169
187
  it("declares a python variable with a class type from a different module", () => {
170
188
  const classKey = refkey();
171
- const res = toSourceTextMultiple([
172
- <py.SourceFile path="classes.py">
173
- <py.ClassDeclaration name="MyClass" refkey={classKey} />
174
- </py.SourceFile>,
175
- <py.SourceFile path="usage.py">
176
- <py.VariableDeclaration name="my_var" type={classKey} />
177
- </py.SourceFile>,
178
- ]);
179
- assertFileContents(res, {
189
+ expect(
190
+ <TestOutputDirectory>
191
+ <py.SourceFile path="classes.py">
192
+ <py.ClassDeclaration name="MyClass" refkey={classKey} />
193
+ </py.SourceFile>
194
+ <py.SourceFile path="usage.py">
195
+ <py.VariableDeclaration name="my_var" type={classKey} />
196
+ </py.SourceFile>
197
+ </TestOutputDirectory>,
198
+ ).toRenderTo({
180
199
  "classes.py": `
181
- class MyClass:
182
- pass
200
+ class MyClass:
201
+ pass
183
202
 
184
- `,
203
+ `,
185
204
  "usage.py": `
186
- from typing import TYPE_CHECKING
205
+ from typing import TYPE_CHECKING
187
206
 
188
- if TYPE_CHECKING:
189
- from classes import MyClass
207
+ if TYPE_CHECKING:
208
+ from classes import MyClass
190
209
 
191
- my_var: MyClass = None
192
- `,
210
+ my_var: MyClass = None
211
+ `,
193
212
  });
194
213
  });
195
214
 
196
215
  it("declares a python variable receiving other variable as value", () => {
197
216
  const varKey = refkey();
198
- const res = toSourceText([
199
- <py.StatementList>
200
- <py.VariableDeclaration
201
- name="my_var"
202
- refkey={varKey}
203
- initializer={42}
204
- />
205
- <py.VariableDeclaration name="my_other_var" initializer={varKey} />
206
- </py.StatementList>,
207
- ]);
208
- expect(res).toBe(`my_var = 42\nmy_other_var = my_var`);
217
+ expect(
218
+ <TestOutput>
219
+ <py.StatementList>
220
+ <py.VariableDeclaration
221
+ name="my_var"
222
+ refkey={varKey}
223
+ initializer={42}
224
+ />
225
+ <py.VariableDeclaration name="my_other_var" initializer={varKey} />
226
+ </py.StatementList>
227
+ </TestOutput>,
228
+ ).toRenderTo("my_var = 42\nmy_other_var = my_var");
209
229
  });
210
230
  });
@@ -0,0 +1 @@
1
+ import "@alloy-js/core/testing";
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.52.9"
8
+ "packageVersion": "7.58.8"
9
9
  }
10
10
  ]
11
11
  }
package/vitest.config.ts CHANGED
@@ -14,5 +14,9 @@ export default defineConfig({
14
14
  jsx: "preserve",
15
15
  sourcemap: "both",
16
16
  },
17
+ test: {
18
+ exclude: ["**/dist/**", "**/node_modules/**"],
19
+ setupFiles: ["./test/vitest.setup.ts"],
20
+ },
17
21
  plugins: [alloyPlugin()],
18
22
  });
@@ -1,31 +0,0 @@
1
- # Reference
2
-
3
- A Python reference to a symbol, such as a variable, function, or class.
4
-
5
- * jsx
6
-
7
- ```tsx
8
- import { Reference } from "@alloy-js/python";
9
-
10
-
11
- <Reference refkey={Refkey} />
12
- ```
13
-
14
- * stc
15
-
16
- ```ts
17
- import { Reference } from "@alloy-js/python/stc";
18
-
19
-
20
- Reference({ refkey: Refkey }).children(children)
21
- ```
22
-
23
- ## Props
24
-
25
- | | | |
26
- | ------ | ------------------------------------- | - |
27
- | refkey | [Refkey](../../../core/types/refkey/) | |
28
-
29
- ## Remarks
30
-
31
- This component is used to render references to symbols in Python code. It takes a `refkey` prop which is the key of the symbol to reference.
@@ -1,41 +0,0 @@
1
- # TypeRefContext
2
-
3
- Set the current context of reference to be type reference.
4
-
5
- * jsx
6
-
7
- ```tsx
8
- import { TypeRefContext } from "@alloy-js/python";
9
-
10
-
11
- <TypeRefContext >
12
- {children}
13
- </TypeRefContext>
14
- ```
15
-
16
- * stc
17
-
18
- ```ts
19
- import { TypeRefContext } from "@alloy-js/python/stc";
20
-
21
-
22
- TypeRefContext({ }).children(children)
23
- ```
24
-
25
- ## Props
26
-
27
- | | | |
28
- | -------- | ----------------------------------------- | -------- |
29
- | children | [Children](../../../core/types/children/) | Children |
30
-
31
- ## Remarks
32
-
33
- References used inside the children of this component will be treated as type-only references. When a symbol is only referenced in type contexts, it will be imported inside a `if TYPE_CHECKING:` block.
34
-
35
- ## Example
36
-
37
- ```tsx
38
- <TypeRefContext>
39
- {someTypeRefkey}
40
- </TypeRefContext>
41
- ```