@@ -8,27 +8,27 @@ const PythonFinder = findPython.test.PythonFinder
8
8
const npmlog = require ( 'npmlog' )
9
9
npmlog . level = 'silent'
10
10
11
- // what chould final error message displayed in terminal contain
11
+ // what final error message displayed in terminal should contain
12
12
const finalErrorMessage = 'Could not find any Python'
13
13
14
- //! dont forget manually call pythonFinderInstance.findPython()
14
+ //! don't forget manually call pythonFinderInstance.findPython()
15
15
16
- // String emmulating path coomand or anything else with spaces
17
- // and UTF-8 charcters .
16
+ // String emulating path command or anything else with spaces
17
+ // and UTF-8 characters .
18
18
// Is returned by execFile
19
19
//! USE FOR ALL STRINGS
20
20
const testString = 'python one love♥'
21
21
const testVersions = {
22
22
outdated : '2.0.0' ,
23
- normal : '3.7 .0' ,
24
- testError : new Error ( 'test error' )
23
+ normal : '3.9 .0' ,
24
+ testError : new Error ( 'test error' ) ,
25
25
}
26
26
27
27
/**
28
28
* @typedef OptionsObj
29
- * @property {boolean } shouldProduceError
29
+ * @property {boolean } shouldProduceError pass test error to callback
30
30
* @property {boolean } checkingPyLauncher
31
- * @property {boolean } isPythonOutdated
31
+ * @property {boolean } isPythonOutdated return outdated version
32
32
* @property {boolean } checkingWinDefaultPathes
33
33
*
34
34
*/
@@ -37,12 +37,12 @@ const testVersions = {
37
37
*
38
38
* @param {OptionsObj } optionsObj
39
39
*/
40
- function TestExecFile ( optionsObj ) {
40
+ function TestExecFile ( optionsObj ) {
41
41
/**
42
42
*
43
43
* @this {PythonFinder}
44
44
*/
45
- return function testExecFile ( exec , args , options , callback ) {
45
+ return function testExecFile ( exec , args , options , callback ) {
46
46
if ( ! ( optionsObj ? optionsObj . shouldProduceError : false ) ) {
47
47
if ( args === this . argsVersion ) {
48
48
if ( optionsObj ? optionsObj . checkingWinDefaultPathes : false ) {
@@ -56,9 +56,14 @@ function TestExecFile (optionsObj) {
56
56
} else {
57
57
callback ( null , testVersions . normal , null )
58
58
}
59
- } else if ( args === this . win ? `"${ this . argsExecutable } "` : this . argsExecutable ) {
59
+ } else if (
60
+ args === this . win ? `"${ this . argsExecutable } "` : this . argsExecutable
61
+ ) {
60
62
if ( optionsObj ? optionsObj . checkingPyLauncher : false ) {
61
- if ( exec === 'py.exe' || exec === ( this . win ? '"python"' : 'python' ) ) {
63
+ if (
64
+ exec === 'py.exe' ||
65
+ exec === ( this . win ? '"python"' : 'python' )
66
+ ) {
62
67
callback ( null , testString , null )
63
68
} else {
64
69
callback ( new Error ( 'not found' ) )
@@ -85,7 +90,7 @@ are: ${args};\n\nValid are: \n${this.argsExecutable}\n${this.argsVersion}`
85
90
86
91
/**
87
92
*
88
- * @param {boolean } isPythonOutdated if true will return outadet version of python
93
+ * @param {boolean } isPythonOutdated if true will return outdated version of python
89
94
* @param {OptionsObj } optionsObj
90
95
*/
91
96
@@ -110,7 +115,7 @@ test('new-find-python', { buffered: true }, (t) => {
110
115
t . test ( 'outdated version of python found' , ( t ) => {
111
116
const pythonFinderInstance = new PythonFinder ( null , ( err , path ) => {
112
117
if ( ! err ) {
113
- t . fail ( "mustn't return path of outdated" )
118
+ t . fail ( "mustn't return path for outdated version " )
114
119
} else {
115
120
t . end ( )
116
121
}
@@ -128,13 +133,13 @@ test('new-find-python', { buffered: true }, (t) => {
128
133
} )
129
134
130
135
pythonFinderInstance . execFile = TestExecFile ( {
131
- shouldProduceError : true
136
+ shouldProduceError : true ,
132
137
} )
133
138
134
139
pythonFinderInstance . findPython ( )
135
140
} )
136
141
137
- t . test ( 'no python2, no python, unix' , ( t ) => {
142
+ t . test ( 'no python, unix' , ( t ) => {
138
143
const pythonFinderInstance = new PythonFinder ( null , ( err , path ) => {
139
144
t . false ( path )
140
145
@@ -147,7 +152,7 @@ test('new-find-python', { buffered: true }, (t) => {
147
152
pythonFinderInstance . checkPyLauncher = t . fail
148
153
149
154
pythonFinderInstance . execFile = TestExecFile ( {
150
- shouldProduceError : true
155
+ shouldProduceError : true ,
151
156
} )
152
157
153
158
pythonFinderInstance . findPython ( )
@@ -165,24 +170,29 @@ test('new-find-python', { buffered: true }, (t) => {
165
170
pythonFinderInstance . win = true
166
171
167
172
pythonFinderInstance . execFile = TestExecFile ( {
168
- checkingPyLauncher : true
173
+ checkingPyLauncher : true ,
169
174
} )
170
175
171
176
pythonFinderInstance . findPython ( )
172
177
} )
173
178
174
- t . test ( 'no python, no python launcher, checking win default locations' , ( t ) => {
175
- const pythonFinderInstance = new PythonFinder ( null , ( err , path ) => {
176
- t . strictEqual ( err , null )
177
- t . true ( pythonFinderInstance . winDefaultLocations . includes ( path ) )
178
- t . end ( )
179
- } )
179
+ t . test (
180
+ 'no python, no python launcher, checking win default locations' ,
181
+ ( t ) => {
182
+ const pythonFinderInstance = new PythonFinder ( null , ( err , path ) => {
183
+ t . strictEqual ( err , null )
184
+ t . true ( pythonFinderInstance . winDefaultLocations . includes ( path ) )
185
+ t . end ( )
186
+ } )
180
187
181
- pythonFinderInstance . win = true
188
+ pythonFinderInstance . win = true
182
189
183
- pythonFinderInstance . execFile = TestExecFile ( { checkingWinDefaultPathes : true } )
184
- pythonFinderInstance . findPython ( )
185
- } )
190
+ pythonFinderInstance . execFile = TestExecFile ( {
191
+ checkingWinDefaultPathes : true ,
192
+ } )
193
+ pythonFinderInstance . findPython ( )
194
+ }
195
+ )
186
196
187
197
t . test ( 'python is setted from config' , ( t ) => {
188
198
const pythonFinderInstance = new PythonFinder ( testString , ( err , path ) => {
@@ -202,6 +212,7 @@ test('new-find-python', { buffered: true }, (t) => {
202
212
t . end ( )
203
213
} )
204
214
215
+ // TODO: make symlink to python with utf-8 chars
205
216
t . test ( 'real testing (trying to find real python exec)' , ( t ) => {
206
217
const pythonFinderInstance = new PythonFinder ( null , ( err , path ) => {
207
218
t . strictEqual ( err , null )
@@ -211,13 +222,8 @@ test('new-find-python', { buffered: true }, (t) => {
211
222
console . log ( 'stdout:' + stdout )
212
223
console . log ( 'stderr:' + stderr )
213
224
214
- if ( stderr . includes ( 'Python 2' ) ) {
215
- t . strictEqual ( stdout , '' )
216
- t . ok ( stderr . includes ( 'Python 2' ) )
217
- } else {
218
- t . ok ( stdout . includes ( 'Python 3' ) )
219
- t . strictEqual ( stderr , '' )
220
- }
225
+ t . ok ( stdout . includes ( 'Python 3' ) )
226
+ t . strictEqual ( stderr , '' )
221
227
222
228
t . end ( )
223
229
} )
0 commit comments