Skip to content

Commit ede5b3d

Browse files
authored
Add commands to run, debug and open tests (microsoft#4332)
For microsoft#4277
1 parent e8aa187 commit ede5b3d

19 files changed

Lines changed: 409 additions & 46 deletions

File tree

‎package.json‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,30 @@
143143
"title": "%python.command.python.buildWorkspaceSymbols.title%",
144144
"category": "Python"
145145
},
146+
{
147+
"command": "python.openTestNodeInEditor",
148+
"title": "Open",
149+
"icon": {
150+
"light": "resources/light/open-file.svg",
151+
"dark": "resources/dark/open-file.svg"
152+
}
153+
},
154+
{
155+
"command": "python.runTestNode",
156+
"title": "Run",
157+
"icon": {
158+
"light": "resources/light/start.svg",
159+
"dark": "resources/dark/start.svg"
160+
}
161+
},
162+
{
163+
"command": "python.debugTestNode",
164+
"title": "Debug",
165+
"icon": {
166+
"light": "resources/light/debug.svg",
167+
"dark": "resources/dark/debug.svg"
168+
}
169+
},
146170
{
147171
"command": "python.runtests",
148172
"title": "%python.command.python.runtests.title%",
@@ -439,6 +463,24 @@
439463
}
440464
],
441465
"commandPalette": [
466+
{
467+
"command": "python.runTestNode",
468+
"title": "Run",
469+
"category": "Python",
470+
"when": "config.noExists"
471+
},
472+
{
473+
"command": "python.debugTestNode",
474+
"title": "Debug",
475+
"category": "Python",
476+
"when": "config.noExists"
477+
},
478+
{
479+
"command": "python.openTestNodeInEditor",
480+
"title": "Open",
481+
"category": "Python",
482+
"when": "config.noExists"
483+
},
442484
{
443485
"command": "python.datascience.runcurrentcell",
444486
"title": "%python.command.python.datascience.runcurrentcell.title%",
@@ -540,6 +582,53 @@
540582
"command": "python.runtests",
541583
"group": "navigation"
542584
}
585+
],
586+
"view/item/context": [
587+
{
588+
"command": "python.openTestNodeInEditor",
589+
"when": "view == python_tests && viewItem == testFunction",
590+
"group": "inline"
591+
},
592+
{
593+
"command": "python.debugTestNode",
594+
"when": "view == python_tests && viewItem == testFunction",
595+
"group": "inline"
596+
},
597+
{
598+
"command": "python.runTestNode",
599+
"when": "view == python_tests && viewItem == testFunction",
600+
"group": "inline"
601+
},
602+
{
603+
"command": "python.openTestNodeInEditor",
604+
"when": "view == python_tests && viewItem == testFile",
605+
"group": "inline"
606+
},
607+
{
608+
"command": "python.debugTestNode",
609+
"when": "view == python_tests && viewItem == testFile",
610+
"group": "inline"
611+
},
612+
{
613+
"command": "python.runTestNode",
614+
"when": "view == python_tests && viewItem == testFile",
615+
"group": "inline"
616+
},
617+
{
618+
"command": "python.openTestNodeInEditor",
619+
"when": "view == python_tests && viewItem == testSuite",
620+
"group": "inline"
621+
},
622+
{
623+
"command": "python.debugTestNode",
624+
"when": "view == python_tests && viewItem == testSuite",
625+
"group": "inline"
626+
},
627+
{
628+
"command": "python.runTestNode",
629+
"when": "view == python_tests && viewItem == testSuite",
630+
"group": "inline"
631+
}
543632
]
544633
},
545634
"debuggers": [

‎pythonFiles/symbolProvider.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def getDataObject(self, node, namespace=""):
4747
"name": node.name,
4848
"range": {
4949
"start": {
50-
"line": node.lineno,
50+
"line": node.lineno - 1,
5151
"character": node.col_offset
5252
},
5353
"end": {
@@ -59,7 +59,7 @@ def getDataObject(self, node, namespace=""):
5959

6060
def getEndPosition(self, node):
6161
if not hasattr(node, 'body') or len(node.body) == 0:
62-
return (node.lineno, node.col_offset)
62+
return (node.lineno - 1, node.col_offset)
6363
return self.getEndPosition(node.body[-1])
6464

6565

‎resources/dark/debug.svg‎

Lines changed: 7 additions & 0 deletions
Loading

‎resources/dark/open-file.svg‎

Lines changed: 1 addition & 0 deletions
Loading

‎resources/dark/start.svg‎

Lines changed: 1 addition & 0 deletions
Loading

‎resources/light/debug.svg‎

Lines changed: 7 additions & 0 deletions
Loading

‎resources/light/open-file.svg‎

Lines changed: 1 addition & 0 deletions
Loading

‎resources/light/start.svg‎

Lines changed: 1 addition & 0 deletions
Loading

‎src/client/common/constants.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export namespace Commands {
4545
export const navigateToTestFunction = 'navigateToTestFunction';
4646
export const navigateToTestSuite = 'navigateToTestSuite';
4747
export const navigateToTestFile = 'navigateToTestFile';
48+
export const openTestNodeInEditor = 'python.openTestNodeInEditor';
49+
export const runTestNode = 'python.runTestNode';
50+
export const debugTestNode = 'python.debugTestNode';
4851
}
4952
export namespace Octicons {
5053
export const Test_Pass = '$(check)';

‎src/client/extension.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ import { EditorLoadTelemetry } from './telemetry/types';
101101
import { registerTypes as commonRegisterTerminalTypes } from './terminals/serviceRegistry';
102102
import { ICodeExecutionManager, ITerminalAutoActivation } from './terminals/types';
103103
import { TEST_OUTPUT_CHANNEL } from './unittests/common/constants';
104-
import { ITestCodeNavigatorCommandHandler } from './unittests/navigation/types';
104+
import { ITestCodeNavigatorCommandHandler, ITestExplorerCommandHandler } from './unittests/navigation/types';
105105
import { registerTypes as unitTestsRegisterTypes } from './unittests/serviceRegistry';
106106

107107
durations.codeLoadingTime = stopWatch.elapsedTime;
@@ -293,6 +293,7 @@ function initializeServices(context: ExtensionContext, serviceManager: ServiceMa
293293
serviceContainer.get<IInterpreterLocatorProgressService>(IInterpreterLocatorProgressService).register();
294294
serviceContainer.get<IApplicationDiagnostics>(IApplicationDiagnostics).register();
295295
serviceContainer.get<ITestCodeNavigatorCommandHandler>(ITestCodeNavigatorCommandHandler).register();
296+
serviceContainer.get<ITestExplorerCommandHandler>(ITestExplorerCommandHandler).register();
296297
}
297298

298299
// tslint:disable-next-line:no-any

0 commit comments

Comments
 (0)