Skip to main content

A Python enabled simple regression testing framework for Modelica models

Project description

MoPyRegtest: A Python enabled simple regression testing framework for Modelica models

License: MIT contributions welcome

Scope of this project is to

  • provide a simple regression testing framework for Modelica models
  • support continuous integration (CI) for Modelica library development, in particular
  • test for reproducibility of results from Modelica models and to
  • have it wrapped in the well-known Python unittest module

Background:

When developing Modelica models or libraries and releases have been made, there is definitely the need for testing. E.g.

  • validation of successful model translation,
  • reproducibility of simulation results, or
  • making sure refactorings in Modelica libraries do not alter the behavior.

Other testing criteria could be memory consumption, CPU time and more.

Why MoPyRegtest

The scope of MoPyRegtest is to have a lightweight and simple way to perform regression tests and to be able to integrate this with automated testing and continuous integration (CI) toolchains, like e.g. GitHub Actions. Without immediately requiring commercial simulation tools or creating strong dependencies from other Modelica libraries.

All that is needed to use MoPyRegtest is a Python 3 installation, an OpenModelica installation and a text editor.

Current realization

The current realization uses the Python unittest module and calls the OpenModelica compiler omc as an external executable for translation and simulation of Modelica models. Note that the implementation of MoPyRegtest is not specific to OpenModelica but can be replaced by any other Modelica simulation tool that comes with a suitable scripting API.

The test execution and orchestration is done by the Python unittest module. In particular, Python unittest supports test discovery. Also, unittest is a standard module that comes with virtually all Python distributions.

MoPyRegtest is work in progress!

Usage and example

With MoPyRegtest users can define regression tests manually in Python for one Modelica model at a time, or automatically for many Modelica models simultaneously.

Manual test case definition

The user has to

  • provide Modelica models that can be translated, built and executed and produce a result .csv file
  • provide for every Modelica model a .csv file with a reference result against which an actual result is compared
  • create a Python file and test methods that instantiate a mopyregtest.RegressionTest object, which needs to know which Modelica model to test and where to find the reference result.

Examples can be found in the examples folder. Also see the examples/README.md.

Automatic test case generation

MoPyRegtest can generate regression test definitions for elements of a Modelica library automatically. Either by creating Generator class objects. Or from the command line using the testgen.py script.

The examples folder generate_tests has a detailed example on how to automatically generate tests using a Python script.

Prerequisites

To use MoPyRegtest you need to have

  • a Python 3 distribution including the modules unittest, numpy and pandas,
  • a working OpenModelica installation (version 1.13.0 or later, works also for latest 1.21), and
  • the OpenModelica compiler executable omc must be accessible via the PATH variable.

Installation using pip3

If you want to install MoPyRegtest using Python's package manager pip, just clone this repo to your local <your-mopyregtest-dir> (adapt to your needs) and then run

cd <your-mopyregtest-dir>
pip3 install --user .

To uninstall, run

pip3 uninstall mopyregtest

Future Work

  • Support other simulators like e.g. Dymola, MapleSim, SystemModeler or others
  • Make definition of the tests even simpler, e.g. using a more human-readable BDD approach
  • Allow for parallel execution of regression tests

Open source software used

MoPyRegtest is implemented in Python3 and uses the Python core modules (including pathlib and unittest) along with numpy and pandas.

License

MoPyRegtest is open source software. MoPyRegtest is provided "as is", without warranty of any kind. Usage is completely at your own risk. See the file LICENSE.

How to contribute

If you want to help me extend MoPyRegtest, please drop me a message! Contributions are welcome!

Authors

The MoPyRegtest is being developed by the following authors:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MoPyRegtest-0.3.1rc2.tar.gz (15.1 kB view hashes)

Uploaded Source

Built Distribution

MoPyRegtest-0.3.1rc2-py3-none-any.whl (17.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page