Skip to content

Commit

Permalink
add test for default typeCheckingMode
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Feb 11, 2024
1 parent 652aa39 commit 47d6df3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
22 changes: 0 additions & 22 deletions packages/pyright-internal/src/tests/typeEvaluator1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,13 @@ import { ConfigOptions } from '../common/configOptions';
import { PythonVersion } from '../common/pythonVersion';
import { Uri } from '../common/uri/uri';
import * as TestUtils from './testUtils';
import { DiagnosticRule } from '../common/diagnosticRules';

test('Unreachable1', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['unreachable1.py']);

TestUtils.validateResults(analysisResults, 0, 0, 2, 1, 4);
});

test('Unreachable1 reportUnreachable', () => {
const configOptions = new ConfigOptions(Uri.empty());
configOptions.diagnosticRuleSet.reportUnreachable = 'error';
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['unreachable1.py'], configOptions);
TestUtils.validateResultsButBased(analysisResults, {
errors: [78, 89, 106, 110].map((line) => ({ code: DiagnosticRule.reportUnreachable, line })),
infos: [{ line: 95 }, { line: 98 }],
unusedCodes: [{ line: 102 }],
});
});

test('Unreachable2 reportUnreachable TYPE_CHECKING', () => {
const configOptions = new ConfigOptions(Uri.empty());
configOptions.diagnosticRuleSet.reportUnreachable = 'error';
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['unreachable2.py'], configOptions);

TestUtils.validateResultsButBased(analysisResults, {
unreachableCodes: [{ line: 3 }, { line: 8 }],
});
});

test('Builtins1', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['builtins1.py']);

Expand Down
42 changes: 42 additions & 0 deletions packages/pyright-internal/src/tests/typeEvaluatorBased.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { BasedConfigOptions, ConfigOptions } from '../common/configOptions';
import { DiagnosticRule } from '../common/diagnosticRules';
import { Uri } from '../common/uri/uri';
import { typeAnalyzeSampleFiles, validateResultsButBased } from './testUtils';

test('reportUnreachable', () => {
const configOptions = new ConfigOptions(Uri.empty());
configOptions.diagnosticRuleSet.reportUnreachable = 'error';
const analysisResults = typeAnalyzeSampleFiles(['unreachable1.py'], configOptions);
validateResultsButBased(analysisResults, {
errors: [78, 89, 106, 110].map((line) => ({ code: DiagnosticRule.reportUnreachable, line })),
infos: [{ line: 95 }, { line: 98 }],
unusedCodes: [{ line: 102 }],
});
});

test('reportUnreachable TYPE_CHECKING', () => {
const configOptions = new ConfigOptions(Uri.empty());
configOptions.diagnosticRuleSet.reportUnreachable = 'error';
const analysisResults = typeAnalyzeSampleFiles(['unreachable2.py'], configOptions);

validateResultsButBased(analysisResults, {
unreachableCodes: [{ line: 3 }, { line: 8 }],
});
});

test('default typeCheckingMode=all', () => {
const configOptions = new BasedConfigOptions(Uri.empty());
const analysisResults = typeAnalyzeSampleFiles(['unreachable1.py'], configOptions);
validateResultsButBased(analysisResults, {
errors: [
...[78, 89, 106, 110].map((line) => ({ code: DiagnosticRule.reportUnreachable, line })),
{ line: 16, code: DiagnosticRule.reportUninitializedInstanceVariable },
{ line: 19, code: DiagnosticRule.reportUnknownParameterType },
{ line: 33, code: DiagnosticRule.reportUnknownParameterType },
{ line: 94, code: DiagnosticRule.reportUnnecessaryComparison },
{ line: 102, code: DiagnosticRule.reportUnusedVariable },
],
infos: [{ line: 95 }, { line: 98 }],
unusedCodes: [{ line: 102 }],
});
});

0 comments on commit 47d6df3

Please sign in to comment.