Skip to main content

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

Project status
Unit tests Examples Example usage in other repo Publish to PyPI

A lightweight, CI-friendly regression testing framework for Modelica models, wrapped in Python's unittest module. Uses OpenModelica for model translation and simulation.

Key features:

  • Regression testing — compare simulation results against reference CSV files using configurable metrics and tolerances
  • Success-only testing — verify that models compile, build, and simulate successfully (useful for unit test models with built-in assertions)
  • Automatic test generation — generate unittest test files for entire Modelica libraries via CLI or Python script
  • CSV comparison — compare two CSV result files directly from the command line

Prerequisites

Installation

# From PyPI
python3 -m pip install --user mopyregtest

# From source
git clone https://github.com/pstelzig/MoPyRegtest.git
cd MoPyRegtest
python3 -m pip install --user .

Verify the CLI: mopyregtest --help

Tip: If mopyregtest is not found, check that pip's script directory is on your PATH.
Run python3 -m pip uninstall mopyregtest (without confirming) to see where pip installed the executable.

Quick start

Regression test (manual)

import mopyregtest

tester = mopyregtest.RegressionTest(
    package_folder="~/.openmodelica/libraries/Modelica 4.0.0+maint.om",
    model_in_package="Modelica.Electrical.Analog.Examples.HeatingRectifier",
    result_folder="./results",
    modelica_version="4.0.0")

tester.compare_result(reference_result="references/HeatingRectifier_res.csv", tol=1e-3)

Success-only test (manual)

tester = mopyregtest.RegressionTest(
    package_folder="~/.openmodelica/libraries/Modelica 4.0.0+maint.om",
    model_in_package="Modelica.Blocks.Examples.Filter",
    result_folder="./results")

tester.check_success()

Auto-generate tests (CLI)

# Regression tests
mopyregtest generate ./gen_tests MyTest ~/".openmodelica/libraries/Modelica 4.0.0+maint.om/" \
    Modelica.Blocks.Sources.Sine,Modelica.Blocks.Sources.Step

# Success-only tests
mopyregtest generate --mode=success ./gen_tests MySimTest ~/".openmodelica/libraries/Modelica 4.0.0+maint.om/" \
    Modelica.Blocks.Examples.Filter

Compare CSV files (CLI)

mopyregtest compare --metric=Lp_dist --tol=0.015 --validated-cols=y reference.csv actual.csv

Documentation

For detailed usage, metrics reference, and worked examples see the documentation.
Runnable examples are in the examples/ folder.

License

MIT — see LICENSE.

Contributing

Contributions are welcome! Please open an issue or pull request.

Authors

Metadata

Release files for MoPyRegtest 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for MoPyRegtest 0.6.0
File Size Uploaded
mopyregtest-0.6.0.tar.gz 21.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for MoPyRegtest 0.6.0
File Interpreter ABI Platform
mopyregtest-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.6 kB

Release files / mopyregtest-0.6.0.tar.gz

Download URL mopyregtest-0.6.0.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8c27fba411909d900a0bf17558ce35df3a2facb1afbf0b2785927914685d7ff0
BLAKE2b-256 checksum
How to use checksums
d46a32281482bf188802a2a1f9c45d38be722e11d669597790fb7951ddb02002
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / mopyregtest-0.6.0-py3-none-any.whl

Download URL mopyregtest-0.6.0-py3-none-any.whl
Size 22.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c54f8a1669732183f0391c4387c2dc671245faa266b3085d6e8c0b064db25850
BLAKE2b-256 checksum
How to use checksums
a8961bda688ee2a13ca42796b1935c6d5605d3afb5c13cb997d1203aa8fa3782
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page