|
| 1 | +import * as assert from 'assert'; |
| 2 | +import * as path from 'path'; |
| 3 | +import { ILintingSettings, PythonSettings } from '../../client/common/configSettings'; |
| 4 | +import { EnumEx } from '../../client/common/enumUtils'; |
| 5 | +import { Product } from '../../client/common/types'; |
| 6 | +import { LinterHelper } from '../../client/linters/helper'; |
| 7 | +import { LinterId } from '../../client/linters/types'; |
| 8 | +import { initialize } from '../initialize'; |
| 9 | + |
| 10 | +// tslint:disable-next-line:max-func-body-length |
| 11 | +suite('Linting - Helper', () => { |
| 12 | + const linterHelper = new LinterHelper(); |
| 13 | + suiteSetup(initialize); |
| 14 | + |
| 15 | + test('Ensure product is set in Execution Info', async () => { |
| 16 | + [Product.flake8, Product.mypy, Product.pep8, |
| 17 | + Product.pydocstyle, Product.pylama, Product.pylint].forEach(linter => { |
| 18 | + const info = linterHelper.getExecutionInfo(linter, []); |
| 19 | + assert.equal(info.product, linter, `Incorrect products for ${linterHelper.translateToId(linter)}`); |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + test('Ensure executable is set in Execution Info', async () => { |
| 24 | + const settings = PythonSettings.getInstance(); |
| 25 | + |
| 26 | + [Product.flake8, Product.mypy, Product.pep8, |
| 27 | + Product.pydocstyle, Product.pylama, Product.pylint].forEach(linter => { |
| 28 | + const info = linterHelper.getExecutionInfo(linter, []); |
| 29 | + const names = linterHelper.getSettingsPropertyNames(linter); |
| 30 | + const execPath = settings.linting[names.pathName] as string; |
| 31 | + let moduleName: string | undefined; |
| 32 | + if (path.basename(execPath) === execPath && linter !== Product.prospector) { |
| 33 | + moduleName = execPath; |
| 34 | + } |
| 35 | + |
| 36 | + assert.equal(info.execPath, execPath, `Incorrect executable paths for product ${linterHelper.translateToId(linter)}`); |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + test('Ensure arguments are set in Execution Info', async () => { |
| 41 | + const settings = PythonSettings.getInstance(); |
| 42 | + const customArgs = ['1', '2', '3']; |
| 43 | + |
| 44 | + [Product.flake8, Product.mypy, Product.pep8, |
| 45 | + Product.pydocstyle, Product.pylama, Product.pylint].forEach(linter => { |
| 46 | + const info = linterHelper.getExecutionInfo(linter, []); |
| 47 | + const names = linterHelper.getSettingsPropertyNames(linter); |
| 48 | + const args: string[] = Array.isArray(settings.linting[names.argsName]) ? settings.linting[names.argsName] as string[] : []; |
| 49 | + const expectedArgs = args.concat(customArgs).join(','); |
| 50 | + |
| 51 | + assert.equal(expectedArgs.endsWith(customArgs.join(',')), true, `Incorrect custom arguments for product ${linterHelper.translateToId(linter)}`); |
| 52 | + |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + test('Ensure correct setting names are returned', async () => { |
| 57 | + [Product.flake8, Product.mypy, Product.pep8, |
| 58 | + Product.pydocstyle, Product.pylama, Product.pylint].forEach(linter => { |
| 59 | + const translatedId = linterHelper.translateToId(linter)!; |
| 60 | + const settings = { |
| 61 | + argsName: `${translatedId}Args` as keyof ILintingSettings, |
| 62 | + pathName: `${translatedId}Path` as keyof ILintingSettings, |
| 63 | + enabledName: `${translatedId}Enabled` as keyof ILintingSettings |
| 64 | + }; |
| 65 | + |
| 66 | + assert.deepEqual(linterHelper.getSettingsPropertyNames(linter), settings, `Incorrect settings for product ${linterHelper.translateToId(linter)}`); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + test('Ensure translation of ids works', async () => { |
| 71 | + const linterIdMapping = new Map<Product, LinterId>(); |
| 72 | + linterIdMapping.set(Product.flake8, 'flake8'); |
| 73 | + linterIdMapping.set(Product.mypy, 'mypy'); |
| 74 | + linterIdMapping.set(Product.pep8, 'pep8'); |
| 75 | + linterIdMapping.set(Product.prospector, 'prospector'); |
| 76 | + linterIdMapping.set(Product.pydocstyle, 'pydocstyle'); |
| 77 | + linterIdMapping.set(Product.pylama, 'pylama'); |
| 78 | + linterIdMapping.set(Product.pylint, 'pylint'); |
| 79 | + |
| 80 | + [Product.flake8, Product.mypy, Product.pep8, |
| 81 | + Product.pydocstyle, Product.pylama, Product.pylint].forEach(linter => { |
| 82 | + const translatedId = linterHelper.translateToId(linter); |
| 83 | + assert.equal(translatedId, linterIdMapping.get(linter)!, `Incorrect translation for product ${linterHelper.translateToId(linter)}`); |
| 84 | + }); |
| 85 | + }); |
| 86 | + |
| 87 | + EnumEx.getValues<Product>(Product).forEach(product => { |
| 88 | + const linterIdMapping = new Map<Product, LinterId>(); |
| 89 | + linterIdMapping.set(Product.flake8, 'flake8'); |
| 90 | + linterIdMapping.set(Product.mypy, 'mypy'); |
| 91 | + linterIdMapping.set(Product.pep8, 'pep8'); |
| 92 | + linterIdMapping.set(Product.prospector, 'prospector'); |
| 93 | + linterIdMapping.set(Product.pydocstyle, 'pydocstyle'); |
| 94 | + linterIdMapping.set(Product.pylama, 'pylama'); |
| 95 | + linterIdMapping.set(Product.pylint, 'pylint'); |
| 96 | + if (linterIdMapping.has(product)) { |
| 97 | + return; |
| 98 | + } |
| 99 | + |
| 100 | + test(`Ensure translation of ids throws exceptions for unknown linters (${product})`, async () => { |
| 101 | + assert.throws(() => linterHelper.translateToId(product)); |
| 102 | + }); |
| 103 | + }); |
| 104 | +}); |
0 commit comments