@darabonba/python-generator 2.0.2 → 2.0.3

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 (179) hide show
  1. package/.github/workflows/ci.yml +1 -1
  2. package/ChangeLog.md +12 -0
  3. package/lib/generator.js +195 -109
  4. package/lib/helper.js +21 -1
  5. package/package.json +1 -1
  6. package/tests/expected/{python3/model/tea_python_tests/client.py → annotation/tea_python_tests/models/__init__.py} +6 -3
  7. package/tests/expected/annotation/tea_python_tests/{models.py → models/_test.py} +1 -1
  8. package/tests/expected/comment/tea_python_tests/models/__init__.py +15 -0
  9. package/tests/expected/comment/tea_python_tests/models/_test_1.py +91 -0
  10. package/tests/expected/comment/tea_python_tests/models/_test_2.py +55 -0
  11. package/tests/expected/comment/tea_python_tests/models/_test_3.py +61 -0
  12. package/tests/expected/complex/tea_python_tests/client.py +6 -6
  13. package/tests/expected/complex/tea_python_tests/exceptions/__init__.py +13 -0
  14. package/tests/expected/complex/tea_python_tests/exceptions/_err_1.py +23 -0
  15. package/tests/expected/complex/tea_python_tests/exceptions/_err_2.py +22 -0
  16. package/tests/expected/complex/tea_python_tests/models/__init__.py +19 -0
  17. package/tests/{output/complex/tea_python_tests/models.py → expected/complex/tea_python_tests/models/_complex_request.py} +12 -141
  18. package/tests/expected/complex/tea_python_tests/models/_complex_request_configs.py +47 -0
  19. package/tests/expected/complex/tea_python_tests/models/_complex_request_header.py +42 -0
  20. package/tests/expected/complex/tea_python_tests/models/_complex_request_part.py +33 -0
  21. package/tests/expected/complex/tea_python_tests/models/_response.py +33 -0
  22. package/tests/expected/model/tea_python_tests/exceptions/__init__.py +11 -0
  23. package/tests/expected/model/tea_python_tests/{exceptions.py → exceptions/_main_file.py} +1 -1
  24. package/tests/expected/model/tea_python_tests/models/__init__.py +33 -0
  25. package/tests/expected/model/tea_python_tests/models/_class.py +24 -0
  26. package/tests/expected/model/tea_python_tests/models/_m.py +38 -0
  27. package/tests/expected/model/tea_python_tests/models/_main_file_model.py +45 -0
  28. package/tests/expected/model/tea_python_tests/models/_main_file_model_model.py +32 -0
  29. package/tests/expected/model/tea_python_tests/models/_model.py +32 -0
  30. package/tests/expected/model/tea_python_tests/models/_msub_m.py +26 -0
  31. package/tests/expected/model/tea_python_tests/{models.py → models/_my_model.py} +16 -321
  32. package/tests/expected/model/tea_python_tests/models/_my_model_model.py +45 -0
  33. package/tests/expected/model/tea_python_tests/models/_my_model_model_model.py +32 -0
  34. package/tests/expected/model/tea_python_tests/models/_my_model_subarraymodel.py +24 -0
  35. package/tests/expected/model/tea_python_tests/models/_my_model_submodel.py +45 -0
  36. package/tests/expected/model/tea_python_tests/models/_my_model_submodel_model.py +32 -0
  37. package/tests/expected/multi/tea_python_tests/api.py +0 -2
  38. package/tests/expected/multi/tea_python_tests/api_models/__init__.py +11 -0
  39. package/tests/expected/{python3/annotation/tea_python_tests/models.py → multi/tea_python_tests/api_models/_test_model_dir_2.py} +7 -9
  40. package/tests/expected/multi/tea_python_tests/client.py +0 -2
  41. package/tests/expected/multi/tea_python_tests/exceptions/__init__.py +13 -0
  42. package/tests/{output/complex/tea_python_tests/exceptions.py → expected/multi/tea_python_tests/exceptions/_err.py} +10 -11
  43. package/tests/expected/multi/tea_python_tests/model/user_exceptions/__init__.py +15 -0
  44. package/tests/expected/multi/tea_python_tests/model/user_exceptions/_err.py +22 -0
  45. package/tests/expected/multi/tea_python_tests/model/{user_exceptions.py → user_exceptions/_err_1.py} +3 -32
  46. package/tests/expected/multi/tea_python_tests/model/user_exceptions/_err_2.py +18 -0
  47. package/tests/expected/multi/tea_python_tests/model/user_models/__init__.py +13 -0
  48. package/tests/expected/multi/tea_python_tests/model/user_models/_base_info.py +72 -0
  49. package/tests/expected/multi/tea_python_tests/model/{user_models.py → user_models/_info.py} +3 -69
  50. package/tests/expected/multi/tea_python_tests/models/__init__.py +13 -0
  51. package/tests/expected/multi/tea_python_tests/models/_test_model_dir.py +79 -0
  52. package/tests/expected/{python2/empty/tea_python_tests/client.py → typedef/tea_python_tests/models/__init__.py} +9 -3
  53. package/tests/{output/typedef/tea_python_tests/models.py → expected/typedef/tea_python_tests/models/_m.py} +1 -1
  54. package/tests/fixtures/multi/api.dara +4 -0
  55. package/tests/fixtures/multi/main.dara +18 -0
  56. package/tests/main.tests.js +194 -219
  57. package/tests/output/annotation/tea_python_tests/models/__init__.py +11 -0
  58. package/tests/output/annotation/tea_python_tests/{models.py → models/_test.py} +1 -1
  59. package/tests/output/comment/tea_python_tests/models/__init__.py +15 -0
  60. package/tests/output/comment/tea_python_tests/models/_test_1.py +91 -0
  61. package/tests/output/comment/tea_python_tests/models/_test_2.py +55 -0
  62. package/tests/output/comment/tea_python_tests/models/_test_3.py +61 -0
  63. package/tests/output/complex/tea_python_tests/client.py +6 -6
  64. package/tests/output/complex/tea_python_tests/exceptions/__init__.py +13 -0
  65. package/tests/output/complex/tea_python_tests/exceptions/_err_1.py +23 -0
  66. package/tests/output/complex/tea_python_tests/exceptions/_err_2.py +22 -0
  67. package/tests/output/complex/tea_python_tests/models/__init__.py +19 -0
  68. package/tests/{expected/complex/tea_python_tests/models.py → output/complex/tea_python_tests/models/_complex_request.py} +12 -141
  69. package/tests/output/complex/tea_python_tests/models/_complex_request_configs.py +47 -0
  70. package/tests/output/complex/tea_python_tests/models/_complex_request_header.py +42 -0
  71. package/tests/output/complex/tea_python_tests/models/_complex_request_part.py +33 -0
  72. package/tests/output/complex/tea_python_tests/models/_response.py +33 -0
  73. package/tests/output/model/tea_python_tests/exceptions/__init__.py +11 -0
  74. package/tests/output/model/tea_python_tests/{exceptions.py → exceptions/_main_file.py} +1 -1
  75. package/tests/output/model/tea_python_tests/models/__init__.py +33 -0
  76. package/tests/output/model/tea_python_tests/models/_class.py +24 -0
  77. package/tests/output/model/tea_python_tests/models/_m.py +38 -0
  78. package/tests/output/model/tea_python_tests/models/_main_file_model.py +45 -0
  79. package/tests/output/model/tea_python_tests/models/_main_file_model_model.py +32 -0
  80. package/tests/output/model/tea_python_tests/models/_model.py +32 -0
  81. package/tests/output/model/tea_python_tests/models/_msub_m.py +26 -0
  82. package/tests/output/model/tea_python_tests/{models.py → models/_my_model.py} +16 -321
  83. package/tests/output/model/tea_python_tests/models/_my_model_model.py +45 -0
  84. package/tests/output/model/tea_python_tests/models/_my_model_model_model.py +32 -0
  85. package/tests/output/model/tea_python_tests/models/_my_model_subarraymodel.py +24 -0
  86. package/tests/output/model/tea_python_tests/models/_my_model_submodel.py +45 -0
  87. package/tests/output/model/tea_python_tests/models/_my_model_submodel_model.py +32 -0
  88. package/tests/output/multi/tea_python_tests/api.py +0 -2
  89. package/tests/output/multi/tea_python_tests/api_models/__init__.py +11 -0
  90. package/tests/{expected/python2/annotation/tea_python_tests/models.py → output/multi/tea_python_tests/api_models/_test_model_dir_2.py} +12 -11
  91. package/tests/output/multi/tea_python_tests/client.py +0 -2
  92. package/tests/output/multi/tea_python_tests/exceptions/__init__.py +13 -0
  93. package/tests/{expected/complex/tea_python_tests/exceptions.py → output/multi/tea_python_tests/exceptions/_err.py} +10 -11
  94. package/tests/output/multi/tea_python_tests/model/user_exceptions/__init__.py +15 -0
  95. package/tests/output/multi/tea_python_tests/model/user_exceptions/_err.py +22 -0
  96. package/tests/output/multi/tea_python_tests/model/{user_exceptions.py → user_exceptions/_err_1.py} +3 -32
  97. package/tests/output/multi/tea_python_tests/model/user_exceptions/_err_2.py +18 -0
  98. package/tests/output/multi/tea_python_tests/model/user_models/__init__.py +13 -0
  99. package/tests/output/multi/tea_python_tests/model/user_models/_base_info.py +72 -0
  100. package/tests/output/multi/tea_python_tests/model/{user_models.py → user_models/_info.py} +3 -69
  101. package/tests/output/multi/tea_python_tests/models/__init__.py +13 -0
  102. package/tests/output/multi/tea_python_tests/models/_test_model_dir.py +79 -0
  103. package/tests/{expected/python2/model/tea_python_tests/client.py → output/typedef/tea_python_tests/models/__init__.py} +9 -3
  104. package/tests/{expected/typedef/tea_python_tests/models.py → output/typedef/tea_python_tests/models/_m.py} +1 -1
  105. package/tests/expected/comment/tea_python_tests/models.py +0 -195
  106. package/tests/expected/python2/alias/setup.py +0 -79
  107. package/tests/expected/python2/alias/tea_python_tests/client.py +0 -23
  108. package/tests/expected/python2/annotation/tea_python_tests/client.py +0 -54
  109. package/tests/expected/python2/api/tea_python_tests/client.py +0 -54
  110. package/tests/expected/python2/comment/tea_python_tests/client.py +0 -188
  111. package/tests/expected/python2/comment/tea_python_tests/models.py +0 -146
  112. package/tests/expected/python2/complex/tea_python_tests/client.py +0 -301
  113. package/tests/expected/python2/complex/tea_python_tests/models.py +0 -315
  114. package/tests/expected/python2/const/tea_python_tests/client.py +0 -14
  115. package/tests/expected/python2/empty/setup.py +0 -76
  116. package/tests/expected/python2/exec/tea_python_tests/exec_client.py +0 -16
  117. package/tests/expected/python2/function/tea_python_tests/client.py +0 -47
  118. package/tests/expected/python2/import/setup.py +0 -85
  119. package/tests/expected/python2/import/tea_python_tests/client.py +0 -24
  120. package/tests/expected/python2/map/tea_python_tests/client.py +0 -19
  121. package/tests/expected/python2/model/tea_python_tests/models.py +0 -575
  122. package/tests/expected/python2/statements/tea_python_tests/client.py +0 -64
  123. package/tests/expected/python2/super/tea_python_tests/client.py +0 -8
  124. package/tests/expected/python2/typedef/setup.py +0 -85
  125. package/tests/expected/python2/typedef/tea_python_tests/client.py +0 -38
  126. package/tests/expected/python2/typedef/tea_python_tests/models.py +0 -35
  127. package/tests/expected/python3/alias/setup.py +0 -77
  128. package/tests/expected/python3/alias/tea_python_tests/client.py +0 -32
  129. package/tests/expected/python3/annotation/tea_python_tests/client.py +0 -88
  130. package/tests/expected/python3/api/tea_python_tests/client.py +0 -92
  131. package/tests/expected/python3/comment/tea_python_tests/__init__.py +0 -1
  132. package/tests/expected/python3/comment/tea_python_tests/client.py +0 -319
  133. package/tests/expected/python3/comment/tea_python_tests/models.py +0 -163
  134. package/tests/expected/python3/complex/tea_python_tests/__init__.py +0 -1
  135. package/tests/expected/python3/complex/tea_python_tests/client.py +0 -514
  136. package/tests/expected/python3/complex/tea_python_tests/models.py +0 -349
  137. package/tests/expected/python3/const/tea_python_tests/__init__.py +0 -1
  138. package/tests/expected/python3/const/tea_python_tests/client.py +0 -9
  139. package/tests/expected/python3/empty/setup.py +0 -74
  140. package/tests/expected/python3/empty/tea_python_tests/__init__.py +0 -1
  141. package/tests/expected/python3/empty/tea_python_tests/client.py +0 -5
  142. package/tests/expected/python3/exec/tea_python_tests/__init__.py +0 -1
  143. package/tests/expected/python3/exec/tea_python_tests/exec_client.py +0 -20
  144. package/tests/expected/python3/function/tea_python_tests/__init__.py +0 -1
  145. package/tests/expected/python3/function/tea_python_tests/client.py +0 -67
  146. package/tests/expected/python3/import/setup.py +0 -77
  147. package/tests/expected/python3/import/tea_python_tests/__init__.py +0 -1
  148. package/tests/expected/python3/import/tea_python_tests/client.py +0 -28
  149. package/tests/expected/python3/map/tea_python_tests/__init__.py +0 -1
  150. package/tests/expected/python3/map/tea_python_tests/client.py +0 -22
  151. package/tests/expected/python3/model/tea_python_tests/__init__.py +0 -1
  152. package/tests/expected/python3/model/tea_python_tests/models.py +0 -631
  153. package/tests/expected/python3/statements/tea_python_tests/__init__.py +0 -1
  154. package/tests/expected/python3/statements/tea_python_tests/client.py +0 -83
  155. package/tests/expected/python3/super/tea_python_tests/__init__.py +0 -1
  156. package/tests/expected/python3/super/tea_python_tests/client.py +0 -13
  157. package/tests/expected/python3/typedef/setup.py +0 -77
  158. package/tests/expected/python3/typedef/tea_python_tests/__init__.py +0 -1
  159. package/tests/expected/python3/typedef/tea_python_tests/client.py +0 -72
  160. package/tests/expected/python3/typedef/tea_python_tests/models.py +0 -39
  161. package/tests/output/comment/tea_python_tests/models.py +0 -195
  162. /package/tests/expected/{python2/alias → multi}/tea_python_tests/__init__.py +0 -0
  163. /package/tests/{expected/python2/annotation → output/alias}/tea_python_tests/__init__.py +0 -0
  164. /package/tests/{expected/python2/api → output/annotation}/tea_python_tests/__init__.py +0 -0
  165. /package/tests/{expected/python2/comment → output/api}/tea_python_tests/__init__.py +0 -0
  166. /package/tests/{expected/python2/complex → output/builtin}/tea_python_tests/__init__.py +0 -0
  167. /package/tests/{expected/python2/const → output/comment}/tea_python_tests/__init__.py +0 -0
  168. /package/tests/{expected/python2/empty → output/complex}/tea_python_tests/__init__.py +0 -0
  169. /package/tests/{expected/python2/exec → output/const}/tea_python_tests/__init__.py +0 -0
  170. /package/tests/{expected/python2/function → output/empty}/tea_python_tests/__init__.py +0 -0
  171. /package/tests/{expected/python2/import → output/exec}/tea_python_tests/__init__.py +0 -0
  172. /package/tests/{expected/python2/map → output/function}/tea_python_tests/__init__.py +0 -0
  173. /package/tests/{expected/python2/model → output/import}/tea_python_tests/__init__.py +0 -0
  174. /package/tests/{expected/python2/statements → output/map}/tea_python_tests/__init__.py +0 -0
  175. /package/tests/{expected/python2/super → output/model}/tea_python_tests/__init__.py +0 -0
  176. /package/tests/{expected/python2/typedef → output/multi}/tea_python_tests/__init__.py +0 -0
  177. /package/tests/{expected/python3/alias → output/statements}/tea_python_tests/__init__.py +0 -0
  178. /package/tests/{expected/python3/annotation → output/super}/tea_python_tests/__init__.py +0 -0
  179. /package/tests/{expected/python3/api → output/typedef}/tea_python_tests/__init__.py +0 -0
