Skip to content

Commit

Permalink
Merge pull request #164 from galaxyproject/planemo_extra_params
Browse files Browse the repository at this point in the history
Add Planemo extra params
  • Loading branch information
davelopez committed Aug 9, 2021
2 parents 3600817 + ca14c9d commit 9e4e6a9
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 33 deletions.
47 changes: 24 additions & 23 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ To support testing your tools using `planemo test` inside VSCode you need to ins

# Table of Content

- [Installation](#installation)
- [Troubleshooting](#troubleshooting)
- [Configuration](#configuration)
- [Completion settings](#completion-settings)
- [Planemo settings](#planemo-settings)
- [Features](#features)
- [Tag and attribute auto-completion](#tag-and-attribute-auto-completion)
- [Documentation on Hover](#documentation-on-hover)
- [Document validation](#document-validation)
- [Document auto-formatting](#document-auto-formatting)
- [Tag auto-closing](#tag-auto-closing)
- [Snippets](#snippets)
- [Embedded syntax highlighting](#embedded-syntax-highlighting)
- [Auto-generate tests](#auto-generate-tests)
- [Auto-generate command section](#auto-generate-command-section)
- [Auto-sort param attributes](#auto-sort-param-attributes)
- [Run planemo tests in the Test Explorer](#run-planemo-tests-in-the-test-explorer)
- [Improved macros support](#improved-macros-support) _New feature!_ :rocket:
- [Installation](#installation)
- [Troubleshooting](#troubleshooting)
- [Configuration](#configuration)
- [Completion settings](#completion-settings)
- [Planemo settings](#planemo-settings)
- [Features](#features)
- [Tag and attribute auto-completion](#tag-and-attribute-auto-completion)
- [Documentation on Hover](#documentation-on-hover)
- [Document validation](#document-validation)
- [Document auto-formatting](#document-auto-formatting)
- [Tag auto-closing](#tag-auto-closing)
- [Snippets](#snippets)
- [Embedded syntax highlighting](#embedded-syntax-highlighting)
- [Auto-generate tests](#auto-generate-tests)
- [Auto-generate command section](#auto-generate-command-section)
- [Auto-sort param attributes](#auto-sort-param-attributes)
- [Run planemo tests in the Test Explorer](#run-planemo-tests-in-the-test-explorer)
- [Improved macros support](#improved-macros-support) _New feature!_ :rocket:

# Installation

Expand All @@ -53,9 +53,9 @@ If you encounter any problem during the language server installation, open the V

Some possible errors:

- `The selected file is not a valid Python <version> path!`. This message will appear if you select a Python binary that is not compatible with the required version. You will be given a chance to select the correct version the next time the extension gets activated. You can force it by reloading the extension or restarting VScode.
- `The selected file is not a valid Python <version> path!`. This message will appear if you select a Python binary that is not compatible with the required version. You will be given a chance to select the correct version the next time the extension gets activated. You can force it by reloading the extension or restarting VScode.

- `Error installing the Galaxy Language Server: pip module not found`. The extension needs to create a virtual environment to install the `galaxy-language-server` package and its dependencies. To create a proper environment with `pip` included, in some systems you need to install the `python3-venv` package using the following command: `apt install python3-venv` (you may need to use `sudo`). Once you have `python3-venv` installed, you may need to remove the `glsenv` directory inside the extension installation directory and then restart or reload VSCode to recreate the environment.
- `Error installing the Galaxy Language Server: pip module not found`. The extension needs to create a virtual environment to install the `galaxy-language-server` package and its dependencies. To create a proper environment with `pip` included, in some systems you need to install the `python3-venv` package using the following command: `apt install python3-venv` (you may need to use `sudo`). Once you have `python3-venv` installed, you may need to remove the `glsenv` directory inside the extension installation directory and then restart or reload VSCode to recreate the environment.

# Configuration

Expand Down Expand Up @@ -86,6 +86,7 @@ Planemo integration is currently in **experimental** phase. Please report any pr
| ----------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| `galaxyTools.planemo.testing.enabled` | Whether to discover and run tests using `planemo test` directly from the Test Explorer. |
| `galaxyTools.planemo.testing.autoTestDiscoverOnSaveEnabled` | Whether to try to discover new tests when a Galaxy Tool Wrapper file is saved. |
| `galaxyTools.planemo.testing.extraParams` | Additional arguments that will be passed to `planemo test` command. |

### Configuring Test Explorer UI

Expand Down Expand Up @@ -182,9 +183,9 @@ Now you can automatically sort the attributes of param elements according to the

You can now run `planemo test` for the currently opened tool directly from the `Test Explorer`.

- The tests are automatically discovered by the `galaxy-language-server` when you open a tool or save the document (this can be controlled by the settings).
- You can then run all the tests from the `Test Explorer` by using `planemo test` in the background. Currently running individual tests is not supported as AFAIK `planemo` does not have an option to do so at the moment.
- After successfully running the tests, the results will be displayed in a convenient way directly on your source XML.
- The tests are automatically discovered by the `galaxy-language-server` when you open a tool or save the document (this can be controlled by the settings).
- You can then run all the tests from the `Test Explorer` by using `planemo test` in the background. Currently running individual tests is not supported as AFAIK `planemo` does not have an option to do so at the moment.
- After successfully running the tests, the results will be displayed in a convenient way directly on your source XML.

The failing tests will be marked in red and the reason for failure can be seen directly beside the test definition in the same line or more detailed in the `Output`. You can also directly navigate to each of the tests XML source from the `Test Explorer`.
This can be very convenient especially when having a large number of tests in your tool.
Expand Down
6 changes: 6 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@
"type": "boolean",
"markdownDescription": "Whether to try to discover new tests when a Galaxy Tool Wrapper file is saved.",
"default": true
},
"galaxyTools.planemo.testing.extraParams": {
"scope": "resource",
"type": "string",
"markdownDescription": "String with additional arguments that will be passed to `planemo test` command. Example: `--no_cleanup --update_test_data`",
"default": ""
}
}
},
Expand Down
7 changes: 7 additions & 0 deletions client/src/configuration/galaxyToolWorkspaceConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ class GalaxyToolsPlanemoConfiguration implements IPlanemoConfiguration {
public enabled(): boolean {
return this.config.get("planemo.enabled", true);
}

public binaryPath(): string {
return this.config.get("planemo.envPath", "planemo");
}

public galaxyRoot(): string | null {
return this.config.get("planemo.galaxyRoot", null);
}
Expand Down Expand Up @@ -87,7 +89,12 @@ class GalaxyToolsPlanemoTestingConfiguration implements IPlanemoTestingConfigura
enabled(): boolean {
return this.config.get("planemo.testing.enabled", true);
}

autoTestDiscoverOnSaveEnabled(): boolean {
return this.config.get("planemo.testing.autoTestDiscoverOnSaveEnabled", true);
}

extraParams(): string {
return this.config.get("planemo.testing.extraParams", "");
}
}
1 change: 1 addition & 0 deletions client/src/configuration/workspaceConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export namespace Settings {
export namespace Testing {
export const ENABLED = "galaxyTools.planemo.testing.enabled";
export const AUTO_DISCOVERY_ON_SAVE_ENABLED = "galaxyTools.planemo.testing.autoTestDiscoverOnSaveEnabled";
export const EXTRA_PARAMS = "galaxyTools.planemo.testing.extraParams";
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions client/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export namespace Constants {

export const EXPAND_DOCUMENT_SCHEMA = "gls-expand";
export const EXPAND_DOCUMENT_URI_SUFFIX = "%20%28Expanded%29";

export const PLANEMO_TEST_OUTPUT_CHANNEL = "Planemo Tests";
}

export namespace DiagnosticCodes {
Expand Down
2 changes: 2 additions & 0 deletions client/src/planemo/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface IPlanemoTestingConfiguration {
enabled(): boolean;

autoTestDiscoverOnSaveEnabled(): boolean;

extraParams(): string;
}

export interface IConfigurationFactory {
Expand Down
48 changes: 44 additions & 4 deletions client/src/planemo/testing/testRunner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { unlinkSync } from "fs";
import * as path from "path";
import * as tmp from "tmp";
import { OutputChannel, window } from "vscode";
import { TestEvent, TestSuiteInfo } from "vscode-test-adapter-api";
import { Constants } from "../../constants";
import { IProcessExecution, runProcess } from "../../processRunner";
Expand All @@ -10,6 +11,7 @@ import { parseTestStates } from "./testsReportParser";

export class PlanemoTestRunner implements ITestRunner {
private readonly testExecutions: Map<string, IProcessExecution> = new Map<string, IProcessExecution>();
private _channel: OutputChannel = window.createOutputChannel(Constants.PLANEMO_TEST_OUTPUT_CHANNEL);

constructor(public readonly adapterId: string) {}

Expand All @@ -25,30 +27,40 @@ export class PlanemoTestRunner implements ITestRunner {
try {
const { file: output_json_file, cleanupCallback } = await this.getJsonReportPath(testFile);
const htmlReportFile = this.getTestHtmlReportFilePath(testFile);
const extraParams = this.getTestExtraParams(planemoConfig);

const testRunArguments = [
const baseArguments = [
`test`,
`--galaxy_root`,
`${planemoConfig.galaxyRoot()}`,
`--test_output_json`,
`${output_json_file}`,
`--test_output`,
`${htmlReportFile}`,
`${testFile}`,
];

const testRunArguments = baseArguments.concat(extraParams).concat(`${testFile}`);

this._channel.appendLine(`Running planemo ${testRunArguments.join(" ")}`);

const testExecution = this.runPlanemoTest(planemoConfig, testRunArguments);

this.testExecutions.set(testSuiteId, testExecution);
await testExecution.complete();
const result = await testExecution.complete();

if (result.exitCode !== 0) {
return [];
}

const states = await parseTestStates(output_json_file, testSuite, htmlReportFile);

cleanupCallback();

this.showSummaryLog(states);

return states;
} catch (err) {
console.log(err);
this.showErrorLog(err);
return [];
} finally {
this.testExecutions.delete(testSuiteId);
Expand All @@ -63,6 +75,7 @@ export class PlanemoTestRunner implements ITestRunner {
console.log(`Cancelling execution of ${test} failed: ${error}`);
}
});
this._channel.appendLine("\nTests run cancelled.\n");
}

public isRunning(): boolean {
Expand Down Expand Up @@ -109,4 +122,31 @@ export class PlanemoTestRunner implements ITestRunner {
const reportFile = path.resolve(baseDir, `${testFileName}_test_report.html`);
return reportFile;
}

private getTestExtraParams(planemoConfig: IPlanemoConfiguration): string[] {
const extraParams = planemoConfig.testing().extraParams();
if (extraParams != "") {
return extraParams.split(" ");
}
return [];
}

private showErrorLog(errorMessage: string) {
this._channel.appendLine(errorMessage);
this._channel.show();
}

private showSummaryLog(states: TestEvent[]) {
let statesMap = new Map<string, number>();
states.forEach((test) => {
let stateCount = statesMap.get(test.state);
stateCount = stateCount === undefined ? 1 : stateCount + 1;
statesMap.set(test.state, stateCount);
});
this._channel.appendLine(`\n${states.length} tests completed:`);
statesMap.forEach((count, state) => {
this._channel.appendLine(` ${count} ${state}`);
});
this._channel.append("\n");
}
}
12 changes: 6 additions & 6 deletions client/src/planemo/testing/testsReportParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ function parseTestResults(parserResult: any, testSuite: TestSuiteInfo, htmlRepor
const testResults: TestEvent[] = [];
testSuiteResults.tests.forEach((testCaseResult) => {
const testInfo = getTestInfo(testCaseResult, testSuite);
const adatedResult = adaptTestResult(testCaseResult, testInfo);
if (adatedResult !== undefined) {
adatedResult.message += `${EOL}${EOL}See full test report: ${htmlReportFile}`;
testResults.push(adatedResult);
const adaptedResult = adaptTestResult(testCaseResult, testInfo);
if (adaptedResult !== undefined) {
adaptedResult.message += `${EOL}${EOL}See full test report: ${htmlReportFile}`;
testResults.push(adaptedResult);
}
});

Expand All @@ -88,7 +88,7 @@ function adaptTestResult(testResult: ITestCaseResult, testInfo: TestInfo | undef
if (!testResult.has_data) {
return undefined;
}
const state = adapTestState(testResult);
const state = adaptTestState(testResult);
const testId = adaptTestId(testResult);
const message = adaptTestMessage(testResult);
const line = testInfo ? testInfo.line : 0;
Expand All @@ -103,7 +103,7 @@ function adaptTestResult(testResult: ITestCaseResult, testInfo: TestInfo | undef
return result;
}

function adapTestState(testResult: ITestCaseResult): TestState {
function adaptTestState(testResult: ITestCaseResult): TestState {
const adapted = stateMap.get(testResult.data.status);
if (adapted === undefined) return "errored";
return adapted;
Expand Down

0 comments on commit 9e4e6a9

Please sign in to comment.