@@ -8,27 +8,27 @@ const PythonFinder = findPython.test.PythonFinder
88const npmlog = require ( 'npmlog' )
99npmlog . level = 'silent'
1010
11- // what chould final error message displayed in terminal contain
11+ // what final error message displayed in terminal should contain
1212const finalErrorMessage = 'Could not find any Python'
1313
14- //! dont forget manually call pythonFinderInstance.findPython()
14+ //! don't forget manually call pythonFinderInstance.findPython()
1515
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 .
1818// Is returned by execFile
1919//! USE FOR ALL STRINGS
2020const testString = 'python one love♥'
2121const testVersions = {
2222 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' ) ,
2525}
2626
2727/**
2828 * @typedef OptionsObj
29- * @property {boolean } shouldProduceError
29+ * @property {boolean } shouldProduceError pass test error to callback
3030 * @property {boolean } checkingPyLauncher
31- * @property {boolean } isPythonOutdated
31+ * @property {boolean } isPythonOutdated return outdated version
3232 * @property {boolean } checkingWinDefaultPathes
3333 *
3434 */
@@ -37,12 +37,12 @@ const testVersions = {
3737 *
3838 * @param {OptionsObj } optionsObj
3939 */
40- function TestExecFile ( optionsObj ) {
40+ function TestExecFile ( optionsObj ) {
4141 /**
4242 *
4343 * @this {PythonFinder}
4444 */
45- return function testExecFile ( exec , args , options , callback ) {
45+ return function testExecFile ( exec , args , options , callback ) {
4646 if ( ! ( optionsObj ? optionsObj . shouldProduceError : false ) ) {
4747 if ( args === this . argsVersion ) {
4848 if ( optionsObj ? optionsObj . checkingWinDefaultPathes : false ) {
@@ -56,9 +56,14 @@ function TestExecFile (optionsObj) {
5656 } else {
5757 callback ( null , testVersions . normal , null )
5858 }
59- } else if ( args === this . win ? `"${ this . argsExecutable } "` : this . argsExecutable ) {
59+ } else if (
60+ args === this . win ? `"${ this . argsExecutable } "` : this . argsExecutable
61+ ) {
6062 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+ ) {
6267 callback ( null , testString , null )
6368 } else {
6469 callback ( new Error ( 'not found' ) )
@@ -85,7 +90,7 @@ are: ${args};\n\nValid are: \n${this.argsExecutable}\n${this.argsVersion}`
8590
8691/**
8792 *
88- * @param {boolean } isPythonOutdated if true will return outadet version of python
93+ * @param {boolean } isPythonOutdated if true will return outdated version of python
8994 * @param {OptionsObj } optionsObj
9095 */
9196
@@ -110,7 +115,7 @@ test('new-find-python', { buffered: true }, (t) => {
110115 t . test ( 'outdated version of python found' , ( t ) => {
111116 const pythonFinderInstance = new PythonFinder ( null , ( err , path ) => {
112117 if ( ! err ) {
113- t . fail ( "mustn't return path of outdated" )
118+ t . fail ( "mustn't return path for outdated version " )
114119 } else {
115120 t . end ( )
116121 }
@@ -128,13 +133,13 @@ test('new-find-python', { buffered: true }, (t) => {
128133 } )
129134
130135 pythonFinderInstance . execFile = TestExecFile ( {
131- shouldProduceError : true
136+ shouldProduceError : true ,
132137 } )
133138
134139 pythonFinderInstance . findPython ( )
135140 } )
136141
137- t . test ( 'no python2, no python, unix' , ( t ) => {
142+ t . test ( 'no python, unix' , ( t ) => {
138143 const pythonFinderInstance = new PythonFinder ( null , ( err , path ) => {
139144 t . false ( path )
140145
@@ -147,7 +152,7 @@ test('new-find-python', { buffered: true }, (t) => {
147152 pythonFinderInstance . checkPyLauncher = t . fail
148153
149154 pythonFinderInstance . execFile = TestExecFile ( {
150- shouldProduceError : true
155+ shouldProduceError : true ,
151156 } )
152157
153158 pythonFinderInstance . findPython ( )
@@ -165,24 +170,29 @@ test('new-find-python', { buffered: true }, (t) => {
165170 pythonFinderInstance . win = true
166171
167172 pythonFinderInstance . execFile = TestExecFile ( {
168- checkingPyLauncher : true
173+ checkingPyLauncher : true ,
169174 } )
170175
171176 pythonFinderInstance . findPython ( )
172177 } )
173178
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+ } )
180187
181- pythonFinderInstance . win = true
188+ pythonFinderInstance . win = true
182189
183- pythonFinderInstance . execFile = TestExecFile ( { checkingWinDefaultPathes : true } )
184- pythonFinderInstance . findPython ( )
185- } )
190+ pythonFinderInstance . execFile = TestExecFile ( {
191+ checkingWinDefaultPathes : true ,
192+ } )
193+ pythonFinderInstance . findPython ( )
194+ }
195+ )
186196
187197 t . test ( 'python is setted from config' , ( t ) => {
188198 const pythonFinderInstance = new PythonFinder ( testString , ( err , path ) => {
@@ -202,6 +212,7 @@ test('new-find-python', { buffered: true }, (t) => {
202212 t . end ( )
203213 } )
204214
215+ // TODO: make symlink to python with utf-8 chars
205216 t . test ( 'real testing (trying to find real python exec)' , ( t ) => {
206217 const pythonFinderInstance = new PythonFinder ( null , ( err , path ) => {
207218 t . strictEqual ( err , null )
@@ -211,13 +222,8 @@ test('new-find-python', { buffered: true }, (t) => {
211222 console . log ( 'stdout:' + stdout )
212223 console . log ( 'stderr:' + stderr )
213224
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 , '' )
221227
222228 t . end ( )
223229 } )
0 commit comments