QGIS Script Assistant Plugin Docs

This is a QGIS plugin with three helper tools for QGIS development purposes.

Here it is in action - testing itself:

_images/plugin_test.gif

To learn more, check out the feature overview and configuration guide below.

Overview

This is a QGIS plugin with three helper tools for QGIS development purposes.

Reload Scripts

_images/reload_scripts.png

Load / reload processing user scripts into QGIS from any existing directory.

_images/reload_scripts.gif

The Reload Scripts tool simply copies processing scripts from the configured directory to the QGIS processing scripts directory, and then reloads the processing toolbox in QGIS. If a script already exists with the same name, it will be overwritten without warning.

Test Scripts

_images/test_scripts.png

Run tests within QGIS in a way that makes them configurable for local and Travis-CI testing without any manual amendments.

_images/test_scripts.gif

The test list

The test list is constructed by finding any file in the configured test directory with a file name starting with test_ and ending with .py. It does not (currently) check folders within the test directory.

Every time you select the dropdown to the right of the Test Scripts button, the test list reloads from the tests directory. So if you’re switching branches in git, you’ll always be running the tests from the same branch you’ve checked out.

Running a test

Select a test from the test list to run it.

The QGIS Python Console will be opened (if it isn’t already visible) to print test results.

reload() is used to reload the test module. This allows the tests to be edited using an external text editor and then recompiled in QGIS. This functionality can be switched off in settings if it isn’t required.

Running a test will also apply that test as the default action for the Test Scripts button - to repetitively run the same test, there is no need to select it from the test list again and again, just click on Test Scripts after the first run.

Running all tests

There is always an additional option in the test list to run all tests. This option collects tests in the same way that the test list is constructed and runs the lot.

Testing using Travis-CI

The plugin repository contains an example of how to run these same tests using Travis-CI.

Thanks to Boundless for making this possible using qgis-testing-environment-docker!

Add Test Data

_images/add_test_data.png

Add all of the test data referred to in a test with a click.

_images/add_test_data.gif

Adding shapefiles used in tests

The Add Test Data tool checks the last test script that was run for references to .shp files. Any shapefile matches from the configured testdata directory are then added to the QGIS layer registry.

Configuration

The Script Assistant plugin is configured using the settings dialog. The plugin is designed to hold multiple project configurations, so that it’s easy to switch between development tasks.

The Settings Dialog

_images/settings.png

Default settings

The plugin comes with one configuration pre-installed - this configuration allows the plugin to test itself.

_images/settings_dialog.png

On install, you can immediately select the Test Scripts button.

_images/test_scripts.png

User settings

To add a new Script Assistant configuration, change the name in the configuration combo box and then type in or select the appropriate settings in the dialog. Click Save to store the configuration.

Don’t reload tests setting
_images/dont_reload.png

This setting turns off the use of reload() to reload test modules. It’ll run tests faster but the test won’t update if it has been edited in an external text editor.

Directory validation

Directories displayed in red text cannot be found in the file system so are invalid. The Save action is unavailable if there are invalid directories.

_images/invalid_dir.png

Save confirmation

If settings have been modified but not yet saved, an asterisk is displayed in the dialog title.

_images/unsaved_asterisk.png

If a dialog is closed in any way with unsaved settings, the user will be asked to confirm via the Save Confirmation dialog. If the user opts not to save, the settings entered into the settings dialog will still be used for the current QGIS session - but they won’t be available in subsequent QGIS sessions.

The Settings Configuration File

Settings are saved to a configuration file stored in the .qgis2/scriptassistant directory in the user folder (the exact location differs depending on operating system). If a group of users require similar configurations, the settings file can be shared between users. User directories will need to be amended.

The settings file should generally be modified by changing settings in the settings dialog, not by directly editing it. It is provided in .ini format for convenience.