Skip to content

Commit

Permalink
fix checking for errrors in executionEnvironments because it now ge…
Browse files Browse the repository at this point in the history
…ts loaded somewhere else
  • Loading branch information
DetachHead committed Aug 28, 2024
1 parent fb2a90f commit 0ca1e87
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
6 changes: 5 additions & 1 deletion packages/pyright-internal/src/common/configOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,11 @@ export class ConfigOptions {
const errors: string[] = [];

// we initialize it with `extends` because this option gets read before this function gets called
const unusedConfigDetector = new UnusedConfigDetector<Record<string, object>>(configObj, ['extends']);
// 'executionEnvironments' also gets read elsewhere
const unusedConfigDetector = new UnusedConfigDetector<Record<string, object>>(configObj, [
'extends',
'executionEnvironments',
]);
configObj = unusedConfigDetector.proxy;

// Read the entries that should be an array of relative file paths
Expand Down
30 changes: 8 additions & 22 deletions packages/pyright-internal/src/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ test('PythonPlatform', () => {

const configOptions = service.test_getConfigOptions(commandLineOptions);
assert.ok(configOptions.executionEnvironments[0]);
assert.equal(configOptions.executionEnvironments[0].pythonPlatform, 'platform');
assert.equal(configOptions.executionEnvironments[0].pythonPlatform, 'Linux');
});

describe('invalid config', () => {
Expand Down Expand Up @@ -251,27 +251,13 @@ describe('invalid config', () => {
'Config "typeCheckingMode" entry must contain "off", "basic", "standard", "strict", or "all".',
]);
});
test('unknown value for top-level option', () => {
const cwd = UriEx.file(normalizePath(process.cwd()));

const configOptions = new ConfigOptions(cwd);

const json = {
executionEnvironments: [
{
root: 'foo',
asdf: true,
},
],
};

const fs = new TestFileSystem(/* ignoreCase */ false);
const nullConsole = new NullConsole();

const sp = createServiceProvider(fs, nullConsole);
const errors = configOptions.initializeFromJson(json, cwd, sp, new NoAccessHost());

assert.deepStrictEqual(errors, [`unknown config option in execution environment "foo": asdf`]);
test('unknown value in execution environments', () => {
const { analysisResult } = setupPyprojectToml(
'src/tests/samples/project_with_invalid_option_in_execution_environments'
);
assert.deepStrictEqual(analysisResult?.configParseErrors, [
`unknown config option in execution environment "foo": asdf`,
]);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.pyright]
executionEnvironments = [{ root = 'foo', asdf = true }]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[tool.pyright]
executionEnvironments = [
{ python = "3.7", pythonPlatform = "platform" },
]
{ root = ".", pythonVersion = "3.7", pythonPlatform = "Linux" },
]

0 comments on commit 0ca1e87

Please sign in to comment.