@zzzen/pyright-internal 1.2.0-dev.20250112 → 1.2.0-dev.20250126

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +1 -0
  2. package/dist/analyzer/backgroundAnalysisProgram.js +3 -0
  3. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  4. package/dist/analyzer/binder.js +7 -1
  5. package/dist/analyzer/binder.js.map +1 -1
  6. package/dist/analyzer/checker.d.ts +1 -1
  7. package/dist/analyzer/checker.js +34 -42
  8. package/dist/analyzer/checker.js.map +1 -1
  9. package/dist/analyzer/constructors.js +1 -1
  10. package/dist/analyzer/constructors.js.map +1 -1
  11. package/dist/analyzer/enums.js +140 -126
  12. package/dist/analyzer/enums.js.map +1 -1
  13. package/dist/analyzer/importResolver.d.ts +3 -2
  14. package/dist/analyzer/importResolver.js +80 -79
  15. package/dist/analyzer/importResolver.js.map +1 -1
  16. package/dist/analyzer/pythonPathUtils.d.ts +2 -0
  17. package/dist/analyzer/pythonPathUtils.js +20 -11
  18. package/dist/analyzer/pythonPathUtils.js.map +1 -1
  19. package/dist/analyzer/service.js +2 -5
  20. package/dist/analyzer/service.js.map +1 -1
  21. package/dist/analyzer/typeCacheUtils.js +1 -1
  22. package/dist/analyzer/typeCacheUtils.js.map +1 -1
  23. package/dist/analyzer/typeEvaluator.js +72 -44
  24. package/dist/analyzer/typeEvaluator.js.map +1 -1
  25. package/dist/analyzer/typeEvaluatorTypes.d.ts +3 -1
  26. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  27. package/dist/analyzer/typeGuards.js +24 -17
  28. package/dist/analyzer/typeGuards.js.map +1 -1
  29. package/dist/backgroundAnalysis.js +2 -0
  30. package/dist/backgroundAnalysis.js.map +1 -1
  31. package/dist/backgroundThreadBase.d.ts +1 -0
  32. package/dist/backgroundThreadBase.js +5 -8
  33. package/dist/backgroundThreadBase.js.map +1 -1
  34. package/dist/common/fullAccessHost.d.ts +1 -1
  35. package/dist/common/fullAccessHost.js +1 -1
  36. package/dist/common/languageServerInterface.d.ts +1 -1
  37. package/dist/common/realFileSystem.d.ts +1 -1
  38. package/dist/common/realFileSystem.js +10 -2
  39. package/dist/common/realFileSystem.js.map +1 -1
  40. package/dist/common/serviceProvider.d.ts +1 -0
  41. package/dist/common/serviceProvider.js +8 -0
  42. package/dist/common/serviceProvider.js.map +1 -1
  43. package/dist/languageServerBase.d.ts +3 -3
  44. package/dist/languageServerBase.js +7 -4
  45. package/dist/languageServerBase.js.map +1 -1
  46. package/dist/languageService/analyzerServiceExecutor.js +4 -1
  47. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  48. package/dist/languageService/hoverProvider.js +5 -3
  49. package/dist/languageService/hoverProvider.js.map +1 -1
  50. package/dist/languageService/tooltipUtils.d.ts +1 -1
  51. package/dist/languageService/tooltipUtils.js +14 -1
  52. package/dist/languageService/tooltipUtils.js.map +1 -1
  53. package/dist/localization/localize.d.ts +9 -7
  54. package/dist/localization/localize.js +6 -2
  55. package/dist/localization/localize.js.map +1 -1
  56. package/dist/localization/package.nls.cs.json +8 -7
  57. package/dist/localization/package.nls.de.json +8 -7
  58. package/dist/localization/package.nls.en-us.json +21 -5
  59. package/dist/localization/package.nls.es.json +8 -7
  60. package/dist/localization/package.nls.fr.json +8 -7
  61. package/dist/localization/package.nls.it.json +8 -7
  62. package/dist/localization/package.nls.ja.json +8 -7
  63. package/dist/localization/package.nls.ko.json +8 -7
  64. package/dist/localization/package.nls.pl.json +6 -5
  65. package/dist/localization/package.nls.pt-br.json +8 -7
  66. package/dist/localization/package.nls.qps-ploc.json +4 -3
  67. package/dist/localization/package.nls.ru.json +8 -7
  68. package/dist/localization/package.nls.tr.json +6 -5
  69. package/dist/localization/package.nls.zh-cn.json +8 -7
  70. package/dist/localization/package.nls.zh-tw.json +8 -7
  71. package/dist/pyright.js +11 -4
  72. package/dist/pyright.js.map +1 -1
  73. package/dist/server.d.ts +2 -1
  74. package/dist/server.js +1 -1
  75. package/dist/server.js.map +1 -1
  76. package/dist/tests/config.test.js +451 -427
  77. package/dist/tests/config.test.js.map +1 -1
  78. package/dist/tests/harness/fourslash/testState.d.ts +3 -1
  79. package/dist/tests/harness/fourslash/testState.js +23 -23
  80. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  81. package/dist/tests/hoverProvider.test.js +51 -0
  82. package/dist/tests/hoverProvider.test.js.map +1 -1
  83. package/dist/tests/importResolver.test.js +537 -527
  84. package/dist/tests/importResolver.test.js.map +1 -1
  85. package/dist/tests/sourceFile.test.js +1 -0
  86. package/dist/tests/sourceFile.test.js.map +1 -1
  87. package/dist/tests/testUtils.js +1 -0
  88. package/dist/tests/testUtils.js.map +1 -1
  89. package/dist/tests/typeEvaluator1.test.js +1 -1
  90. package/dist/tests/typeEvaluator3.test.js +5 -1
  91. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  92. package/dist/tests/typeEvaluator5.test.js +1 -1
  93. package/dist/tests/typeEvaluator6.test.js +8 -0
  94. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  95. package/dist/tests/typeEvaluator7.test.js +4 -0
  96. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  97. package/dist/tests/uri.test.js +3 -0
  98. package/dist/tests/uri.test.js.map +1 -1
  99. package/dist/tests/zipfs.test.js +2 -0
  100. package/dist/tests/zipfs.test.js.map +1 -1
  101. package/dist/workspaceFactory.d.ts +2 -1
  102. package/dist/workspaceFactory.js.map +1 -1
  103. package/package.json +1 -1
@@ -26,433 +26,457 @@ const uri_1 = require("../common/uri/uri");
26
26
  const uriUtils_1 = require("../common/uri/uriUtils");
27
27
  const testAccessHost_1 = require("./harness/testAccessHost");
28
28
  const filesystem_1 = require("./harness/vfs/filesystem");
