@darabonba/python-generator 1.2.19 → 2.0.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.
- package/ChangeLog.md +0 -158
- package/lib/builtin.js +818 -0
- package/lib/generator.js +2704 -0
- package/lib/helper.js +422 -0
- package/package.json +6 -5
- package/tests/expected/alias/setup.py +79 -0
- package/tests/expected/alias/tea_python_tests/__init__.py +1 -0
- package/tests/expected/alias/tea_python_tests/client.py +35 -0
- package/tests/expected/annotation/tea_python_tests/__init__.py +1 -0
- package/tests/expected/annotation/tea_python_tests/client.py +93 -0
- package/tests/expected/annotation/tea_python_tests/models.py +37 -0
- package/tests/expected/api/tea_python_tests/__init__.py +1 -0
- package/tests/expected/api/tea_python_tests/client.py +106 -0
- package/tests/expected/builtin/tea_python_tests/client.py +685 -0
- package/tests/expected/comment/tea_python_tests/__init__.py +1 -0
- package/tests/expected/comment/tea_python_tests/client.py +288 -0
- package/tests/expected/comment/tea_python_tests/models.py +195 -0
- package/tests/expected/complex/tea_python_tests/__init__.py +1 -0
- package/tests/expected/complex/tea_python_tests/client.py +1168 -0
- package/tests/expected/complex/tea_python_tests/exceptions.py +39 -0
- package/tests/expected/complex/tea_python_tests/models.py +570 -0
- package/tests/expected/const/tea_python_tests/__init__.py +1 -0
- package/tests/expected/const/tea_python_tests/client.py +14 -0
- package/tests/expected/empty/setup.py +74 -0
- package/tests/expected/empty/tea_python_tests/__init__.py +1 -0
- package/tests/expected/empty/tea_python_tests/client.py +10 -0
- package/tests/expected/exec/tea_python_tests/__init__.py +1 -0
- package/tests/expected/exec/tea_python_tests/exec_client.py +21 -0
- package/tests/expected/function/tea_python_tests/__init__.py +1 -0
- package/tests/expected/function/tea_python_tests/client.py +64 -0
- package/tests/expected/import/setup.py +78 -0
- package/tests/expected/import/tea_python_tests/__init__.py +1 -0
- package/tests/expected/import/tea_python_tests/client.py +29 -0
- package/tests/expected/map/tea_python_tests/__init__.py +1 -0
- package/tests/expected/map/tea_python_tests/client.py +39 -0
- package/tests/expected/model/tea_python_tests/__init__.py +1 -0
- package/tests/expected/model/tea_python_tests/client.py +10 -0
- package/tests/expected/model/tea_python_tests/exceptions.py +28 -0
- package/tests/expected/model/tea_python_tests/models.py +780 -0
- package/tests/expected/multi/tea_python_tests/api.py +95 -0
- package/tests/expected/multi/tea_python_tests/client.py +40 -0
- package/tests/expected/multi/tea_python_tests/lib/util.py +19 -0
- package/tests/expected/multi/tea_python_tests/model/user.py +23 -0
- package/tests/expected/multi/tea_python_tests/model/user_exceptions.py +83 -0
- package/tests/expected/multi/tea_python_tests/model/user_models.py +145 -0
- package/tests/expected/statements/tea_python_tests/__init__.py +1 -0
- package/tests/expected/statements/tea_python_tests/client.py +86 -0
- package/tests/expected/super/tea_python_tests/__init__.py +1 -0
- package/tests/expected/super/tea_python_tests/client.py +16 -0
- package/tests/expected/typedef/setup.py +77 -0
- package/tests/expected/typedef/tea_python_tests/__init__.py +1 -0
- package/tests/expected/typedef/tea_python_tests/client.py +74 -0
- package/tests/expected/typedef/tea_python_tests/models.py +42 -0
- package/tests/fixtures/alias/Darafile +11 -0
- package/tests/fixtures/alias/libraries/Alias/Darafile +11 -0
- package/tests/fixtures/alias/libraries/Alias-Symbol/Darafile +11 -0
- package/tests/fixtures/builtin/Darafile +6 -0
- package/tests/fixtures/builtin/main.dara +333 -0
- package/tests/fixtures/complex/libraries/import.dara +18 -11
- package/tests/fixtures/complex/main.dara +451 -103
- package/tests/fixtures/import/libraries/Darafile +1 -1
- package/tests/fixtures/import/pack/Darafile +3 -0
- package/tests/fixtures/map/libraries/Darafile +3 -0
- package/tests/fixtures/map/libraries/import.dara +4 -0
- package/tests/fixtures/map/main.dara +17 -2
- package/tests/fixtures/model/.libraries.json +3 -0
- package/tests/fixtures/model/Darafile +5 -2
- package/tests/fixtures/model/libraries/Darafile +20 -0
- package/tests/fixtures/model/libraries/import.dara +27 -0
- package/tests/fixtures/model/main.dara +60 -42
- package/tests/fixtures/multi/.libraries.json +3 -0
- package/tests/fixtures/multi/Darafile +12 -0
- package/tests/fixtures/multi/api.dara +20 -0
- package/tests/fixtures/multi/lib/util.dara +5 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/Teafile +62 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/main.tea +244 -0
- package/tests/fixtures/multi/main.dara +32 -0
- package/tests/fixtures/multi/model/user.dara +33 -0
- package/tests/{python3.tests.js → main.tests.js} +107 -65
- package/tests/output/alias/setup.py +79 -0
- package/tests/output/alias/tea_python_tests/client.py +35 -0
- package/tests/output/annotation/setup.py +77 -0
- package/tests/output/annotation/tea_python_tests/client.py +93 -0
- package/tests/output/annotation/tea_python_tests/models.py +37 -0
- package/tests/output/api/setup.py +77 -0
- package/tests/output/api/tea_python_tests/client.py +106 -0
- package/tests/output/builtin/setup.py +77 -0
- package/tests/output/builtin/tea_python_tests/client.py +685 -0
- package/tests/output/comment/setup.py +77 -0
- package/tests/output/comment/tea_python_tests/client.py +288 -0
- package/tests/output/comment/tea_python_tests/models.py +195 -0
- package/tests/output/complex/setup.py +77 -0
- package/tests/output/complex/tea_python_tests/client.py +1168 -0
- package/tests/output/complex/tea_python_tests/exceptions.py +39 -0
- package/tests/output/complex/tea_python_tests/models.py +570 -0
- package/tests/output/const/setup.py +77 -0
- package/tests/output/const/tea_python_tests/client.py +14 -0
- package/tests/output/empty/setup.py +77 -0
- package/tests/output/empty/tea_python_tests/client.py +10 -0
- package/tests/output/exec/setup.py +77 -0
- package/tests/output/exec/tea_python_tests/exec_client.py +21 -0
- package/tests/output/function/setup.py +77 -0
- package/tests/output/function/tea_python_tests/client.py +64 -0
- package/tests/output/import/setup.py +78 -0
- package/tests/output/import/tea_python_tests/client.py +29 -0
- package/tests/output/map/setup.py +77 -0
- package/tests/output/map/tea_python_tests/client.py +39 -0
- package/tests/output/model/setup.py +77 -0
- package/tests/output/model/tea_python_tests/client.py +10 -0
- package/tests/output/model/tea_python_tests/exceptions.py +28 -0
- package/tests/output/model/tea_python_tests/models.py +780 -0
- package/tests/output/multi/setup.py +77 -0
- package/tests/output/multi/tea_python_tests/api.py +95 -0
- package/tests/output/multi/tea_python_tests/client.py +40 -0
- package/tests/output/multi/tea_python_tests/lib/util.py +19 -0
- package/tests/output/multi/tea_python_tests/model/user.py +23 -0
- package/tests/output/multi/tea_python_tests/model/user_exceptions.py +83 -0
- package/tests/output/multi/tea_python_tests/model/user_models.py +145 -0
- package/tests/output/statements/setup.py +77 -0
- package/tests/output/statements/tea_python_tests/client.py +86 -0
- package/tests/output/super/setup.py +77 -0
- package/tests/output/super/tea_python_tests/client.py +16 -0
- package/tests/output/typedef/setup.py +78 -0
- package/tests/output/typedef/tea_python_tests/client.py +74 -0
- package/tests/output/typedef/tea_python_tests/models.py +42 -0
- package/tests/common.tests.js +0 -244
- package/tests/lib.tests.js +0 -269
- package/tests/python2.tests.js +0 -283
- package/tests/resolver.tests.js +0 -434
package/tests/lib.tests.js
DELETED
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const debug = require('../src/lib/debug');
|
|
5
|
-
const mm = require('mm');
|
|
6
|
-
const expect = require('chai').expect;
|
|
7
|
-
const Emitter = require('../src/lib/emitter');
|
|
8
|
-
require('mocha-sinon');
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
_camelCase,
|
|
12
|
-
_subModelName,
|
|
13
|
-
_string,
|
|
14
|
-
_upperFirst,
|
|
15
|
-
_config,
|
|
16
|
-
_avoidKeywords,
|
|
17
|
-
_avoidFuncKeywords,
|
|
18
|
-
_avoidClassKeywords,
|
|
19
|
-
_avoidVarKeywords,
|
|
20
|
-
_modify,
|
|
21
|
-
_symbol,
|
|
22
|
-
_toSnakeCase,
|
|
23
|
-
_toCamelCase,
|
|
24
|
-
_isSnakeCase
|
|
25
|
-
} = require('../src/lib/helper');
|
|
26
|
-
|
|
27
|
-
describe('debug should be ok', function () {
|
|
28
|
-
beforeEach(function () {
|
|
29
|
-
this.sinon.stub(console, 'log');
|
|
30
|
-
this.sinon.stub(process, 'exit');
|
|
31
|
-
this.sinon.stub(fs, 'mkdirSync');
|
|
32
|
-
this.sinon.stub(fs, 'writeFileSync');
|
|
33
|
-
this.sinon.stub(fs, 'appendFileSync');
|
|
34
|
-
this.sinon.stub(fs, 'existsSync');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('dump should be ok', function () {
|
|
38
|
-
debug.dump(null, 1, '1', 1.11111);
|
|
39
|
-
expect(console.log.calledWith('foo')).to.be.false;
|
|
40
|
-
expect(console.log.calledWith(null)).to.be.true;
|
|
41
|
-
expect(console.log.calledWith(1)).to.be.true;
|
|
42
|
-
expect(console.log.calledWith('1')).to.be.true;
|
|
43
|
-
expect(console.log.calledWith(1.11111)).to.be.true;
|
|
44
|
-
expect(process.exit.calledWith(-1)).to.be.false;
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('halt should be ok', function () {
|
|
48
|
-
debug.halt(null, 1, '1', 1.11111);
|
|
49
|
-
expect(console.log.calledWith('foo')).to.be.false;
|
|
50
|
-
expect(console.log.calledWith(null)).to.be.true;
|
|
51
|
-
expect(console.log.calledWith(1)).to.be.true;
|
|
52
|
-
expect(console.log.calledWith('1')).to.be.true;
|
|
53
|
-
expect(console.log.calledWith(1.11111)).to.be.true;
|
|
54
|
-
expect(process.exit.calledWith(-1)).to.be.true;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('jump should be ok', function () {
|
|
58
|
-
for (let i = 0; i < 3; i++) {
|
|
59
|
-
debug.jump(1, `jump output : ${i}`);
|
|
60
|
-
}
|
|
61
|
-
expect(console.log.calledWith('jump output : 0')).to.be.false;
|
|
62
|
-
expect(console.log.calledWith('jump output : 1')).to.be.true;
|
|
63
|
-
expect(console.log.calledWith('jump output : 2')).to.be.false;
|
|
64
|
-
expect(process.exit.calledWith(-1)).to.be.true;
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('stack should be ok', function () {
|
|
68
|
-
try {
|
|
69
|
-
debug.stack('called debug stack with message', 'data1', 'data2');
|
|
70
|
-
} catch (e) {
|
|
71
|
-
expect(e.message).to.be.eql('called debug stack with message');
|
|
72
|
-
expect(console.log.calledWith('called debug stack with message')).to.be.false;
|
|
73
|
-
expect(console.log.calledWith('data1')).to.be.true;
|
|
74
|
-
expect(console.log.calledWith('data2')).to.be.true;
|
|
75
|
-
expect(process.exit.calledWith(-1)).to.be.false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
debug.stack(1, 'called debug stack without message', 'some data');
|
|
80
|
-
} catch (e) {
|
|
81
|
-
expect(e.message).to.be.eql('');
|
|
82
|
-
expect(console.log.calledWith(1)).to.be.true;
|
|
83
|
-
expect(console.log.calledWith('called debug stack without message')).to.be.true;
|
|
84
|
-
expect(console.log.calledWith('some data')).to.be.true;
|
|
85
|
-
expect(process.exit.calledWith(-1)).to.be.false;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe('emitter should be ok', function () {
|
|
91
|
-
beforeEach(function () {
|
|
92
|
-
this.sinon.stub(console, 'log');
|
|
93
|
-
this.sinon.stub(process, 'exit');
|
|
94
|
-
this.sinon.stub(fs, 'mkdirSync');
|
|
95
|
-
this.sinon.stub(fs, 'writeFileSync');
|
|
96
|
-
this.sinon.stub(fs, 'appendFileSync');
|
|
97
|
-
this.sinon.stub(fs, 'existsSync');
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('indent should be ok', function () {
|
|
101
|
-
const emitter = new Emitter();
|
|
102
|
-
expect(emitter.indent(1)).to.be.eql(' ');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('emit should be ok', function () {
|
|
106
|
-
const emitter = new Emitter();
|
|
107
|
-
emitter.emit('emit some string');
|
|
108
|
-
expect(emitter.output).to.be.eql('emit some string');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('emitln should be ok', function () {
|
|
112
|
-
const emitter = new Emitter();
|
|
113
|
-
emitter.emitln('emitln some string');
|
|
114
|
-
expect(emitter.output).to.be.eql('emitln some string' + emitter.eol);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('emits should be ok', function () {
|
|
118
|
-
const emitter = new Emitter();
|
|
119
|
-
emitter.emits(1);
|
|
120
|
-
expect(emitter.output).to.be.eql('');
|
|
121
|
-
emitter.emits(0, 'row1', 'row2');
|
|
122
|
-
expect(emitter.output).to.be.eql('row1' + emitter.eol + 'row2' + emitter.eol);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('erase should be ok', function () {
|
|
126
|
-
const emitter = new Emitter();
|
|
127
|
-
emitter.emit('full string');
|
|
128
|
-
emitter.erase(3);
|
|
129
|
-
expect(emitter.output).to.be.eql('full str');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('savePath should be ok', function () {
|
|
133
|
-
const emitter = new Emitter({
|
|
134
|
-
dir: '/tmp/',
|
|
135
|
-
layer: 'a.b.c',
|
|
136
|
-
filename: 'filename',
|
|
137
|
-
ext: '.tmp'
|
|
138
|
-
});
|
|
139
|
-
expect(emitter.savePath()).to.be.eql('/tmp/a/b/c/filename.tmp');
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('save should be ok', function () {
|
|
143
|
-
const emitter = new Emitter();
|
|
144
|
-
try {
|
|
145
|
-
emitter.save();
|
|
146
|
-
} catch (e) {
|
|
147
|
-
expect(e.message).to.be.eql('`option.dir` should not be empty');
|
|
148
|
-
}
|
|
149
|
-
emitter.config.dir = '/tmp/';
|
|
150
|
-
try {
|
|
151
|
-
emitter.save();
|
|
152
|
-
} catch (e) {
|
|
153
|
-
expect(e.message).to.be.eql('filename cannot be empty');
|
|
154
|
-
}
|
|
155
|
-
emitter.config.filename = 'filename';
|
|
156
|
-
emitter.config.ext = '.tmp';
|
|
157
|
-
|
|
158
|
-
emitter.emit('test');
|
|
159
|
-
|
|
160
|
-
emitter.save();
|
|
161
|
-
emitter.emit();
|
|
162
|
-
mm(fs, 'existsSync', function (filename) {
|
|
163
|
-
return true;
|
|
164
|
-
});
|
|
165
|
-
emitter.save(true);
|
|
166
|
-
mm.restore();
|
|
167
|
-
|
|
168
|
-
// show emit info
|
|
169
|
-
emitter.config.showInfo = true;
|
|
170
|
-
emitter.emit('test');
|
|
171
|
-
emitter.save();
|
|
172
|
-
const filename = emitter.savePath();
|
|
173
|
-
|
|
174
|
-
expect(filename).to.be.eql('/tmp/filename.tmp');
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe('helper tests', function () {
|
|
179
|
-
it('_upperFirst should be ok', function () {
|
|
180
|
-
expect(_upperFirst(null)).to.be.eql('');
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('_camelCase should be ok', function () {
|
|
184
|
-
expect(_camelCase('test_camel_case')).to.be.eql('testCamelCase');
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('_subModelName should be ok', function () {
|
|
188
|
-
expect(_subModelName('test.model.name')).to.be.eql('TestModelName');
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('_string should be ok', function () {
|
|
192
|
-
const obj = {
|
|
193
|
-
string: 'test'
|
|
194
|
-
};
|
|
195
|
-
expect(_string(obj)).to.be.eql('test');
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('_avoidKeywords should be ok', function () {
|
|
199
|
-
_config({
|
|
200
|
-
keywords: {
|
|
201
|
-
general: 'key',
|
|
202
|
-
function: ['function'],
|
|
203
|
-
class: ['class'],
|
|
204
|
-
param_variables: ['var']
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
expect(_avoidKeywords('key')).to.be.eql('key_');
|
|
208
|
-
expect(_avoidFuncKeywords('key')).to.be.eql('key_');
|
|
209
|
-
expect(_avoidFuncKeywords('function')).to.be.eql('function_');
|
|
210
|
-
expect(_avoidClassKeywords('key')).to.be.eql('key_');
|
|
211
|
-
expect(_avoidClassKeywords('class')).to.be.eql('class_');
|
|
212
|
-
expect(_avoidVarKeywords('key')).to.be.eql('key_');
|
|
213
|
-
expect(_avoidVarKeywords('var')).to.be.eql('var_');
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('_modify should be ok', function () {
|
|
217
|
-
_config({
|
|
218
|
-
modifyOrder: [
|
|
219
|
-
'PRIVATE',
|
|
220
|
-
'PROTECTED',
|
|
221
|
-
'PUBLIC',
|
|
222
|
-
'FINAL',
|
|
223
|
-
'ABSTRACT',
|
|
224
|
-
'STATIC'
|
|
225
|
-
]
|
|
226
|
-
});
|
|
227
|
-
expect(_modify('PRIVATE')).to.be.eql('private');
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('_symbol should be ok', function () {
|
|
231
|
-
_config({ symbolMap: { 'ASSIGN': '=' } });
|
|
232
|
-
expect(function () {
|
|
233
|
-
_symbol('InvalidSymbol');
|
|
234
|
-
}).to.be.throw('Unsupported symbol : InvalidSymbol');
|
|
235
|
-
|
|
236
|
-
expect(_symbol('ASSIGN')).to.be.eql('=');
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it('_isSnakeCase should be ok', function () {
|
|
240
|
-
expect(_isSnakeCase('tea_rpc')).to.be.eql(true);
|
|
241
|
-
expect(_isSnakeCase('tea')).to.be.eql(true);
|
|
242
|
-
expect(_isSnakeCase('tearpc')).to.be.eql(true);
|
|
243
|
-
expect(_isSnakeCase('tearpc01')).to.be.eql(true);
|
|
244
|
-
expect(_isSnakeCase('_tearpc')).to.be.eql(true);
|
|
245
|
-
expect(_isSnakeCase('teaRpc')).to.be.eql(false);
|
|
246
|
-
expect(_isSnakeCase('tea-rpc')).to.be.eql(false);
|
|
247
|
-
expect(_isSnakeCase('tea-Rpc')).to.be.eql(false);
|
|
248
|
-
expect(_isSnakeCase('tea rpc')).to.be.eql(false);
|
|
249
|
-
expect(_isSnakeCase('01tearpc')).to.be.eql(false);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('_toSnakeCase should be ok', function () {
|
|
253
|
-
expect(_toSnakeCase('TestABC')).to.be.eql('test_abc');
|
|
254
|
-
expect(_toSnakeCase(null)).to.be.eql('');
|
|
255
|
-
expect(_toSnakeCase('SLS')).to.be.eql('sls');
|
|
256
|
-
expect(_toSnakeCase('_runtime')).to.be.eql('_runtime');
|
|
257
|
-
expect(_toSnakeCase('TT123')).to.be.eql('tt123');
|
|
258
|
-
expect(_toSnakeCase('fooBar')).to.be.eql('foo_bar');
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('_toCamelCase should be ok', function () {
|
|
262
|
-
expect(_toCamelCase('test_abc')).to.be.eql('TestAbc');
|
|
263
|
-
expect(_toCamelCase(null)).to.be.eql('');
|
|
264
|
-
expect(_toCamelCase('sls')).to.be.eql('Sls');
|
|
265
|
-
expect(_toCamelCase('_runtime')).to.be.eql('Runtime');
|
|
266
|
-
expect(_toCamelCase('tt_123')).to.be.eql('Tt123');
|
|
267
|
-
expect(_toCamelCase('foo_bar')).to.be.eql('FooBar');
|
|
268
|
-
});
|
|
269
|
-
});
|
package/tests/python2.tests.js
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const assert = require('assert');
|
|
6
|
-
|
|
7
|
-
const DSL = require('@darabonba/parser');
|
|
8
|
-
|
|
9
|
-
let Generator = require('../src/generator');
|
|
10
|
-
|
|
11
|
-
const lang = 'python2';
|
|
12
|
-
|
|
13
|
-
const expectedDir = path.join(__dirname, 'expected/python2/');
|
|
14
|
-
const fixturesDir = path.join(__dirname, 'fixtures/');
|
|
15
|
-
const outputDir = path.join(__dirname, '../', 'output/tests/python2/');
|
|
16
|
-
|
|
17
|
-
function check(moduleName, expectedFiles = [], option = {}) {
|
|
18
|
-
const mainFilePath = path.join(fixturesDir, moduleName, 'main.dara') ? path.join(fixturesDir, moduleName, 'main.dara') : path.join(fixturesDir, moduleName, 'main.tea');
|
|
19
|
-
const moduleOutputDir = path.join(outputDir, moduleName);
|
|
20
|
-
const prefixDir = path.join(fixturesDir, moduleName);
|
|
21
|
-
const pkgContent = fs.readFileSync(
|
|
22
|
-
fs.existsSync(path.join(prefixDir, 'Darafile')) ? path.join(prefixDir, 'Darafile') : path.join(prefixDir, 'Teafile'), 'utf8');
|
|
23
|
-
const pkgInfo = JSON.parse(pkgContent);
|
|
24
|
-
const config = {
|
|
25
|
-
outputDir: moduleOutputDir,
|
|
26
|
-
pkgDir: path.join(fixturesDir, moduleName),
|
|
27
|
-
...pkgInfo,
|
|
28
|
-
...option
|
|
29
|
-
};
|
|
30
|
-
const generator = new Generator(config, lang);
|
|
31
|
-
|
|
32
|
-
const dsl = fs.readFileSync(mainFilePath, 'utf8');
|
|
33
|
-
const ast = DSL.parse(dsl, mainFilePath);
|
|
34
|
-
generator.visit(ast);
|
|
35
|
-
expectedFiles.forEach(element => {
|
|
36
|
-
const outputFilePath = path.join(outputDir, moduleName, element);
|
|
37
|
-
const expectedFilePath = path.join(expectedDir, moduleName, element);
|
|
38
|
-
const expected = fs.readFileSync(expectedFilePath, 'utf8');
|
|
39
|
-
assert.deepStrictEqual(fs.readFileSync(outputFilePath, 'utf8'), expected);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
describe('Python Generator', function () {
|
|
44
|
-
it('alias should ok', function () {
|
|
45
|
-
check('alias', [
|
|
46
|
-
'tea_python_tests/client.py'
|
|
47
|
-
],
|
|
48
|
-
{
|
|
49
|
-
python2: {
|
|
50
|
-
package: 'tea_python_tests',
|
|
51
|
-
clientName: 'client',
|
|
52
|
-
packageInfo: {
|
|
53
|
-
name: 'tea_python_tests',
|
|
54
|
-
desc: 'Generate setup.py',
|
|
55
|
-
github: 'https://github.com/',
|
|
56
|
-
author: 'Alibaba',
|
|
57
|
-
email: 'sdk-team@alibabacloud.com'
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('add annotation should ok', function () {
|
|
64
|
-
check('annotation', [
|
|
65
|
-
'tea_python_tests/client.py',
|
|
66
|
-
'tea_python_tests/models.py'
|
|
67
|
-
],
|
|
68
|
-
{
|
|
69
|
-
python2: {
|
|
70
|
-
package: 'tea_python_tests',
|
|
71
|
-
clientName: 'client'
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('api should ok', function () {
|
|
77
|
-
check('api', [
|
|
78
|
-
'tea_python_tests/client.py'
|
|
79
|
-
],
|
|
80
|
-
{
|
|
81
|
-
python2: {
|
|
82
|
-
package: 'tea_python_tests',
|
|
83
|
-
clientName: 'client'
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('add comments should ok', function () {
|
|
89
|
-
check('comment', [
|
|
90
|
-
'tea_python_tests/client.py',
|
|
91
|
-
'tea_python_tests/models.py'
|
|
92
|
-
],
|
|
93
|
-
{
|
|
94
|
-
python2: {
|
|
95
|
-
package: 'tea_python_tests',
|
|
96
|
-
clientName: 'client'
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('complex should ok', function () {
|
|
102
|
-
check('complex', [
|
|
103
|
-
'tea_python_tests/client.py',
|
|
104
|
-
'tea_python_tests/models.py'
|
|
105
|
-
],
|
|
106
|
-
{
|
|
107
|
-
python2: {
|
|
108
|
-
package: 'tea_python_tests',
|
|
109
|
-
clientName: 'client'
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('const should ok', function () {
|
|
115
|
-
check('const', [
|
|
116
|
-
'tea_python_tests/client.py'
|
|
117
|
-
],
|
|
118
|
-
{
|
|
119
|
-
python2: {
|
|
120
|
-
package: 'tea_python_tests',
|
|
121
|
-
clientName: 'client'
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('empty should ok', function () {
|
|
127
|
-
check('empty', [
|
|
128
|
-
'tea_python_tests/client.py',
|
|
129
|
-
'.gitignore'
|
|
130
|
-
],
|
|
131
|
-
{
|
|
132
|
-
python2: {
|
|
133
|
-
package: 'tea_python_tests',
|
|
134
|
-
clientName: 'client',
|
|
135
|
-
packageInfo: {
|
|
136
|
-
name: 'tea_python_tests',
|
|
137
|
-
desc: 'Generate setup.py',
|
|
138
|
-
github: 'https://github.com/',
|
|
139
|
-
author: 'Alibaba',
|
|
140
|
-
email: 'sdk-team@alibabacloud.com'
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('function should ok', function () {
|
|
147
|
-
check('function', [
|
|
148
|
-
'tea_python_tests/client.py'
|
|
149
|
-
],
|
|
150
|
-
{
|
|
151
|
-
python2: {
|
|
152
|
-
package: 'tea_python_tests',
|
|
153
|
-
clientName: 'client'
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('import should ok', function () {
|
|
159
|
-
check('import', [
|
|
160
|
-
'tea_python_tests/client.py'
|
|
161
|
-
],
|
|
162
|
-
{
|
|
163
|
-
python2: {
|
|
164
|
-
package: 'tea_python_tests',
|
|
165
|
-
clientName: 'client',
|
|
166
|
-
packageInfo: {
|
|
167
|
-
name: 'tea_python_tests',
|
|
168
|
-
desc: 'Generate setup.py',
|
|
169
|
-
github: 'https://github.com/',
|
|
170
|
-
author: 'Alibaba',
|
|
171
|
-
email: 'sdk-team@alibabacloud.com'
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
const expected = fs.readFileSync(path.join(expectedDir, 'import', 'setup.py'), 'utf8');
|
|
176
|
-
const output = fs.readFileSync(path.join(outputDir, 'import', 'setup.py'), 'utf8');
|
|
177
|
-
assert.deepStrictEqual(output.replace(new RegExp('\\d{2}\\/\\d{2}\\/\\d{4}'), '*'), expected);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('map should ok', function () {
|
|
181
|
-
check('map', [
|
|
182
|
-
'tea_python_tests/client.py'
|
|
183
|
-
],
|
|
184
|
-
{
|
|
185
|
-
python2: {
|
|
186
|
-
package: 'tea_python_tests',
|
|
187
|
-
clientName: 'client'
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it('model should ok', function () {
|
|
193
|
-
check('model', [
|
|
194
|
-
'tea_python_tests/client.py',
|
|
195
|
-
'tea_python_tests/models.py'
|
|
196
|
-
],
|
|
197
|
-
{
|
|
198
|
-
python2: {
|
|
199
|
-
package: 'tea_python_tests',
|
|
200
|
-
clientName: 'client'
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('statements should ok', function () {
|
|
206
|
-
check('statements', [
|
|
207
|
-
'tea_python_tests/client.py'
|
|
208
|
-
],
|
|
209
|
-
{
|
|
210
|
-
python2: {
|
|
211
|
-
package: 'tea_python_tests',
|
|
212
|
-
clientName: 'client'
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it('super should ok', function () {
|
|
218
|
-
check('super', [
|
|
219
|
-
'tea_python_tests/client.py'
|
|
220
|
-
],
|
|
221
|
-
{
|
|
222
|
-
python2: {
|
|
223
|
-
package: 'tea_python_tests',
|
|
224
|
-
clientName: 'client'
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it('exec should ok', function () {
|
|
230
|
-
check('exec', [
|
|
231
|
-
'tea_python_tests/exec_client.py'
|
|
232
|
-
],
|
|
233
|
-
{
|
|
234
|
-
exec: true,
|
|
235
|
-
python2: {
|
|
236
|
-
package: 'tea_python_tests',
|
|
237
|
-
clientName: 'exec_client'
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
it('typedef should ok', function () {
|
|
242
|
-
check('typedef', [
|
|
243
|
-
'tea_python_tests/client.py',
|
|
244
|
-
'tea_python_tests/models.py'
|
|
245
|
-
],
|
|
246
|
-
{
|
|
247
|
-
python2: {
|
|
248
|
-
package: 'tea_python_tests',
|
|
249
|
-
clientName: 'client',
|
|
250
|
-
packageInfo: {
|
|
251
|
-
name: 'tea_python_tests',
|
|
252
|
-
desc: 'Generate setup.py',
|
|
253
|
-
github: 'https://github.com/',
|
|
254
|
-
author: 'Alibaba',
|
|
255
|
-
email: 'sdk-team@alibabacloud.com'
|
|
256
|
-
},
|
|
257
|
-
typedef: {
|
|
258
|
-
HttpResponse: {
|
|
259
|
-
import: 'requests',
|
|
260
|
-
type: 'Response',
|
|
261
|
-
package: 'requests:2.21.0'
|
|
262
|
-
},
|
|
263
|
-
HttpHeader: {
|
|
264
|
-
import: null,
|
|
265
|
-
type: 'Dict[str, Any]',
|
|
266
|
-
package: null
|
|
267
|
-
},
|
|
268
|
-
TeaModel: {
|
|
269
|
-
import: 'Tea.model',
|
|
270
|
-
type: 'TeaModel',
|
|
271
|
-
package: 'alibabacloud-tea-py2:0.0.4'
|
|
272
|
-
},
|
|
273
|
-
TeaException: {
|
|
274
|
-
import: 'Tea.exceptions',
|
|
275
|
-
type: 'TeaException',
|
|
276
|
-
package: 'alibabacloud-tea-py2:0.0.4'
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
});
|