@@ -34,6 +34,8 @@ import {
3434 runPyrightServer ,
3535 waitForDiagnostics ,
3636} from './lsp/languageServerTestUtils' ;
37+ import { BaselineFile } from '../baseline' ;
38+ import { DiagnosticRule } from '../common/diagnosticRules' ;
3739
3840/** objects from `sendRequest` don't work with assertions and i cant figure out why */
3941const assertEqual = < T > ( actual : T , expected : T ) => expect ( JSON . parse ( JSON . stringify ( actual ) ) ) . toStrictEqual ( expected ) ;
@@ -962,4 +964,70 @@ describe(`Basic language server tests`, () => {
962964 'invalid diagnosticMode: "asdf". valid options are "workspace" or "openFilesOnly"'
963965 ) ;
964966 } ) ;
967+ describe ( 'baseline' , ( ) => {
968+ test ( 'baselined error not shown' , async ( ) => {
969+ const baseline : BaselineFile = {
970+ files : {
971+ './foo.py' : [
972+ {
973+ code : DiagnosticRule . reportAssignmentType ,
974+ range : {
975+ startColumn : 11 ,
976+ endColumn : 13 ,
977+ } ,
978+ } ,
979+ ] ,
980+ } ,
981+ } ;
982+ const code = `
983+ // @filename: .basedpyright/baseline.json
984+ //// ${ JSON . stringify ( baseline ) }
985+ ////
986+ // @filename: foo.py
987+ //// foo: int = ""
988+ //// asdf
989+ //// [|/*marker*/|]
990+ ` ;
991+ const settings = [
992+ {
993+ item : {
994+ scopeUri : `file://${ normalizeSlashes ( DEFAULT_WORKSPACE_ROOT , '/' ) } ` ,
995+ section : 'basedpyright.analysis' ,
996+ } ,
997+ value : {
998+ diagnosticSeverityOverrides : {
999+ reportAssignmentType : 'error' ,
1000+ reportUndefinedVariable : 'error' ,
1001+ } ,
1002+ } ,
1003+ } ,
1004+ ] ;
1005+
1006+ const info = await runLanguageServer (
1007+ DEFAULT_WORKSPACE_ROOT ,
1008+ code ,
1009+ /* callInitialize */ true ,
1010+ settings ,
1011+ undefined ,
1012+ /* supportsBackgroundThread */ false
1013+ ) ;
1014+
1015+ // get the file containing the marker that also contains our task list comments
1016+ await openFile ( info , 'marker' ) ;
1017+
1018+ // Wait for the diagnostics to publish
1019+ const diagnostics = await waitForDiagnostics ( info ) ;
1020+ const file = diagnostics . find ( ( d ) => d . uri . includes ( 'test.py' ) ) ;
1021+ assert ( file ) ;
1022+
1023+ // Make sure the error has a special rule
1024+ assert . equal ( file . diagnostics [ 0 ] . code , 'reportUnknownParameterType' ) ;
1025+
1026+ // make sure additional diagnostic severities work
1027+ assert . equal (
1028+ file . diagnostics . find ( ( diagnostic ) => diagnostic . code === 'reportUnusedFunction' ) ?. severity ,
1029+ DiagnosticSeverity . Hint // TODO: hint? how do we differentiate between unused/unreachable/deprecated?
1030+ ) ;
1031+ } ) ;
1032+ } ) ;
9651033} ) ;
0 commit comments