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

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

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.6.0.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mopyregtest-0.6.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file mopyregtest-0.6.0.tar.gz.

File metadata

  • Download URL: mopyregtest-0.6.0.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mopyregtest-0.6.0.tar.gz
Algorithm Hash digest
SHA256 8c27fba411909d900a0bf17558ce35df3a2facb1afbf0b2785927914685d7ff0
MD5 c39267bfc9ea396eab3e25b607ee0407
BLAKE2b-256 d46a32281482bf188802a2a1f9c45d38be722e11d669597790fb7951ddb02002

See more details on using hashes here.

File details

Details for the file mopyregtest-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: mopyregtest-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mopyregtest-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c54f8a1669732183f0391c4387c2dc671245faa266b3085d6e8c0b064db25850
MD5 42c6c556707871586e43155caaa5886b
BLAKE2b-256 a8961bda688ee2a13ca42796b1935c6d5605d3afb5c13cb997d1203aa8fa3782

See more details on using hashes here.

Supported by

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