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

General
License: MIT contributions welcome

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
  • Simulation-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
pip3 install --user mopyregtest

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

Verify the CLI: mopyregtest --help

Tip: If mopyregtest is not found, check that pip's script directory is on your PATH.
Run pip3 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)
tester.cleanup(ask_confirmation=False)

Simulation-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_simulation()
tester.cleanup(ask_confirmation=False)

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

# Simulation-only tests
mopyregtest generate --mode=simulation ./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.0rc1.tar.gz (21.7 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.0rc1-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mopyregtest-0.6.0rc1.tar.gz
  • Upload date:
  • Size: 21.7 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.0rc1.tar.gz
Algorithm Hash digest
SHA256 c7b78d4dbaa3e3b20a50e61efae0cdc4de9d3da517dd781b8c92be7e72b16ba7
MD5 b5d99b9a446a8aa54ca3e9ac8986806d
BLAKE2b-256 bbee334fa9c64fb8bd922d998e11df73676e027f0a7b9fb8c95a3d2f18c83c3f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mopyregtest-0.6.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 22.1 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.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff3b0adf822e6f306bfc72b35667358c0732e1e406164ba72b722f00f3f0c262
MD5 a724f4a5a99e3d15ecaa0afdb97fc6a2
BLAKE2b-256 06872928e0bd273edd2bb36cf147a74c9fa067ac3ae71b501df919925824d579

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