Running the test suite

MAT includes a good deal of test code for the core Python library and tools. There's also some Java JUnit test code, which can be found in the lib/mat/java subdirectory in an appropriate location for building a Netbeans project. There's no Javascript test code, and no test code for the MAT UI itself. This page documents the test code for the core Python library and tools.

The test suite is known to pass, in both Python 2.7 and Python 3.7, on Linux/Unix platforms; it may generate a few (ignorable) errors on Windows.

The test suite requires Python 2.7 or later, because it relies on a feature for skipping tests which is required by the Python pip module.

The test suite is not delivered with the Python pip module; the pip module can only be tested from the full distribution. See the section on building testing the pip module for details.

Unix:

% python $MAT_PKG_HOME/test/mat_unittest.py --help

Windows:

> python.exe %MAT_PKG_HOME%\test\mat_unittest.py --help

Usage: mat_unittest.py [ --debug ] [ --quiet ] [ --verbose ] [ --tmpdir <d> ] [ --block_context_teardown ]
[ --setting <a>=<b> ]* [ --categories a,b,c... ] [ --class_name_pattern p ]
[ --test_name_pattern p ] [ --list_tests_only ] [ --core_only ] [ --subprocess_debug <i>] app_dir...

Options

--debug
pass debug to unittest
--verbose
verbose execution
--tmpdir <d>
the temp directory will be created in <d> instead of the default location
--block_context_teardown
don't clean up the context at the end (so tmpdir remains)
--setting <a>=<b>
provide a setting to the test context
--categories <a,b,c...>
an optional comma-delimited list of core categories to test. If present, the system will test only files in the unittest directory named mat_<category>_unittest.py
--class_name_pattern <p>
an optional Python regular expression pattern to filter unit test class names
--test_name_pattern <p>
an optional Python regular expression pattern to filter the individual test method names
--list_tests_only
list the selected tests and exit
--core_only
test the Python pip module alone
--subprocess_debug <i>
set the subprocess debug level to the value provided, overriding the global setting. 0 disables, 1 shows some subprocess activity, 2 shows all subprocess activity

Using the test suite

The basic invocation is

% python $MAT_PKG_HOME/test/mat_unittest.py

This will run all the installed tests for the core MAT system.

If any tasks are installed, and they have a test/ subdirectory with Python files, and you pass the task directory as an argument to the test suite, those files will be run as part of the test. In order to test just the task, and ignore the core tests, use --categories "" (empty string) in your command line. The --setting option passes values to these task tests (if you have any tasks with tests in them, you may have some examples of this, but it's unlikely).

The core tests are subdivided into a number of files in the test/ subdirectory named mat_<category>_unittest.py. The --categories option allows you to select a subset of these to run. E.g., if you just want to run the tests in mat_workspace_unittest.py, call

% python $MAT_PKG_HOME/test/mat_unittest.py --categories workspace

Building and testing the pip module

The Python pip module is simple to build. On Unix:

% cd $MAT_PKG_HOME/lib/mat/python
% python local_setup.py sdist --formats zip

This script is a wrapper around the standard setup.py script which temporarily copies appropriate files (e.g., the license file) for the setup.py script to access. The resulting MAT-<version>.zip file will be in the dist/ subdirectory.

We recommend testing this module in a virtual environment. Once you've set up that environment:

% pip install $MAT_PKG_HOME/lib/mat/python/dist/MAT-<version>.zip
% python $MAT_PKG_HOME/test/mat_unittest.py --core_only

The installation of the package will cause the third-party munkres package to be installed, so make sure you have your environment set up to access the appropriate Python package repository.