@@ -14,7 +14,33 @@ const expectedDir = path.join(__dirname, 'expected/');
14
14
  const fixturesDir = path.join(__dirname, 'fixtures/');
15
15
  const outputDir = path.join(__dirname, 'output/');
16
16
 
17
- function check(moduleName, expectedFiles = [], option = {}) {
17
+ function compareDirectories(expectedDir, outputDir) {
18
+ const expectedFiles = fs.readdirSync(expectedDir);
19
+ const outputFiles = fs.readdirSync(outputDir);
20
+ for (let fileName of expectedFiles) {
21
+ if (!outputFiles.includes(fileName)) {
22
+ assert.ok(false);
23
+ }
24
+ const expectedPath = path.join(outputDir, fileName);
25
+ const actualPath = path.join(expectedDir, fileName);
26
+ const expectedStat = fs.statSync(expectedPath);
27
+ const actualStat = fs.statSync(actualPath);
28
+
29
+ // 如果两个文件都是文件夹,则递归进行比较
30
+ if (expectedStat.isDirectory() && actualStat.isDirectory()) {
31
+ compareDirectories(expectedPath, actualPath);
32
+ }
33
+ // 如果是文件,则比较文件内容
34
+ else if (expectedStat.isFile() && actualStat.isFile()) {
35
+ const expectedContent = fs.readFileSync(expectedPath, 'utf8');
36
+ const acutalContent = fs.readFileSync(actualPath, 'utf8');
37
+
38
+ assert.deepStrictEqual(expectedContent, acutalContent);
39
+ }
40
+ }
41
+ }
42
+
43
+ function check(moduleName, expectedDir, option = {}) {
18
44
  const mainFilePath = path.join(fixturesDir, moduleName, 'main.dara') ? path.join(fixturesDir, moduleName, 'main.dara') : path.join(fixturesDir, moduleName, 'main.tea');
19
45
  const moduleOutputDir = path.join(outputDir, moduleName);
20
46
  const prefixDir = path.join(fixturesDir, moduleName);
@@ -34,195 +60,158 @@ function check(moduleName, expectedFiles = [], option = {}) {
34
60
  const dsl = fs.readFileSync(mainFilePath, 'utf8');
35
61
  const ast = DSL.parse(dsl, mainFilePath);
36
62
  generator.visit(ast);
37
- expectedFiles.forEach(element => {
38
- const outputFilePath = path.join(outputDir, moduleName, element);
39
- const expectedFilePath = path.join(expectedDir, moduleName, element);
40
- const expected = fs.readFileSync(expectedFilePath, 'utf8');
41
- assert.deepStrictEqual(fs.readFileSync(outputFilePath, 'utf8'), expected);
42
- });
63
+ compareDirectories(path.join(__dirname, 'expected', moduleName, expectedDir), path.join(moduleOutputDir, expectedDir));
43
64
  }
44
65
 
45
66
  describe('Python Generator', function () {
46
67
 
47
68
  it('multi should ok', function () {
48
- check('multi', [
49
- 'tea_python_tests/client.py',
50
- 'tea_python_tests/api.py',
51
- 'tea_python_tests/lib/util.py',
52
- 'tea_python_tests/model/user.py',
53
- 'tea_python_tests/model/user_exceptions.py',
54
- 'tea_python_tests/model/user_models.py',
55
- ],
56
- {
57
- python: {
58
- package: 'tea_python_tests',
59
- clientName: 'client'
60
- }
61
- });
69
+ check('multi', 'tea_python_tests',
70
+ {
71
+ python: {
72
+ package: 'tea_python_tests',
73
+ clientName: 'client'
74
+ }
75
+ });
62
76
  });
63
77
 
64
78
 
65
79
  it('complex should ok', function () {
66
- check('complex', [
67
- 'tea_python_tests/client.py',
68
- 'tea_python_tests/models.py'
69
- ],
70
- {
71
- python: {
72
- package: 'tea_python_tests',
73
- clientName: 'client'
74
- }
75
- });
80
+ check('complex', 'tea_python_tests',
81
+ {
82
+ python: {
83
+ package: 'tea_python_tests',
84
+ clientName: 'client'
85
+ }
86
+ });
76
87
  });
77
88
 
78
89
  it('model should ok', function () {
79
- check('model', [
80
- 'tea_python_tests/client.py',
81
- 'tea_python_tests/exceptions.py',
82
- 'tea_python_tests/models.py'
83
- ],
84
- {
85
- python: {
86
- package: 'tea_python_tests',
87
- clientName: 'client',
88
- additionalPackage: [
89
- {
90
- from: '__future__',
91
- import: 'annotations'
92
- }
93
- ]
94
- }
95
- });
90
+ check('model', 'tea_python_tests',
91
+ {
92
+ python: {
93
+ package: 'tea_python_tests',
94
+ clientName: 'client',
95
+ additionalPackage: [
96
+ {
97
+ from: '__future__',
98
+ import: 'annotations'
99
+ }
100
+ ]
101
+ }
102
+ });
96
103
  });
97
104
 
98
105
  it('map should ok', function () {
99
- check('map', [
100
- 'tea_python_tests/client.py'
101
- ],
102
- {
103
- python: {
104
- package: 'tea_python_tests',
105
- clientName: 'client'
106
- }
107
- });
106
+ check('map', 'tea_python_tests',
107
+ {
108
+ python: {
109
+ package: 'tea_python_tests',
110
+ clientName: 'client'
111
+ }
112
+ });
108
113
  });
109
114
 
110
115
  it('builtin should ok', function () {
111
- check('builtin', [
112
- 'tea_python_tests/client.py'
113
- ],
114
- {
115
- exec: true,
116
- python: {
117
- package: 'tea_python_tests',
118
- clientName: 'client'
119
- }
120
- });
116
+ check('builtin', 'tea_python_tests',
117
+ {
118
+ exec: true,
119
+ python: {
120
+ package: 'tea_python_tests',
121
+ clientName: 'client'
122
+ }
123
+ });
121
124
  });
122
125
 
123
126
  it('exec should ok', function () {
124
- check('exec', [
125
- 'tea_python_tests/exec_client.py'
126
- ],
127
- {
128
- exec: true,
129
- python: {
130
- package: 'tea_python_tests',
131
- clientName: 'exec_client'
132
- }
133
- });
127
+ check('exec', 'tea_python_tests',
128
+ {
129
+ exec: true,
130
+ python: {
131
+ package: 'tea_python_tests',
132
+ clientName: 'exec_client'
133
+ }
134
+ });
134
135
  });
135
136
 
136
137
  it('alias should ok', function () {
137
- check('alias', [
138
- 'tea_python_tests/client.py'
139
- ],
140
- {
141
- python: {
142
- package: 'tea_python_tests',
143
- clientName: 'client',
144
- packageInfo: {
145
- name: 'tea_python_tests',
146
- desc: 'Generate setup.py',
147
- github: 'https://github.com/',
148
- author: 'Alibaba',
149
- email: 'sdk-team@alibabacloud.com'
138
+ check('alias', 'tea_python_tests',
139
+ {
140
+ python: {
141
+ package: 'tea_python_tests',
142
+ clientName: 'client',
143
+ packageInfo: {
144
+ name: 'tea_python_tests',
145
+ desc: 'Generate setup.py',
146
+ github: 'https://github.com/',
147
+ author: 'Alibaba',
148
+ email: 'sdk-team@alibabacloud.com'
149
+ }
150
150
  }
151
- }
152
- });
151
+ });
153
152
  });
154
153
 
155
154
  it('const should ok', function () {
156
- check('const', [
157
- 'tea_python_tests/client.py'
158
- ],
159
- {
160
- python: {
161
- package: 'tea_python_tests',
162
- clientName: 'client'
163
- }
164
- });
155
+ check('const', 'tea_python_tests',
156
+ {
157
+ python: {
158
+ package: 'tea_python_tests',
159
+ clientName: 'client'
160
+ }
161
+ });
165
162
  });
166
163
 
167
164
  it('statements should ok', function () {
168
- check('statements', [
169
- 'tea_python_tests/client.py'
170
- ],
171
- {
172
- python: {
173
- package: 'tea_python_tests',
174
- clientName: 'client'
175
- }
176
- });
165
+ check('statements', 'tea_python_tests',
166
+ {
167
+ python: {
168
+ package: 'tea_python_tests',
169
+ clientName: 'client'
170
+ }
171
+ });
177
172
  });
178
173
 
179
174
  it('function should ok', function () {
180
- check('function', [
181
- 'tea_python_tests/client.py'
182
- ],
183
- {
184
- python: {
185
- package: 'tea_python_tests',
186
- clientName: 'client'
187
- }
188
- });
175
+ check('function', 'tea_python_tests',
176
+ {
177
+ python: {
178
+ package: 'tea_python_tests',
179
+ clientName: 'client'
180
+ }
181
+ });
189
182
  });
190
183
 
191
184
  it('api should ok', function () {
192
- check('api', [
193
- 'tea_python_tests/client.py'
194
- ],
195
- {
196
- python: {
197
- package: 'tea_python_tests',
198
- clientName: 'client'
199
- }
200
- });
185
+ check('api', 'tea_python_tests',
186
+ {
187
+ python: {
188
+ package: 'tea_python_tests',
189
+ clientName: 'client'
190
+ }
191
+ });
201
192
  });
202
193
 
203
194
  it('import should ok', function () {
204
- check('import', [
205
- 'tea_python_tests/client.py'
206
- ],
207
- {
208
- python: {
209
- package: 'tea_python_tests',
210
- clientName: 'client',
211
- packageInfo: {
212
- name: 'tea_python_tests',
213
- desc: 'Generate setup.py',
214
- github: 'https://github.com/',
215
- author: 'Alibaba',
216
- email: 'sdk-team@alibabacloud.com'
217
- },
218
- additionalPackage: [
219
- {
220
- from: '__future__',
221
- import: 'annotations'
222
- }
223
- ]
224
- }
225
- });
195
+ check('import', 'tea_python_tests',
196
+ {
197
+ python: {
198
+ package: 'tea_python_tests',
199
+ clientName: 'client',
200
+ packageInfo: {
201
+ name: 'tea_python_tests',
202
+ desc: 'Generate setup.py',
203
+ github: 'https://github.com/',
204
+ author: 'Alibaba',
205
+ email: 'sdk-team@alibabacloud.com'
206
+ },
207
+ additionalPackage: [
208
+ {
209
+ from: '__future__',
210
+ import: 'annotations'
211
+ }
212
+ ]
213
+ }
214
+ });
226
215
  const expected = fs.readFileSync(path.join(expectedDir, 'import', 'setup.py'), 'utf8');
227
216
  const output = fs.readFileSync(path.join(outputDir, 'import', 'setup.py'), 'utf8');
228
217
  assert.deepStrictEqual(output.replace(new RegExp('\\d{2}\\/\\d{2}\\/\\d{4}'), '*'), expected);
@@ -231,38 +220,29 @@ describe('Python Generator', function () {
231
220
 
232
221
 
233
222
  it('add annotation should ok', function () {
234
- check('annotation', [
235
- 'tea_python_tests/client.py',
236
- 'tea_python_tests/models.py'
237
- ],
238
- {
239
- python: {
240
- package: 'tea_python_tests',
241
- clientName: 'client'
242
- }
243
- });
223
+ check('annotation', 'tea_python_tests',
224
+ {
225
+ python: {
226
+ package: 'tea_python_tests',
227
+ clientName: 'client'
228
+ }
229
+ });
244
230
  });
245
231
 
246
232
  it('add comments should ok', function () {
247
- check('comment', [
248
- 'tea_python_tests/client.py',
249
- 'tea_python_tests/models.py'
250
- ],
251
- {
252
- python: {
253
- package: 'tea_python_tests',
254
- clientName: 'client'
255
- }
256
- });
233
+ check('comment', 'tea_python_tests',
234
+ {
235
+ python: {
236
+ package: 'tea_python_tests',
237
+ clientName: 'client'
238
+ }
239
+ });
257
240
  });
258
241
 
259
242
 
260
243
 
261
244
  it('empty should ok', function () {
262
- check('empty', [
263
- 'tea_python_tests/client.py',
264
- // '.gitignore'
265
- ],
245
+ check('empty', 'tea_python_tests',
266
246
  {
267
247
  python: {
268
248
  package: 'tea_python_tests',
@@ -281,57 +261,52 @@ describe('Python Generator', function () {
281
261
 
282
262
 
283
263
  it('super should ok', function () {
284
- check('super', [
285
- 'tea_python_tests/client.py'
286
- ],
287
- {
288
- python: {
289
- package: 'tea_python_tests',
290
- clientName: 'client'
291
- }
292
- });
264
+ check('super', 'tea_python_tests',
265
+ {
266
+ python: {
267
+ package: 'tea_python_tests',
268
+ clientName: 'client'
269
+ }
270
+ });
293
271
  });
294
272
 
295
273
 
296
274
  it('typedef should ok', function () {
297
- check('typedef', [
298
- 'tea_python_tests/client.py',
299
- 'tea_python_tests/models.py'
300
- ],
301
- {
302
- python: {
303
- package: 'tea_python_tests',
304
- clientName: 'client',
305
- packageInfo: {
306
- name: 'tea_python_tests',
307
- desc: 'Generate setup.py',
308
- github: 'https://github.com/',
309
- author: 'Alibaba',
310
- email: 'sdk-team@alibabacloud.com'
311
- },
312
- typedef: {
313
- HttpResponse: {
314
- import: 'requests',
315
- type: 'Response',
316
- package: 'requests:2.21.0'
317
- },
318
- HttpHeader: {
319
- import: null,
320
- type: 'Dict[str, Any]',
321
- package: null
275
+ check('typedef', 'tea_python_tests',
276
+ {
277
+ python: {
278
+ package: 'tea_python_tests',
279
+ clientName: 'client',
280
+ packageInfo: {
281
+ name: 'tea_python_tests',
282
+ desc: 'Generate setup.py',
283
+ github: 'https://github.com/',
284
+ author: 'Alibaba',
285
+ email: 'sdk-team@alibabacloud.com'
322
286
  },
323
- TeaModel: {
324
- import: 'Tea.model',
325
- type: 'TeaModel',
326
- package: 'alibabacloud-tea:0.2.9'
327
- },
328
- TeaException: {
329
- import: 'Tea.exceptions',
330
- type: 'TeaException',
331
- package: 'alibabacloud-tea:0.2.9'
287
+ typedef: {
288
+ HttpResponse: {
289
+ import: 'requests',
290
+ type: 'Response',
291
+ package: 'requests:2.21.0'
292
+ },
293
+ HttpHeader: {
294
+ import: null,
295
+ type: 'Dict[str, Any]',
296
+ package: null
297
+ },
298
+ TeaModel: {
299
+ import: 'Tea.model',
300
+ type: 'TeaModel',
301
+ package: 'alibabacloud-tea:0.2.9'
302
+ },
303
+ TeaException: {
304
+ import: 'Tea.exceptions',
305
+ type: 'TeaException',
306
+ package: 'alibabacloud-tea:0.2.9'
307
+ }
332
308
  }
333
309
  }
334
- }
335
- });
310
+ });
336
311
  });
337
312
  });
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This file is auto-generated, don't edit it. Thanks.
3
+ from __future__ import annotations
4
+
5
+
6
+
7
+ from ._test import Test
8
+
9
+ __all__ = [
10
+ Test
11
+ ]
@@ -10,7 +10,7 @@ from darabonba.model import DaraModel
10
10
  """
11
11
  class Test(DaraModel):
12
12
  def __init__(
13
- self,
13
+ self, *,
14
14
  test: str = None,
15
15
  ):
16
16
  # Alichange app id
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This file is auto-generated, don't edit it. Thanks.
3
+ from __future__ import annotations
4
+
5
+
6
+
7
+ from ._test_1 import Test1
8
+ from ._test_2 import Test2
9
+ from ._test_3 import Test3
10
+
11
+ __all__ = [
12
+ Test1,
13
+ Test2,
14
+ Test3
15
+ ]
@@ -0,0 +1,91 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This file is auto-generated, don't edit it. Thanks.
3
+ from __future__ import annotations
4
+ from darabonba.model import DaraModel
5
+ from typing import List
6
+
7
+
8
+ # import comment
9
+
10
+
11
+ """
12
+ * @remarks
13
+ * TestModel
14
+ """
15
+ class Test1(DaraModel):
16
+ def __init__(
17
+ self, *,
18
+ test: str = None,
19
+ # odel的test back comment
20
+ test_2: str = None,
21
+ # odel的test2 back comment
22
+ test_3: List[List[str]] = None,
23
+ test_5: str = None,
24
+ sts: str = None,
25
+ a_sts: str = None,
26
+ ):
27
+ # test desc
28
+ self.test = test
29
+ # odel的test back comment
30
+ # test2 desc
31
+ self.test_2 = test_2
32
+ # odel的test2 back comment
33
+ # test3 desc
34
+ self.test_3 = test_3
35
+ # test desc
36
+ self.test_5 = test_5
37
+ # sts desc
38
+ self.sts = sts
39
+ # asts desc
40
+ self.a_sts = a_sts
41
+
42
+ def validate(self):
43
+ self.validate_required(self.test, 'test')
44
+ # odel的test back comment
45
+ self.validate_required(self.test_2, 'test_2')
46
+ # odel的test2 back comment
47
+ self.validate_required(self.test_3, 'test_3')
48
+ self.validate_required(self.test_5, 'test_5')
49
+ self.validate_required(self.sts, 'sts')
50
+ self.validate_required(self.a_sts, 'a_sts')
51
+
52
+ def to_map(self):
53
+ _map = super().to_map()
54
+ if _map is not None:
55
+ return _map
56
+
57
+ result = dict()
58
+ if self.test is not None:
59
+ result['test'] = self.test
60
+ # odel的test back comment
61
+ if self.test_2 is not None:
62
+ result['test2'] = self.test_2
63
+ # odel的test2 back comment
64
+ if self.test_3 is not None:
65
+ result['test3'] = self.test_3
66
+ if self.test_5 is not None:
67
+ result['test5'] = self.test_5
68
+ if self.sts is not None:
69
+ result['sts'] = self.sts
70
+ if self.a_sts is not None:
71
+ result['asts'] = self.a_sts
72
+ return result
73
+
74
+ def from_map(self, m: dict = None):
75
+ m = m or dict()
76
+ if m.get('test') is not None:
77
+ self.test = m.get('test')
78
+ # odel的test back comment
79
+ if m.get('test2') is not None:
80
+ self.test_2 = m.get('test2')
81
+ # odel的test2 back comment
82
+ if m.get('test3') is not None:
83
+ self.test_3 = m.get('test3')
84
+ if m.get('test5') is not None:
85
+ self.test_5 = m.get('test5')
86
+ if m.get('sts') is not None:
87
+ self.sts = m.get('sts')
88
+ if m.get('asts') is not None:
89
+ self.a_sts = m.get('asts')
90
+ return self
91
+
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This file is auto-generated, don't edit it. Thanks.
3
+ from __future__ import annotations
4
+ from darabonba.model import DaraModel
5
+
6
+
7
+ """
8
+ * @remarks
9
+ * TestModel2
10
+ """
11
+ class Test2(DaraModel):
12
+ def __init__(
13
+ self, *,
14
+ # model的test front comment
15
+ test: str = None,
16
+ # model的test front comment
17
+ test_2: str = None,
18
+ ):
19
+ # model的test front comment
20
+ # test desc
21
+ self.test = test
22
+ # model的test front comment
23
+ # test2 desc
24
+ self.test_2 = test_2
25
+
26
+ def validate(self):
27
+ # model的test front comment
28
+ self.validate_required(self.test, 'test')
29
+ # model的test front comment
30
+ self.validate_required(self.test_2, 'test_2')
31
+
32
+ def to_map(self):
33
+ _map = super().to_map()
34
+ if _map is not None:
35
+ return _map
36
+
37
+ result = dict()
38
+ # model的test front comment
39
+ if self.test is not None:
40
+ result['test'] = self.test
41
+ # model的test front comment
42
+ if self.test_2 is not None:
43
+ result['test2'] = self.test_2
44
+ return result
45
+
46
+ def from_map(self, m: dict = None):
47
+ m = m or dict()
48
+ # model的test front comment
49
+ if m.get('test') is not None:
50
+ self.test = m.get('test')
51
+ # model的test front comment
52
+ if m.get('test2') is not None:
53
+ self.test_2 = m.get('test2')
54
+ return self
55
+