Skip to content

Commit ecb0a60

Browse files
test: remove python2 support in tests
1 parent 5b0d98a commit ecb0a60

File tree

2 files changed

+49
-43
lines changed

2 files changed

+49
-43
lines changed

test/test-find-python-script.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@ const path = require('path')
88

99
require('npmlog').level = 'warn'
1010

11-
//* can use name as short descriptions
11+
//* name can be used as short descriptions
1212

1313
/**
1414
* @typedef Check
15-
* @property {string} path - path to execurtable or command
15+
* @property {string} path - path to executable or command
1616
* @property {string} name - very little description
1717
*/
1818

19+
// TODO: add symlinks to python which will contain utf-8 chars
1920
/**
2021
* @type {Check[]}
2122
*/
2223
const checks = [
2324
{ path: process.env.PYTHON, name: 'env var PYTHON' },
24-
{ path: process.env.python2, name: 'env var python2' },
2525
{ path: 'python3', name: 'python3 in PATH' },
26-
{ path: 'python2', name: 'python2 in PATH' },
27-
{ path: 'python', name: 'pyhton in PATH' }
26+
{ path: 'python', name: 'python in PATH' }
2827
]
2928
const args = [path.resolve('./lib/find-python-script.py')]
3029
const options = {
@@ -34,15 +33,15 @@ const options = {
3433
/**
3534
Getting output from find-python-script.py,
3635
compare it to path provided to terminal.
37-
If equale - test pass
36+
If equals - test pass
3837
3938
runs for all checks
4039
4140
@private
4241
@argument {Error} err - exec error
4342
@argument {string} stdout - stdout buffer of child process
4443
@argument {string} stderr
45-
@this {{t, exec: Check}}
44+
@this {{t: Tap, exec: Check}}
4645
*/
4746
function check (err, stdout, stderr) {
4847
const { t, exec } = this
@@ -64,6 +63,7 @@ function check (err, stdout, stderr) {
6463
test('find-python-script', { buffered: false }, (t) => {
6564
t.plan(checks.length)
6665

66+
//? may be more elegant way to copy and pass context
6767
// context for check functions
6868
const ctx = {
6969
t: t,
@@ -74,7 +74,7 @@ test('find-python-script', { buffered: false }, (t) => {
7474
// checking if env var exist
7575
if (!(exec.path === undefined || exec.path === null)) {
7676
ctx.exec = exec
77-
// passing ctx as coppied object to make properties immutable from here
77+
// passing ctx as copied object to make properties immutable from here
7878
const boundedCheck = check.bind(Object.assign({}, ctx))
7979
execFile(exec.path, args, options, boundedCheck)
8080
} else {

test/test-find-python.js

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ const PythonFinder = findPython.test.PythonFinder
88
const npmlog = require('npmlog')
99
npmlog.level = 'silent'
1010

11-
// what chould final error message displayed in terminal contain
11+
// what final error message displayed in terminal should contain
1212
const 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
2020
const testString = 'python one love♥'
2121
const 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

Comments
 (0)