33 * Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import path from 'path' ;
76import { test , tags } from '../_test.setup.js' ;
87
98test . use ( {
@@ -56,23 +55,8 @@ test.describe('Diagnostics', {
5655 await problems . expectDiagnosticsToBe ( { badgeCount : 1 , warningCount : 0 , errorCount : 1 , timeout : 15000 } ) ;
5756 await problems . expectWarningText ( 'Cannot find module `termcolor`' ) ;
5857
59- // does pyrefly use squiggly correctly?
60- // await problems.expectSquigglyCountToBe('warning', 1);
61-
62- // Python Session 1 - restart session and verify no problems
63- /* skipping for now until this is fixed with pyrefly
64- await sessions.select(pySession.id);
65- await sessions.restart(pySession.id);
66- await problems.expectDiagnosticsToBe({ badgeCount: 0, warningCount: 0, errorCount: 0 });
67- await problems.expectSquigglyCountToBe('warning', 0);
68- */
6958 } ) ;
7059
71- // Adding these additional tests to ensure a more robust coverage
72- // The idea is to use different scenarios as a proxy for potential pyrefly issues/delays/halts
73- // Some tests may appear redundant, but they are designed to catch potential breakages in pyrefly functionality
74- // NOTE: Check on maintenance over time - if pyrefly changes warning text too often, we may want to consider removing that line.
75-
7660 test ( 'Python - File shows diagnostic for non-existent module import' , async function ( { app, runCommand, sessions, python } ) {
7761 const { problems, editor } = app . workbench ;
7862 await runCommand ( 'Python: New File' ) ;
@@ -81,82 +65,6 @@ test.describe('Diagnostics', {
8165 await problems . expectWarningText ( 'Cannot find module `bad_module`' ) ;
8266 } ) ;
8367
84- test ( 'Python - File shows diagnostic for missing attribute on module' , async function ( { app, runCommand } ) {
85- const { problems, editor } = app . workbench ;
86- await runCommand ( 'Python: New File' ) ;
87- await editor . type ( 'import math\nmath.not_a_real_attr\n' ) ;
88- await problems . expectDiagnosticsToBe ( { badgeCount : 1 , warningCount : 0 , errorCount : 1 } ) ;
89- await problems . expectWarningText ( 'No attribute' ) ;
90- } ) ;
91-
92- test ( 'Python - File shows diagnostic for calling non-callable' , async function ( { app, runCommand } ) {
93- const { problems, editor } = app . workbench ;
94- await runCommand ( 'Python: New File' ) ;
95- await editor . type ( 'x = 1\nx()\n' ) ;
96- await problems . expectDiagnosticsToBe ( { badgeCount : 1 , warningCount : 0 , errorCount : 1 } ) ;
97- await problems . expectWarningText ( 'Expected a callable' ) ;
98- } ) ;
99-
100- test ( 'Python - File shows diagnostic for incompatible assignment (annotated int)' , async function ( { app, runCommand } ) {
101- const { problems, editor } = app . workbench ;
102- await runCommand ( 'Python: New File' ) ;
103- await editor . type ( 'x: int = "hello"\n' ) ;
104- await problems . expectDiagnosticsToBe ( { badgeCount : 1 , warningCount : 0 , errorCount : 1 } ) ;
105- await problems . expectWarningText ( 'not assignable' ) ;
106- } ) ;
107-
108- test ( 'Python - File shows diagnostic for wrong return type' , async function ( { app, runCommand } ) {
109- const { problems, editor } = app . workbench ;
110- await runCommand ( 'Python: New File' ) ;
111- await editor . type ( 'def f() -> int:\n\treturn "nope"\n' ) ;
112- await problems . expectDiagnosticsToBe ( { badgeCount : 1 , warningCount : 0 , errorCount : 1 } ) ;
113- await problems . expectWarningText ( 'Return type' ) ;
114- } ) ;
115-
116- test ( 'Python - File shows diagnostic for list element type mismatch' , async function ( { app, runCommand } ) {
117- const { problems, editor } = app . workbench ;
118- await runCommand ( 'Python: New File' ) ;
119- await editor . type ( 'xs: list[int] = [1, "a"]\n' ) ;
120- await problems . expectDiagnosticsToBe ( { badgeCount : 1 , warningCount : 0 , errorCount : 1 } ) ;
121- await problems . expectWarningText ( 'not assignable' ) ;
122- } ) ;
123-
124- test ( 'Python - File shows diagnostic for dict value type mismatch' , async function ( { app, runCommand } ) {
125- const { problems, editor } = app . workbench ;
126- await runCommand ( 'Python: New File' ) ;
127- await editor . type ( 'm: dict[str, int] = {"a": 1, "b": "x"}\n' ) ;
128- await problems . expectDiagnosticsToBe ( { badgeCount : 1 , warningCount : 0 , errorCount : 1 } ) ;
129- await problems . expectWarningText ( 'not assignable' ) ;
130- } ) ;
131-
132- test ( 'Python - File shows type errors when indentation error is present' , async function ( { app, runCommand, sessions, python } ) {
133- const { problems, editor } = app . workbench ;
134- await runCommand ( 'Python: New File' ) ;
135- await editor . type ( 'def greet(name: str) -> str:\n\treturn f"Hello, {name}"\n\n# Type error: passing int instead of str\nresult = greet(123)\n' ) ;
136- await problems . expectDiagnosticsToBe ( { badgeCount : 6 , warningCount : 0 , errorCount : 6 } ) ;
137- } ) ;
138-
139- // NOTE[RSF]: Unskip/fix tests for QMD and Notebook files
140- // Currently skipping due to pyrefly not working with .qmd and .ipynb
141-
142- test . skip ( 'Python - QMD file shows diagnostic for undefined variable' , async function ( { app, runCommand } ) {
143- const { problems, editor, quickInput, hotKeys } = app . workbench ;
144- await runCommand ( 'workbench.action.files.newUntitledFile' ) ;
145- await editor . type ( '---\ntitle: "Test"\n---\n\n```{python}\nprint(does_not_exist)\n```\n' ) ;
146-
147- await runCommand ( 'workbench.action.files.saveAs' , { keepOpen : true } ) ;
148- await quickInput . waitForQuickInputOpened ( ) ;
149- await quickInput . type ( path . join ( app . workspacePathOrFolder , 'smoke.qmd' ) ) ;
150- await app . code . driver . currentPage . keyboard . press ( 'Enter' ) ;
151- await quickInput . waitForQuickInputClosed ( ) ;
152- await problems . expectDiagnosticsToBe ( { badgeCount : 1 , warningCount : 0 , errorCount : 1 } ) ;
153-
154- await hotKeys . selectAll ( ) ;
155- await editor . type ( '---\ntitle: "Test"\n---\n\n```{python}\nx = 1\nprint(x)\n```\n' ) ;
156-
157- await problems . expectDiagnosticsToBe ( { badgeCount : 0 , warningCount : 0 , errorCount : 0 } ) ;
158- } ) ;
159-
16068 test ( 'Python - Notebook shows diagnostic for undefined variable' , async function ( { app, hotKeys } ) {
16169 const { problems, notebooksPositron } = app . workbench ;
16270
0 commit comments