29
- function createAnalyzer(console) {
29
+ describe(`config test'}`, () => {
30
30
  const tempFile = new realFileSystem_1.RealTempFile();
31
- const cons = console ?? new console_1.NullConsole();
32
- const fs = (0, realFileSystem_1.createFromRealFileSystem)(tempFile, cons);
33
- const serviceProvider = (0, serviceProviderExtensions_1.createServiceProvider)(fs, cons, tempFile);
34
- return new service_1.AnalyzerService('<default>', serviceProvider, { console: cons });
35
- }
36
- test('FindFilesWithConfigFile', () => {
37
- const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
38
- const service = createAnalyzer();
39
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
40
- commandLineOptions.configFilePath = 'src/tests/samples/project1';
41
- const configOptions = service.test_getConfigOptions(commandLineOptions);
42
- service.setOptions(commandLineOptions);
43
- // The config file specifies a single file spec (a directory).
44
- assert_1.default.strictEqual(configOptions.include.length, 1, `failed creating options from ${cwd}`);
45
- assert_1.default.strictEqual(configOptions.projectRoot.key, service.fs.realCasePath(uri_1.Uri.file((0, pathUtils_1.combinePaths)(cwd, commandLineOptions.configFilePath), service.serviceProvider))
46
- .key);
47
- const fileList = service.test_getFileNamesFromFileSpecs();
48
- // The config file specifies a subdirectory, so we should find
49
- // only two of the three "*.py" files present in the project
50
- // directory.
51
- assert_1.default.strictEqual(fileList.length, 2);
52
- });
53
- test('FindFilesVirtualEnvAutoDetectExclude', () => {
54
- const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
55
- const service = createAnalyzer();
56
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
57
- commandLineOptions.configFilePath = 'src/tests/samples/project_with_venv_auto_detect_exclude';
58
- service.setOptions(commandLineOptions);
59
- // The config file is empty, so no 'exclude' are specified
60
- // The myVenv directory is detected as a venv and will be automatically excluded
61
- const fileList = service.test_getFileNamesFromFileSpecs();
62
- // There are 3 python files in the workspace, outside of myVenv
63
- // There is 1 python file in myVenv, which should be excluded
64
- const fileNames = fileList.map((p) => p.fileName).sort();
65
- assert_1.default.deepStrictEqual(fileNames, ['sample1.py', 'sample2.py', 'sample3.py']);
66
- });
67
- test('FindFilesVirtualEnvAutoDetectInclude', () => {
68
- const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
69
- const service = createAnalyzer();
70
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
71
- commandLineOptions.configFilePath = 'src/tests/samples/project_with_venv_auto_detect_include';
72
- service.setOptions(commandLineOptions);
73
- // Config file defines 'exclude' folder so virtual env will be included
74
- const fileList = service.test_getFileNamesFromFileSpecs();
75
- // There are 3 python files in the workspace, outside of myVenv
76
- // There is 1 more python file in excluded folder
77
- // There is 1 python file in myVenv, which should be included
78
- const fileNames = fileList.map((p) => p.fileName).sort();
79
- assert_1.default.deepStrictEqual(fileNames, ['library1.py', 'sample1.py', 'sample2.py', 'sample3.py']);
80
- });
81
- test('FileSpecNotAnArray', () => {
82
- const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
83
- const nullConsole = new console_1.NullConsole();
84
- const service = createAnalyzer(nullConsole);
85
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
86
- commandLineOptions.configFilePath = 'src/tests/samples/project2';
87
- service.setOptions(commandLineOptions);
88
- service.test_getConfigOptions(commandLineOptions);
89
- // The method should return a default config and log an error.
90
- (0, assert_1.default)(nullConsole.infoCount > 0);
91
- });
92
- test('FileSpecNotAString', () => {
93
- const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
94
- const nullConsole = new console_1.NullConsole();
95
- const service = createAnalyzer(nullConsole);
96
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
97
- commandLineOptions.configFilePath = 'src/tests/samples/project3';
98
- service.setOptions(commandLineOptions);
99
- service.test_getConfigOptions(commandLineOptions);
100
- // The method should return a default config and log an error.
101
- (0, assert_1.default)(nullConsole.infoCount > 0);
102
- });
103
- test('SomeFileSpecsAreInvalid', () => {
104
- const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
105
- const nullConsole = new console_1.NullConsole();
106
- const service = createAnalyzer(nullConsole);
107
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
108
- commandLineOptions.configFilePath = 'src/tests/samples/project4';
109
- service.setOptions(commandLineOptions);
110
- const configOptions = service.test_getConfigOptions(commandLineOptions);
111
- // The config file specifies four file specs in the include array
112
- // and one in the exclude array.
113
- assert_1.default.strictEqual(configOptions.include.length, 4, `failed creating options from ${cwd}`);
114
- assert_1.default.strictEqual(configOptions.exclude.length, 1);
115
- assert_1.default.strictEqual(configOptions.projectRoot.getFilePath(), service.fs
116
- .realCasePath(uri_1.Uri.file((0, pathUtils_1.combinePaths)(cwd, commandLineOptions.configFilePath), service.serviceProvider))
117
- .getFilePath());
118
- const fileList = service.test_getFileNamesFromFileSpecs();
119
- // We should receive two final files that match the include/exclude rules.
120
- assert_1.default.strictEqual(fileList.length, 2);
121
- });
122
- test('ConfigBadJson', () => {
123
- const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
124
- const nullConsole = new console_1.NullConsole();
125
- const service = createAnalyzer(nullConsole);
126
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
127
- commandLineOptions.configFilePath = 'src/tests/samples/project5';
128
- service.setOptions(commandLineOptions);
129
- service.test_getConfigOptions(commandLineOptions);
130
- // The method should return a default config and log an error.
131
- (0, assert_1.default)(nullConsole.infoCount > 0);
132
- });
133
- test('FindExecEnv1', () => {
134
- const cwd = uriUtils_1.UriEx.file((0, pathUtils_1.normalizePath)(process.cwd()));
135
- const configOptions = new configOptions_1.ConfigOptions(cwd);
136
- // Build a config option with three execution environments.
137
- const execEnv1 = new configOptions_1.ExecutionEnvironment('python', cwd.resolvePaths('src/foo'), (0, configOptions_1.getStandardDiagnosticRuleSet)(),
138
- /* defaultPythonVersion */ undefined,
139
- /* defaultPythonPlatform */ undefined,
140
- /* defaultExtraPaths */ undefined);
141
- configOptions.executionEnvironments.push(execEnv1);
142
- const execEnv2 = new configOptions_1.ExecutionEnvironment('python', cwd.resolvePaths('src'), (0, configOptions_1.getStandardDiagnosticRuleSet)(),
143
- /* defaultPythonVersion */ undefined,
144
- /* defaultPythonPlatform */ undefined,
145
- /* defaultExtraPaths */ undefined);
146
- configOptions.executionEnvironments.push(execEnv2);
147
- const file1 = cwd.resolvePaths('src/foo/bar.py');
148
- assert_1.default.strictEqual(configOptions.findExecEnvironment(file1), execEnv1);
149
- const file2 = cwd.resolvePaths('src/foo2/bar.py');
150
- assert_1.default.strictEqual(configOptions.findExecEnvironment(file2), execEnv2);
151
- // If none of the execution environments matched, we should get
152
- // a default environment with the root equal to that of the config.
153
- const file4 = uriUtils_1.UriEx.file('/nothing/bar.py');
154
- const defaultExecEnv = configOptions.findExecEnvironment(file4);
155
- (0, assert_1.default)(defaultExecEnv.root);
156
- const rootFilePath = uri_1.Uri.is(defaultExecEnv.root) ? defaultExecEnv.root.getFilePath() : defaultExecEnv.root;
157
- assert_1.default.strictEqual((0, pathUtils_1.normalizeSlashes)(rootFilePath), (0, pathUtils_1.normalizeSlashes)(configOptions.projectRoot.getFilePath()));
158
- });
159
- test('PythonPlatform', () => {
160
- const nullConsole = new console_1.NullConsole();
161
- const service = createAnalyzer(nullConsole);
162
- const cwd = uri_1.Uri.file((0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_pyproject_toml_platform')), service.serviceProvider);
163
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd.getFilePath(), /* fromLanguageServer */ false);
164
- service.setOptions(commandLineOptions);
165
- const configOptions = service.test_getConfigOptions(commandLineOptions);
166
- assert_1.default.ok(configOptions.executionEnvironments[0]);
167
- assert_1.default.equal(configOptions.executionEnvironments[0].pythonPlatform, 'platform');
168
- });
169
- test('AutoSearchPathsOn', () => {
170
- const nullConsole = new console_1.NullConsole();
171
- const service = createAnalyzer(nullConsole);
172
- const cwd = uri_1.Uri.file((0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_src')), service.serviceProvider);
173
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd.getFilePath(), /* fromLanguageServer */ false);
174
- commandLineOptions.configSettings.autoSearchPaths = true;
175
- service.setOptions(commandLineOptions);
176
- const configOptions = service.test_getConfigOptions(commandLineOptions);
177
- const expectedExtraPaths = [service.fs.realCasePath(cwd.combinePaths('src'))];
178
- assert_1.default.deepStrictEqual(configOptions.defaultExtraPaths, expectedExtraPaths);
179
- });
180
- test('AutoSearchPathsOff', () => {
181
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_src'));
182
- const nullConsole = new console_1.NullConsole();
183
- const service = createAnalyzer(nullConsole);
184
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
185
- commandLineOptions.configSettings.autoSearchPaths = false;
186
- service.setOptions(commandLineOptions);
187
- const configOptions = service.test_getConfigOptions(commandLineOptions);
188
- assert_1.default.deepStrictEqual(configOptions.executionEnvironments, []);
189
- });
190
- test('AutoSearchPathsOnSrcIsPkg', () => {
191
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_src_is_pkg'));
192
- const nullConsole = new console_1.NullConsole();
193
- const service = createAnalyzer(nullConsole);
194
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
195
- commandLineOptions.configSettings.autoSearchPaths = true;
196
- service.setOptions(commandLineOptions);
197
- const configOptions = service.test_getConfigOptions(commandLineOptions);
198
- // The src folder is a package (has __init__.py) and so should not be automatically added as extra path
199
- assert_1.default.deepStrictEqual(configOptions.executionEnvironments, []);
200
- });
201
- test('AutoSearchPathsOnWithConfigExecEnv', () => {
202
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_src_with_config_extra_paths'));
203
- const nullConsole = new console_1.NullConsole();
204
- const service = createAnalyzer(nullConsole);
205
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
206
- commandLineOptions.configFilePath = (0, pathUtils_1.combinePaths)(cwd, 'pyrightconfig.json');
207
- commandLineOptions.configSettings.autoSearchPaths = true;
208
- service.setOptions(commandLineOptions);
209
- const configOptions = service.test_getConfigOptions(commandLineOptions);
210
- // The extraPaths in the config file should override the setting.
211
- const expectedExtraPaths = [];
212
- assert_1.default.deepStrictEqual(configOptions.defaultExtraPaths, expectedExtraPaths);
213
- });
214
- test('AutoSearchPathsOnAndExtraPaths', () => {
215
- const nullConsole = new console_1.NullConsole();
216
- const service = createAnalyzer(nullConsole);
217
- const cwd = uri_1.Uri.file((0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_src_with_config_no_extra_paths')), service.serviceProvider);
218
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd.getFilePath(), /* fromLanguageServer */ false);
219
- commandLineOptions.configSettings.autoSearchPaths = true;
220
- commandLineOptions.configSettings.extraPaths = ['src/_vendored'];
221
- service.setOptions(commandLineOptions);
222
- const configOptions = service.test_getConfigOptions(commandLineOptions);
223
- const expectedExtraPaths = [
224
- service.fs.realCasePath(cwd.combinePaths('src')),
225
- service.fs.realCasePath(cwd.combinePaths('src', '_vendored')),
226
- ];
227
- assert_1.default.deepStrictEqual(configOptions.defaultExtraPaths, expectedExtraPaths);
228
- });
229
- test('BasicPyprojectTomlParsing', () => {
230
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_pyproject_toml'));
231
- const service = createAnalyzer();
232
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
233
- service.setOptions(commandLineOptions);
234
- const configOptions = service.test_getConfigOptions(commandLineOptions);
235
- assert_1.default.strictEqual(configOptions.defaultPythonVersion.toString(), pythonVersion_1.pythonVersion3_9.toString());
236
- assert_1.default.strictEqual(configOptions.diagnosticRuleSet.reportMissingImports, 'error');
237
- assert_1.default.strictEqual(configOptions.diagnosticRuleSet.reportUnusedClass, 'warning');
238
- });
239
- test('FindFilesInMemoryOnly', () => {
240
- const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
241
- const service = createAnalyzer();
242
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(undefined, /* fromLanguageServer */ true);
243
- // Force a lookup of the typeshed path. This causes us to try and generate a module path for the untitled file.
244
- commandLineOptions.configSettings.typeshedPath = (0, pathUtils_1.combinePaths)(cwd, 'src', 'tests', 'samples');
245
- service.setOptions(commandLineOptions);
246
- // Open a file that is not backed by the file system.
247
- const untitled = uri_1.Uri.parse('untitled:Untitled-1.py', service.serviceProvider);
248
- service.setFileOpened(untitled, 1, '# empty');
249
- const fileList = service.test_getFileNamesFromFileSpecs();
250
- (0, assert_1.default)(fileList.filter((f) => f.equals(untitled)));
251
- });
252
- test('verify config fileSpecs after cloning', () => {
253
- const fs = new filesystem_1.TestFileSystem(/* ignoreCase */ true);
254
- const configFile = {
255
- ignore: ['**/node_modules/**'],
256
- };
257
- const rootUri = uri_1.Uri.file(process.cwd(), fs);
258
- const config = new configOptions_1.ConfigOptions(rootUri);
259
- const sp = (0, serviceProviderExtensions_1.createServiceProvider)(fs, new console_1.NullConsole());
260
- config.initializeFromJson(configFile, rootUri, sp, new testAccessHost_1.TestAccessHost());
261
- const cloned = (0, backgroundThreadBase_1.deserialize)((0, backgroundThreadBase_1.serialize)(config));
262
- assert_1.default.deepEqual(config.ignore, cloned.ignore);
263
- });
264
- test('verify can serialize config options', () => {
265
- const config = new configOptions_1.ConfigOptions(uriUtils_1.UriEx.file(process.cwd()));
266
- const serialized = (0, backgroundThreadBase_1.serialize)(config);
267
- const deserialized = (0, backgroundThreadBase_1.deserialize)(serialized);
268
- assert_1.default.deepEqual(config, deserialized);
269
- assert_1.default.ok(deserialized.findExecEnvironment(uriUtils_1.UriEx.file('foo/bar.py')));
270
- });
271
- test('extra paths on undefined execution root/default workspace', () => {
272
- const nullConsole = new console_1.NullConsole();
273
- const service = createAnalyzer(nullConsole);
274
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(undefined, /* fromLanguageServer */ false);
275
- commandLineOptions.configSettings.extraPaths = ['/extraPaths'];
276
- service.setOptions(commandLineOptions);
277
- const configOptions = service.test_getConfigOptions(commandLineOptions);
278
- const expectedExtraPaths = [uri_1.Uri.file('/extraPaths', service.serviceProvider)];
279
- assert_1.default.deepStrictEqual(configOptions.defaultExtraPaths?.map((u) => u.getFilePath()), expectedExtraPaths.map((u) => u.getFilePath()));
280
- });
281
- test('Extended config files', () => {
282
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_extended_config'));
283
- const service = createAnalyzer();
284
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
285
- service.setOptions(commandLineOptions);
286
- const fileList = service.test_getFileNamesFromFileSpecs();
287
- const fileNames = fileList.map((p) => p.fileName).sort();
288
- assert_1.default.deepStrictEqual(fileNames, ['sample.pyi', 'test.py']);
289
- const configOptions = service.test_getConfigOptions(commandLineOptions);
290
- assert_1.default.equal(configOptions.diagnosticRuleSet.strictListInference, true);
291
- });
292
- test('Typechecking mode is standard when just config file is present', () => {
293
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_pyproject_toml'));
294
- const service = createAnalyzer();
295
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
296
- commandLineOptions.configSettings.typeCheckingMode = 'off';
297
- service.setOptions(commandLineOptions);
298
- const configOptions = service.test_getConfigOptions(commandLineOptions);
299
- assert_1.default.equal(configOptions.diagnosticRuleSet.reportPossiblyUnboundVariable, 'error');
300
- });
301
- test('Typechecking mode depends upon if vscode extension or not', () => {
302
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/package1'));
303
- let service = createAnalyzer();
304
- let commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
305
- service.setOptions(commandLineOptions);
306
- let configOptions = service.test_getConfigOptions(commandLineOptions);
307
- assert_1.default.equal(configOptions.diagnosticRuleSet.reportPossiblyUnboundVariable, 'none');
308
- service = createAnalyzer();
309
- commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
310
- service.setOptions(commandLineOptions);
311
- configOptions = service.test_getConfigOptions(commandLineOptions);
312
- assert_1.default.equal(configOptions.diagnosticRuleSet.reportPossiblyUnboundVariable, 'error');
313
- commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
314
- commandLineOptions.configSettings.typeCheckingMode = 'strict';
315
- service = createAnalyzer();
316
- service.setOptions(commandLineOptions);
317
- configOptions = service.test_getConfigOptions(commandLineOptions);
318
- assert_1.default.equal(configOptions.diagnosticRuleSet.reportPossiblyUnboundVariable, 'error');
319
- });
320
- test('Include file paths are only set in the config file when using extension', () => {
321
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project1'));
322
- const service = createAnalyzer();
323
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
324
- commandLineOptions.configSettings.includeFileSpecs = ['test'];
325
- service.setOptions(commandLineOptions);
326
- const configOptions = service.test_getConfigOptions(commandLineOptions);
327
- assert_1.default.equal(configOptions.include.length, 1);
328
- assert_1.default.ok(configOptions.include[0].regExp.source.includes('/subfolder1)'));
329
- });
330
- test('Include file paths can be added to on the command line with a config', () => {
331
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project1'));
332
- const service = createAnalyzer();
333
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
334
- commandLineOptions.configSettings.includeFileSpecs = ['test'];
335
- service.setOptions(commandLineOptions);
336
- const configOptions = service.test_getConfigOptions(commandLineOptions);
337
- assert_1.default.equal(configOptions.include.length, 2);
338
- assert_1.default.ok(configOptions.include[1].regExp.source.includes('/test)'));
339
- });
340
- test('Include file paths can be added to by an extension without a config', () => {
341
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/package1'));
342
- const service = createAnalyzer();
343
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
344
- commandLineOptions.configSettings.includeFileSpecs = ['test'];
345
- service.setOptions(commandLineOptions);
346
- const configOptions = service.test_getConfigOptions(commandLineOptions);
347
- assert_1.default.equal(configOptions.include.length, 1);
348
- assert_1.default.ok(configOptions.include[0].regExp.source.includes('/test)'));
349
- });
350
- test('Command line options can override config but only when not using extension', () => {
351
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_all_config'));
352
- const service = createAnalyzer();
353
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
354
- service.setOptions(commandLineOptions);
355
- // First get the default.
356
- const defaultOptions = service.test_getConfigOptions(commandLineOptions);
357
- // Now set all of the different options and make sure the command line options override.
358
- commandLineOptions.configSettings.typeCheckingMode = 'strict';
359
- commandLineOptions.configSettings.venvPath = 'test2';
360
- commandLineOptions.configSettings.typeshedPath = 'test2';
361
- commandLineOptions.configSettings.stubPath = 'test2';
362
- commandLineOptions.configSettings.useLibraryCodeForTypes = true;
363
- commandLineOptions.configSettings.includeFileSpecs = ['test2'];
364
- commandLineOptions.configSettings.excludeFileSpecs = ['test2'];
365
- commandLineOptions.configSettings.diagnosticSeverityOverrides = {
366
- reportMissingImports: "error" /* DiagnosticSeverityOverrides.Error */,
367
- };
368
- commandLineOptions.configSettings.ignoreFileSpecs = ['test2'];
369
- service.setOptions(commandLineOptions);
370
- const overriddenOptions = service.test_getConfigOptions(commandLineOptions);
371
- assert_1.default.notDeepStrictEqual(defaultOptions.include, overriddenOptions.include);
372
- assert_1.default.notDeepStrictEqual(defaultOptions.exclude, overriddenOptions.exclude);
373
- assert_1.default.notDeepStrictEqual(defaultOptions.ignore, overriddenOptions.ignore);
374
- assert_1.default.notDeepStrictEqual(defaultOptions.diagnosticRuleSet, overriddenOptions.diagnosticRuleSet);
375
- assert_1.default.notDeepStrictEqual(defaultOptions.venvPath, overriddenOptions.venvPath);
376
- // Typeshed and stub path are an exception, it should just be reported as a dupe.
377
- assert_1.default.deepStrictEqual(defaultOptions.typeshedPath, overriddenOptions.typeshedPath);
378
- assert_1.default.deepStrictEqual(defaultOptions.stubPath, overriddenOptions.stubPath);
379
- // Do the same with an extension based config, but make sure we get the default back.
380
- const commandLineOptions2 = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
381
- service.setOptions(commandLineOptions2);
382
- const overriddenOptions2 = service.test_getConfigOptions(commandLineOptions2);
383
- assert_1.default.deepStrictEqual(defaultOptions, overriddenOptions2);
384
- });
385
- test('Config venvPath take precedences over language server settings', () => {
386
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_all_config'));
387
- const service = createAnalyzer();
388
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
389
- commandLineOptions.languageServerSettings.venvPath = 'test_from_language_server';
390
- service.setOptions(commandLineOptions);
391
- // Verify language server options don't override
392
- const options = service.test_getConfigOptions(commandLineOptions);
393
- assert_1.default.equal(options.venvPath?.pathIncludes('from_language_server'), false);
394
- });
395
- test('Command line venvPath take precedences over everything else', () => {
396
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_all_config'));
397
- const service = createAnalyzer();
398
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
399
- commandLineOptions.configSettings.venvPath = 'test_from_command_line';
400
- commandLineOptions.languageServerSettings.venvPath = 'test_from_language_server';
401
- service.setOptions(commandLineOptions);
402
- // Verify command line overrides everything
403
- const options = service.test_getConfigOptions(commandLineOptions);
404
- assert_1.default.ok(options.venvPath?.pathIncludes('test_from_command_line'));
405
- });
406
- test('Config empty venvPath does not take precedences over language server settings', () => {
407
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_src_with_config_extra_paths'));
408
- const service = createAnalyzer();
409
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
410
- commandLineOptions.languageServerSettings.venvPath = 'test_from_language_server';
411
- service.setOptions(commandLineOptions);
412
- // Verify language server options don't override
413
- const options = service.test_getConfigOptions(commandLineOptions);
414
- assert_1.default.ok(options.venvPath?.pathIncludes('from_language_server'));
415
- });
416
- test('Language server specific settings are set whether or not there is a pyproject.toml', () => {
417
- const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_all_config'));
418
- const service = createAnalyzer();
419
- const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
420
- commandLineOptions.languageServerSettings.autoImportCompletions = true;
421
- commandLineOptions.languageServerSettings.indexing = true;
422
- commandLineOptions.languageServerSettings.taskListTokens = [{ priority: diagnostic_1.TaskListPriority.High, text: 'test' }];
423
- commandLineOptions.languageServerSettings.logTypeEvaluationTime = true;
424
- commandLineOptions.languageServerSettings.typeEvaluationTimeThreshold = 1;
425
- commandLineOptions.languageServerSettings.enableAmbientAnalysis = false;
426
- commandLineOptions.languageServerSettings.disableTaggedHints = true;
427
- commandLineOptions.languageServerSettings.watchForSourceChanges = true;
428
- commandLineOptions.languageServerSettings.watchForLibraryChanges = true;
429
- commandLineOptions.languageServerSettings.watchForConfigChanges = true;
430
- commandLineOptions.languageServerSettings.typeStubTargetImportName = 'test';
431
- commandLineOptions.languageServerSettings.checkOnlyOpenFiles = true;
432
- commandLineOptions.languageServerSettings.disableTaggedHints = true;
433
- commandLineOptions.languageServerSettings.pythonPath = 'test_python_path';
434
- service.setOptions(commandLineOptions);
435
- let options = service.test_getConfigOptions(commandLineOptions);
436
- assert_1.default.strictEqual(options.autoImportCompletions, true);
437
- assert_1.default.strictEqual(options.indexing, true);
438
- assert_1.default.strictEqual(options.taskListTokens?.length, 1);
439
- assert_1.default.strictEqual(options.logTypeEvaluationTime, true);
440
- assert_1.default.strictEqual(options.typeEvaluationTimeThreshold, 1);
441
- assert_1.default.strictEqual(options.disableTaggedHints, true);
442
- assert_1.default.ok(options.pythonPath?.pathIncludes('test_python_path'));
443
- // Test with language server set to true to make sure they are still set.
444
- commandLineOptions.fromLanguageServer = true;
445
- commandLineOptions.languageServerSettings.venvPath = 'test_venv_path';
446
- service.setOptions(commandLineOptions);
447
- options = service.test_getConfigOptions(commandLineOptions);
448
- assert_1.default.strictEqual(options.autoImportCompletions, true);
449
- assert_1.default.strictEqual(options.indexing, true);
450
- assert_1.default.strictEqual(options.taskListTokens?.length, 1);
451
- assert_1.default.strictEqual(options.logTypeEvaluationTime, true);
452
- assert_1.default.strictEqual(options.typeEvaluationTimeThreshold, 1);
453
- assert_1.default.strictEqual(options.disableTaggedHints, true);
454
- assert_1.default.ok(options.pythonPath?.pathIncludes('test_python_path'));
455
- // Verify language server options don't override the config setting. Only command line should
456
- assert_1.default.equal(options.venvPath?.pathIncludes('test_venv_path'), false);
31
+ afterAll(() => tempFile.dispose());
32
+ test('FindFilesWithConfigFile', () => {
33
+ const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
34
+ const service = createAnalyzer();
35
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
36
+ commandLineOptions.configFilePath = 'src/tests/samples/project1';
37
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
38
+ service.setOptions(commandLineOptions);
39
+ // The config file specifies a single file spec (a directory).
40
+ assert_1.default.strictEqual(configOptions.include.length, 1, `failed creating options from ${cwd}`);
41
+ assert_1.default.strictEqual(configOptions.projectRoot.key, service.fs.realCasePath(uri_1.Uri.file((0, pathUtils_1.combinePaths)(cwd, commandLineOptions.configFilePath), service.serviceProvider)).key);
42
+ const fileList = service.test_getFileNamesFromFileSpecs();
43
+ // The config file specifies a subdirectory, so we should find
44
+ // only two of the three "*.py" files present in the project
45
+ // directory.
46
+ assert_1.default.strictEqual(fileList.length, 2);
47
+ });
48
+ test('FindFilesVirtualEnvAutoDetectExclude', () => {
49
+ const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
50
+ const service = createAnalyzer();
51
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
52
+ commandLineOptions.configFilePath = 'src/tests/samples/project_with_venv_auto_detect_exclude';
53
+ service.setOptions(commandLineOptions);
54
+ // The config file is empty, so no 'exclude' are specified
55
+ // The myVenv directory is detected as a venv and will be automatically excluded
56
+ const fileList = service.test_getFileNamesFromFileSpecs();
57
+ // There are 3 python files in the workspace, outside of myVenv
58
+ // There is 1 python file in myVenv, which should be excluded
59
+ const fileNames = fileList.map((p) => p.fileName).sort();
60
+ assert_1.default.deepStrictEqual(fileNames, ['sample1.py', 'sample2.py', 'sample3.py']);
61
+ });
62
+ test('FindFilesVirtualEnvAutoDetectInclude', () => {
63
+ const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
64
+ const service = createAnalyzer();
65
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
66
+ commandLineOptions.configFilePath = 'src/tests/samples/project_with_venv_auto_detect_include';
67
+ service.setOptions(commandLineOptions);
68
+ // Config file defines 'exclude' folder so virtual env will be included
69
+ const fileList = service.test_getFileNamesFromFileSpecs();
70
+ // There are 3 python files in the workspace, outside of myVenv
71
+ // There is 1 more python file in excluded folder
72
+ // There is 1 python file in myVenv, which should be included
73
+ const fileNames = fileList.map((p) => p.fileName).sort();
74
+ assert_1.default.deepStrictEqual(fileNames, ['library1.py', 'sample1.py', 'sample2.py', 'sample3.py']);
75
+ });
76
+ test('FileSpecNotAnArray', () => {
77
+ const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
78
+ const nullConsole = new console_1.NullConsole();
79
+ const service = createAnalyzer(nullConsole);
80
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
81
+ commandLineOptions.configFilePath = 'src/tests/samples/project2';
82
+ service.setOptions(commandLineOptions);
83
+ service.test_getConfigOptions(commandLineOptions);
84
+ // The method should return a default config and log an error.
85
+ (0, assert_1.default)(nullConsole.infoCount > 0);
86
+ });
87
+ test('FileSpecNotAString', () => {
88
+ const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
89
+ const nullConsole = new console_1.NullConsole();
90
+ const service = createAnalyzer(nullConsole);
91
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
92
+ commandLineOptions.configFilePath = 'src/tests/samples/project3';
93
+ service.setOptions(commandLineOptions);
94
+ service.test_getConfigOptions(commandLineOptions);
95
+ // The method should return a default config and log an error.
96
+ (0, assert_1.default)(nullConsole.infoCount > 0);
97
+ });
98
+ test('SomeFileSpecsAreInvalid', () => {
99
+ const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
100
+ const nullConsole = new console_1.NullConsole();
101
+ const service = createAnalyzer(nullConsole);
102
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
103
+ commandLineOptions.configFilePath = 'src/tests/samples/project4';
104
+ service.setOptions(commandLineOptions);
105
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
106
+ // The config file specifies four file specs in the include array
107
+ // and one in the exclude array.
108
+ assert_1.default.strictEqual(configOptions.include.length, 4, `failed creating options from ${cwd}`);
109
+ assert_1.default.strictEqual(configOptions.exclude.length, 1);
110
+ assert_1.default.strictEqual(configOptions.projectRoot.getFilePath(), service.fs
111
+ .realCasePath(uri_1.Uri.file((0, pathUtils_1.combinePaths)(cwd, commandLineOptions.configFilePath), service.serviceProvider))
112
+ .getFilePath());
113
+ const fileList = service.test_getFileNamesFromFileSpecs();
114
+ // We should receive two final files that match the include/exclude rules.
115
+ assert_1.default.strictEqual(fileList.length, 2);
116
+ });
117
+ test('ConfigBadJson', () => {
118
+ const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
119
+ const nullConsole = new console_1.NullConsole();
120
+ const service = createAnalyzer(nullConsole);
121
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
122
+ commandLineOptions.configFilePath = 'src/tests/samples/project5';
123
+ service.setOptions(commandLineOptions);
124
+ service.test_getConfigOptions(commandLineOptions);
125
+ // The method should return a default config and log an error.
126
+ (0, assert_1.default)(nullConsole.infoCount > 0);
127
+ });
128
+ test('FindExecEnv1', () => {
129
+ const cwd = uriUtils_1.UriEx.file((0, pathUtils_1.normalizePath)(process.cwd()));
130
+ const configOptions = new configOptions_1.ConfigOptions(cwd);
131
+ // Build a config option with three execution environments.
132
+ const execEnv1 = new configOptions_1.ExecutionEnvironment('python', cwd.resolvePaths('src/foo'), (0, configOptions_1.getStandardDiagnosticRuleSet)(),
133
+ /* defaultPythonVersion */ undefined,
134
+ /* defaultPythonPlatform */ undefined,
135
+ /* defaultExtraPaths */ undefined);
136
+ configOptions.executionEnvironments.push(execEnv1);
137
+ const execEnv2 = new configOptions_1.ExecutionEnvironment('python', cwd.resolvePaths('src'), (0, configOptions_1.getStandardDiagnosticRuleSet)(),
138
+ /* defaultPythonVersion */ undefined,
139
+ /* defaultPythonPlatform */ undefined,
140
+ /* defaultExtraPaths */ undefined);
141
+ configOptions.executionEnvironments.push(execEnv2);
142
+ const file1 = cwd.resolvePaths('src/foo/bar.py');
143
+ assert_1.default.strictEqual(configOptions.findExecEnvironment(file1), execEnv1);
144
+ const file2 = cwd.resolvePaths('src/foo2/bar.py');
145
+ assert_1.default.strictEqual(configOptions.findExecEnvironment(file2), execEnv2);
146
+ // If none of the execution environments matched, we should get
147
+ // a default environment with the root equal to that of the config.
148
+ const file4 = uriUtils_1.UriEx.file('/nothing/bar.py');
149
+ const defaultExecEnv = configOptions.findExecEnvironment(file4);
150
+ (0, assert_1.default)(defaultExecEnv.root);
151
+ const rootFilePath = uri_1.Uri.is(defaultExecEnv.root) ? defaultExecEnv.root.getFilePath() : defaultExecEnv.root;
152
+ assert_1.default.strictEqual((0, pathUtils_1.normalizeSlashes)(rootFilePath), (0, pathUtils_1.normalizeSlashes)(configOptions.projectRoot.getFilePath()));
153
+ });
154
+ test('PythonPlatform', () => {
155
+ const nullConsole = new console_1.NullConsole();
156
+ const service = createAnalyzer(nullConsole);
157
+ const cwd = uri_1.Uri.file((0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_pyproject_toml_platform')), service.serviceProvider);
158
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd.getFilePath(), /* fromLanguageServer */ false);
159
+ service.setOptions(commandLineOptions);
160
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
161
+ assert_1.default.ok(configOptions.executionEnvironments[0]);
162
+ assert_1.default.equal(configOptions.executionEnvironments[0].pythonPlatform, 'platform');
163
+ });
164
+ test('AutoSearchPathsOn', () => {
165
+ const nullConsole = new console_1.NullConsole();
166
+ const service = createAnalyzer(nullConsole);
167
+ const cwd = uri_1.Uri.file((0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_src')), service.serviceProvider);
168
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd.getFilePath(), /* fromLanguageServer */ false);
169
+ commandLineOptions.configSettings.autoSearchPaths = true;
170
+ service.setOptions(commandLineOptions);
171
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
172
+ const expectedExtraPaths = [service.fs.realCasePath(cwd.combinePaths('src'))];
173
+ assert_1.default.deepStrictEqual(configOptions.defaultExtraPaths, expectedExtraPaths);
174
+ });
175
+ test('AutoSearchPathsOff', () => {
176
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_src'));
177
+ const nullConsole = new console_1.NullConsole();
178
+ const service = createAnalyzer(nullConsole);
179
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
180
+ commandLineOptions.configSettings.autoSearchPaths = false;
181
+ service.setOptions(commandLineOptions);
182
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
183
+ assert_1.default.deepStrictEqual(configOptions.executionEnvironments, []);
184
+ });
185
+ test('AutoSearchPathsOnSrcIsPkg', () => {
186
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_src_is_pkg'));
187
+ const nullConsole = new console_1.NullConsole();
188
+ const service = createAnalyzer(nullConsole);
189
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
190
+ commandLineOptions.configSettings.autoSearchPaths = true;
191
+ service.setOptions(commandLineOptions);
192
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
193
+ // The src folder is a package (has __init__.py) and so should not be automatically added as extra path
194
+ assert_1.default.deepStrictEqual(configOptions.executionEnvironments, []);
195
+ });
196
+ test('AutoSearchPathsOnWithConfigExecEnv', () => {
197
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_src_with_config_extra_paths'));
198
+ const nullConsole = new console_1.NullConsole();
199
+ const service = createAnalyzer(nullConsole);
200
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
201
+ commandLineOptions.configFilePath = (0, pathUtils_1.combinePaths)(cwd, 'pyrightconfig.json');
202
+ commandLineOptions.configSettings.autoSearchPaths = true;
203
+ service.setOptions(commandLineOptions);
204
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
205
+ // The extraPaths in the config file should override the setting.
206
+ const expectedExtraPaths = [];
207
+ assert_1.default.deepStrictEqual(configOptions.defaultExtraPaths, expectedExtraPaths);
208
+ });
209
+ test('AutoSearchPathsOnAndExtraPaths', () => {
210
+ const nullConsole = new console_1.NullConsole();
211
+ const service = createAnalyzer(nullConsole);
212
+ const cwd = uri_1.Uri.file((0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_src_with_config_no_extra_paths')), service.serviceProvider);
213
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd.getFilePath(), /* fromLanguageServer */ false);
214
+ commandLineOptions.configSettings.autoSearchPaths = true;
215
+ commandLineOptions.configSettings.extraPaths = ['src/_vendored'];
216
+ service.setOptions(commandLineOptions);
217
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
218
+ const expectedExtraPaths = [
219
+ service.fs.realCasePath(cwd.combinePaths('src')),
220
+ service.fs.realCasePath(cwd.combinePaths('src', '_vendored')),
221
+ ];
222
+ assert_1.default.deepStrictEqual(configOptions.defaultExtraPaths, expectedExtraPaths);
223
+ });
224
+ test('BasicPyprojectTomlParsing', () => {
225
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_pyproject_toml'));
226
+ const service = createAnalyzer();
227
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
228
+ service.setOptions(commandLineOptions);
229
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
230
+ assert_1.default.strictEqual(configOptions.defaultPythonVersion.toString(), pythonVersion_1.pythonVersion3_9.toString());
231
+ assert_1.default.strictEqual(configOptions.diagnosticRuleSet.reportMissingImports, 'error');
232
+ assert_1.default.strictEqual(configOptions.diagnosticRuleSet.reportUnusedClass, 'warning');
233
+ });
234
+ test('FindFilesInMemoryOnly', () => {
235
+ const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
236
+ const service = createAnalyzer();
237
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(undefined, /* fromLanguageServer */ true);
238
+ // Force a lookup of the typeshed path. This causes us to try and generate a module path for the untitled file.
239
+ commandLineOptions.configSettings.typeshedPath = (0, pathUtils_1.combinePaths)(cwd, 'src', 'tests', 'samples');
240
+ service.setOptions(commandLineOptions);
241
+ // Open a file that is not backed by the file system.
242
+ const untitled = uri_1.Uri.parse('untitled:Untitled-1.py', service.serviceProvider);
243
+ service.setFileOpened(untitled, 1, '# empty');
244
+ const fileList = service.test_getFileNamesFromFileSpecs();
245
+ (0, assert_1.default)(fileList.filter((f) => f.equals(untitled)));
246
+ });
247
+ test('verify config fileSpecs after cloning', () => {
248
+ const fs = new filesystem_1.TestFileSystem(/* ignoreCase */ true);
249
+ const configFile = {
250
+ ignore: ['**/node_modules/**'],
251
+ };
252
+ const rootUri = uri_1.Uri.file(process.cwd(), fs);
253
+ const config = new configOptions_1.ConfigOptions(rootUri);
254
+ const sp = (0, serviceProviderExtensions_1.createServiceProvider)(fs, new console_1.NullConsole());
255
+ config.initializeFromJson(configFile, rootUri, sp, new testAccessHost_1.TestAccessHost());
256
+ const cloned = (0, backgroundThreadBase_1.deserialize)((0, backgroundThreadBase_1.serialize)(config));
257
+ assert_1.default.deepEqual(config.ignore, cloned.ignore);
258
+ });
259
+ test('verify can serialize config options', () => {
260
+ const config = new configOptions_1.ConfigOptions(uriUtils_1.UriEx.file(process.cwd()));
261
+ const serialized = (0, backgroundThreadBase_1.serialize)(config);
262
+ const deserialized = (0, backgroundThreadBase_1.deserialize)(serialized);
263
+ assert_1.default.deepEqual(config, deserialized);
264
+ assert_1.default.ok(deserialized.findExecEnvironment(uriUtils_1.UriEx.file('foo/bar.py')));
265
+ });
266
+ test('extra paths on undefined execution root/default workspace', () => {
267
+ const nullConsole = new console_1.NullConsole();
268
+ const service = createAnalyzer(nullConsole);
269
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(undefined, /* fromLanguageServer */ false);
270
+ commandLineOptions.configSettings.extraPaths = ['/extraPaths'];
271
+ service.setOptions(commandLineOptions);
272
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
273
+ const expectedExtraPaths = [uri_1.Uri.file('/extraPaths', service.serviceProvider)];
274
+ assert_1.default.deepStrictEqual(configOptions.defaultExtraPaths?.map((u) => u.getFilePath()), expectedExtraPaths.map((u) => u.getFilePath()));
275
+ });
276
+ test('Extended config files', () => {
277
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_extended_config'));
278
+ const service = createAnalyzer();
279
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
280
+ service.setOptions(commandLineOptions);
281
+ const fileList = service.test_getFileNamesFromFileSpecs();
282
+ const fileNames = fileList.map((p) => p.fileName).sort();
283
+ assert_1.default.deepStrictEqual(fileNames, ['sample.pyi', 'test.py']);
284
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
285
+ assert_1.default.equal(configOptions.diagnosticRuleSet.strictListInference, true);
286
+ });
287
+ test('Typechecking mode is standard when just config file is present', () => {
288
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_pyproject_toml'));
289
+ const service = createAnalyzer();
290
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
291
+ commandLineOptions.configSettings.typeCheckingMode = 'off';
292
+ service.setOptions(commandLineOptions);
293
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
294
+ assert_1.default.equal(configOptions.diagnosticRuleSet.reportPossiblyUnboundVariable, 'error');
295
+ });
296
+ test('Typechecking mode depends upon if vscode extension or not', () => {
297
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/package1'));
298
+ let service = createAnalyzer();
299
+ let commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
300
+ service.setOptions(commandLineOptions);
301
+ let configOptions = service.test_getConfigOptions(commandLineOptions);
302
+ assert_1.default.equal(configOptions.diagnosticRuleSet.reportPossiblyUnboundVariable, 'none');
303
+ service = createAnalyzer();
304
+ commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
305
+ service.setOptions(commandLineOptions);
306
+ configOptions = service.test_getConfigOptions(commandLineOptions);
307
+ assert_1.default.equal(configOptions.diagnosticRuleSet.reportPossiblyUnboundVariable, 'error');
308
+ commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
309
+ commandLineOptions.configSettings.typeCheckingMode = 'strict';
310
+ service = createAnalyzer();
311
+ service.setOptions(commandLineOptions);
312
+ configOptions = service.test_getConfigOptions(commandLineOptions);
313
+ assert_1.default.equal(configOptions.diagnosticRuleSet.reportPossiblyUnboundVariable, 'error');
314
+ });
315
+ test('Include file paths are only set in the config file when using extension', () => {
316
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project1'));
317
+ const service = createAnalyzer();
318
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
319
+ commandLineOptions.configSettings.includeFileSpecs = ['test'];
320
+ service.setOptions(commandLineOptions);
321
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
322
+ assert_1.default.equal(configOptions.include.length, 1);
323
+ assert_1.default.ok(configOptions.include[0].regExp.source.includes('/subfolder1)'));
324
+ });
325
+ test('Include file paths can be added to on the command line with a config', () => {
326
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project1'));
327
+ const service = createAnalyzer();
328
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
329
+ commandLineOptions.configSettings.includeFileSpecs = ['test'];
330
+ service.setOptions(commandLineOptions);
331
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
332
+ assert_1.default.equal(configOptions.include.length, 2);
333
+ assert_1.default.ok(configOptions.include[1].regExp.source.includes('/test)'));
334
+ });
335
+ test('Include file paths can be added to by an extension without a config', () => {
336
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/package1'));
337
+ const service = createAnalyzer();
338
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
339
+ commandLineOptions.configSettings.includeFileSpecs = ['test'];
340
+ service.setOptions(commandLineOptions);
341
+ const configOptions = service.test_getConfigOptions(commandLineOptions);
342
+ assert_1.default.equal(configOptions.include.length, 1);
343
+ assert_1.default.ok(configOptions.include[0].regExp.source.includes('/test)'));
344
+ });
345
+ test('Command line options can override config but only when not using extension', () => {
346
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_all_config'));
347
+ const service = createAnalyzer();
348
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
349
+ service.setOptions(commandLineOptions);
350
+ // First get the default.
351
+ const defaultOptions = service.test_getConfigOptions(commandLineOptions);
352
+ // Now set all of the different options and make sure the command line options override.
353
+ commandLineOptions.configSettings.typeCheckingMode = 'strict';
354
+ commandLineOptions.configSettings.venvPath = 'test2';
355
+ commandLineOptions.configSettings.typeshedPath = 'test2';
356
+ commandLineOptions.configSettings.stubPath = 'test2';
357
+ commandLineOptions.configSettings.useLibraryCodeForTypes = true;
358
+ commandLineOptions.configSettings.includeFileSpecs = ['test2'];
359
+ commandLineOptions.configSettings.excludeFileSpecs = ['test2'];
360
+ commandLineOptions.configSettings.diagnosticSeverityOverrides = {
361
+ reportMissingImports: "error" /* DiagnosticSeverityOverrides.Error */,
362
+ };
363
+ commandLineOptions.configSettings.ignoreFileSpecs = ['test2'];
364
+ service.setOptions(commandLineOptions);
365
+ const overriddenOptions = service.test_getConfigOptions(commandLineOptions);
366
+ assert_1.default.notDeepStrictEqual(defaultOptions.include, overriddenOptions.include);
367
+ assert_1.default.notDeepStrictEqual(defaultOptions.exclude, overriddenOptions.exclude);
368
+ assert_1.default.notDeepStrictEqual(defaultOptions.ignore, overriddenOptions.ignore);
369
+ assert_1.default.notDeepStrictEqual(defaultOptions.diagnosticRuleSet, overriddenOptions.diagnosticRuleSet);
370
+ assert_1.default.notDeepStrictEqual(defaultOptions.venvPath, overriddenOptions.venvPath);
371
+ // Typeshed and stub path are an exception, it should just be reported as a dupe.
372
+ assert_1.default.deepStrictEqual(defaultOptions.typeshedPath, overriddenOptions.typeshedPath);
373
+ assert_1.default.deepStrictEqual(defaultOptions.stubPath, overriddenOptions.stubPath);
374
+ // Do the same with an extension based config, but make sure we get the default back.
375
+ const commandLineOptions2 = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
376
+ service.setOptions(commandLineOptions2);
377
+ const overriddenOptions2 = service.test_getConfigOptions(commandLineOptions2);
378
+ assert_1.default.deepStrictEqual(defaultOptions, overriddenOptions2);
379
+ });
380
+ test('Config venvPath take precedences over language server settings', () => {
381
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_all_config'));
382
+ const service = createAnalyzer();
383
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
384
+ commandLineOptions.languageServerSettings.venvPath = 'test_from_language_server';
385
+ service.setOptions(commandLineOptions);
386
+ // Verify language server options don't override
387
+ const options = service.test_getConfigOptions(commandLineOptions);
388
+ assert_1.default.equal(options.venvPath?.pathIncludes('from_language_server'), false);
389
+ });
390
+ test('Command line venvPath take precedences over everything else', () => {
391
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_all_config'));
392
+ const service = createAnalyzer();
393
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
394
+ commandLineOptions.configSettings.venvPath = 'test_from_command_line';
395
+ commandLineOptions.languageServerSettings.venvPath = 'test_from_language_server';
396
+ service.setOptions(commandLineOptions);
397
+ // Verify command line overrides everything
398
+ const options = service.test_getConfigOptions(commandLineOptions);
399
+ assert_1.default.ok(options.venvPath?.pathIncludes('test_from_command_line'));
400
+ });
401
+ test('Config empty venvPath does not take precedences over language server settings', () => {
402
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_src_with_config_extra_paths'));
403
+ const service = createAnalyzer();
404
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ true);
405
+ commandLineOptions.languageServerSettings.venvPath = 'test_from_language_server';
406
+ service.setOptions(commandLineOptions);
407
+ // Verify language server options don't override
408
+ const options = service.test_getConfigOptions(commandLineOptions);
409
+ assert_1.default.ok(options.venvPath?.pathIncludes('from_language_server'));
410
+ });
411
+ test('Language server specific settings are set whether or not there is a pyproject.toml', () => {
412
+ const cwd = (0, pathUtils_1.normalizePath)((0, pathUtils_1.combinePaths)(process.cwd(), 'src/tests/samples/project_with_all_config'));
413
+ const service = createAnalyzer();
414
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
415
+ commandLineOptions.languageServerSettings.autoImportCompletions = true;
416
+ commandLineOptions.languageServerSettings.indexing = true;
417
+ commandLineOptions.languageServerSettings.taskListTokens = [{ priority: diagnostic_1.TaskListPriority.High, text: 'test' }];
418
+ commandLineOptions.languageServerSettings.logTypeEvaluationTime = true;
419
+ commandLineOptions.languageServerSettings.typeEvaluationTimeThreshold = 1;
420
+ commandLineOptions.languageServerSettings.enableAmbientAnalysis = false;
421
+ commandLineOptions.languageServerSettings.disableTaggedHints = true;
422
+ commandLineOptions.languageServerSettings.watchForSourceChanges = true;
423
+ commandLineOptions.languageServerSettings.watchForLibraryChanges = true;
424
+ commandLineOptions.languageServerSettings.watchForConfigChanges = true;
425
+ commandLineOptions.languageServerSettings.typeStubTargetImportName = 'test';
426
+ commandLineOptions.languageServerSettings.checkOnlyOpenFiles = true;
427
+ commandLineOptions.languageServerSettings.disableTaggedHints = true;
428
+ commandLineOptions.languageServerSettings.pythonPath = 'test_python_path';
429
+ service.setOptions(commandLineOptions);
430
+ let options = service.test_getConfigOptions(commandLineOptions);
431
+ assert_1.default.strictEqual(options.autoImportCompletions, true);
432
+ assert_1.default.strictEqual(options.indexing, true);
433
+ assert_1.default.strictEqual(options.taskListTokens?.length, 1);
434
+ assert_1.default.strictEqual(options.logTypeEvaluationTime, true);
435
+ assert_1.default.strictEqual(options.typeEvaluationTimeThreshold, 1);
436
+ assert_1.default.strictEqual(options.disableTaggedHints, true);
437
+ assert_1.default.ok(options.pythonPath?.pathIncludes('test_python_path'));
438
+ // Test with language server set to true to make sure they are still set.
439
+ commandLineOptions.fromLanguageServer = true;
440
+ commandLineOptions.languageServerSettings.venvPath = 'test_venv_path';
441
+ service.setOptions(commandLineOptions);
442
+ options = service.test_getConfigOptions(commandLineOptions);
443
+ assert_1.default.strictEqual(options.autoImportCompletions, true);
444
+ assert_1.default.strictEqual(options.indexing, true);
445
+ assert_1.default.strictEqual(options.taskListTokens?.length, 1);
446
+ assert_1.default.strictEqual(options.logTypeEvaluationTime, true);
447
+ assert_1.default.strictEqual(options.typeEvaluationTimeThreshold, 1);
448
+ assert_1.default.strictEqual(options.disableTaggedHints, true);
449
+ assert_1.default.ok(options.pythonPath?.pathIncludes('test_python_path'));
450
+ // Verify language server options don't override the config setting. Only command line should
451
+ assert_1.default.equal(options.venvPath?.pathIncludes('test_venv_path'), false);
452
+ });
453
+ test('DefaultPythonVersion no config', () => {
454
+ const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
455
+ const nullConsole = new console_1.NullConsole();
456
+ const service = createAnalyzer(nullConsole);
457
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
458
+ commandLineOptions.configFilePath = 'src/tests/samples/package1';
459
+ service.setOptions(commandLineOptions);
460
+ const config = service.test_getConfigOptions(commandLineOptions);
461
+ assert_1.default.deepStrictEqual(config.defaultPythonVersion, pythonVersion_1.pythonVersion3_13);
462
+ });
463
+ test('DefaultPythonVersion with config', () => {
464
+ const cwd = (0, pathUtils_1.normalizePath)(process.cwd());
465
+ const nullConsole = new console_1.NullConsole();
466
+ const service = createAnalyzer(nullConsole);
467
+ const commandLineOptions = new commandLineOptions_1.CommandLineOptions(cwd, /* fromLanguageServer */ false);
468
+ commandLineOptions.configFilePath = 'src/tests/samples/project1';
469
+ service.setOptions(commandLineOptions);
470
+ const config = service.test_getConfigOptions(commandLineOptions);
471
+ assert_1.default.deepStrictEqual(config.defaultPythonVersion, pythonVersion_1.pythonVersion3_13);
472
+ });
473
+ function createAnalyzer(console) {
474
+ const cons = console ?? new console_1.NullConsole();
475
+ const fs = (0, realFileSystem_1.createFromRealFileSystem)(tempFile, cons);
476
+ const serviceProvider = (0, serviceProviderExtensions_1.createServiceProvider)(fs, cons, tempFile);
477
+ const host = new testAccessHost_1.TestAccessHost();
478
+ host.getPythonVersion = () => pythonVersion_1.pythonVersion3_13;
479
+ return new service_1.AnalyzerService('<default>', serviceProvider, { console: cons, hostFactory: () => host });
480
+ }
457
481
  });
458
482
  //# sourceMappingURL=config.test.js.map