Icontract-hypothesis-vscode is an extension for Visual Studio Code (VS Code) that allows you to automatically test your Python code using icontract-hypothesis.
Icontract-hypothesis-vscode has two dependencies:
- The Python extension ms-python.python for VS Code, and
- The Python package icontract-hypothesis.
ms-python.python. Use the Visual Studio marketplace to install the extension ms-python.python by following this link.
icontract-hypothesis. The easiest way to install the package icontract-hypothesis is via pip3:
pip3 install icontract-hypothesis
If you use a virtual environment, make sure that you activate it beforehand so that the package icontract-hypothesis is installed in it (instead of globally).
You have to set up ms-python.python extension so that icontract-hypothesis-vscode can use the package icontract-hypothesis.
icontract-hypothesis-vscode. Use the Visual Studio marketplace to install the extension ms-python.python by following this link.
The icontract-hypothesis-vscode is automatically activated when you start your VS Code.
You access it through the editor context pop-up menu:
Once you click on it, a quick pick will appear so that you can choose one of the possible commands:
If your file contains unsaved changes, the file will be saved first before the commands are executed.
The commands are executed in a terminal named "icontract-hypothesis". (If a terminal with that name already exists, it will be closed first and then freshly re-opened. This is necessary so that we do not pollute your terminal space on many command calls.)
The following commands are provided:
test. Infer the Hypothesis strategies for all the global functions in the active file and execute them.
test at. Infer the Hypothesis strategy for the global function at the caret.
If the caret is outside of a function, this command does nothing.
inspect. Infer the Hypothesis strategies for all the global functions in the active file and write them to the standard output so that you can inspect what will be eventually executed.
inspect at. Analogous to "test at", this command lets you inspect the inferred Hypothesis strategies for the global function at the caret.
If the caret is outside of a function, this command does nothing.
ghostwrite explicit. Infer the Hypothesis strategies for all the global functions in the active file. Then generate a stub unit test file with the strategies explicitly written out and print the test file to the standard output.
ghostwrite explicit to. Same as "ghostwrite explicit", but saves the generated test file to a file on disk.
The extension defines the following commands:
icontract-hypothesis-vscode.pick
(Show the quickpick),icontract-hypothesis-vscode.test
(Infer the Hypothesis strategies for the current file and execute them),icontract-hypothesis-vscode.test-at
(Infer the Hypothesis strategy for the function under the caret and execute it),icontract-hypothesis-vscode.inspect
(Infer the Hypothesis strategies for the current file and inspect them),icontract-hypothesis-vscode.inspect-at
(Infer the Hypothesis strategy for the function under the caret and inspect it),icontract-hypothesis-vscode.ghostwrite-explicit
(Ghostwrite and print an explicit test file for the current file), andicontract-hypothesis-vscode.ghostwrite-explicit-to
(Ghostwrite and save an explicit test file for the current file)
Please see Section "Usage" for more details.
It is hard to control terminals in VS Code (see this issue). We wait for a short delay (~1 second) till we send commands to the terminal. This might cause racing conditions in some rare cases.
We follow a bit unusual semantic versioning schema:
- X is the oldest supported version of icontract-hypothesis,
- Y is the minor version (new or modified features), and
- Z is the patch version (only bug fixes).
Refactor actions into individual commands (#4)
Fix URL of the images in the Readme (#2)
Initial release of icontract-hypothesis-vscode.