-
Notifications
You must be signed in to change notification settings - Fork 32
Unit Testing
Unit tests are an important part of making sure we don't, unintentionally, ruin our life or others. :face_palm:
--> Insert funny analogy here 😑 <--
In that spirit, contributors, let us all do our part! ☯️
To see what tests are already part of the system you can run (from your IDE) all the regression tests. This can be helpful in finding issues if the python regression system fails. To do so:
- Copy
runAll_Dymola.mosfrom/TRANSFORM-Library/to your favorite place to run models. Recommended for that to be a directory such as/Documents/Dymola/. - Open up your IDE and execute the
runAll_Dymola.mosscript.
TADA!
Unit tests are automagically added to the regression system from a python script if 3 simple things are followed.
-
The model to be added must be put in a package labeled
Examplescomplete with the icon extensionTRANSFORM.Icons.ExamplesPackage.
-
The model to be added must also extend the icon
TRANSFORM.Icons.Exampleat the highest level.-
Note: Currently a model's unit test in an
Examplespackage can not have the same name as any other model in any otherExamplespackage, regardless of path. I know, I know... super lame. This is a current "feature" of the buildingspy regression system we are piggybacking 🐖. Fortunately, when you run the regression test system you'll get a friendly reminder letting you know you need to change it.

-
Note: Currently a model's unit test in an
-
The unit test model
TRANSFORM.Utilities.ErrorAnalysis.UnitTestsmust be placed on the model with the default nameunitTests.-
Note: The variable(s) set to
unitTest.xwill be added to the regression system.unitTest.x_referenceprovides a place to put the expected result if desired to make a comparison from the IDE. However, values other thanxfromUnitTestsare not saved to the regression test reference result file.

-
Note: The variable(s) set to
-
Lots of extraneous files get put to a Modelica library during development. Before running the python scripts to add files to the regression system you need to clean up files, either manually or using a directory saving approach (recommended) described below.
- (From IDE) Right-click
TRANSFORMand check "Store as one file". - (From IDE) Save TRANSFORM to a temporary location (e.g, Desktop).
- Move the directory
/TRANSFORM-Library/TRANSFORM/Resourcesup a level to/TRANSFORM-Library/. This file will not be retained in the single file version of the library. - Delete the directory
/TRANSFORM-Library/TRANSFORM/ - (From IDE) Right-click
TRANSFORMand uncheck "Store as one file". If prompted, select "Directores - No Questions". - (From IDE) Save TRANSFORM back to the original location (i.e.,
/TRANSFORM-Library/). - Now is a good time to check Git to make sure the process performed as expected. You should now have a clean library.
- Commit changes to Git.
- (From IDE) Right-click
Take a gander at existing examples to get a real feel for how it works. Next up, python!
- Run
createUnitScrips.pyfrom its location (i.e.,TRANSFORM-Library\TRANSFORM\Resources\pythonas the working directory)- This deletes the entire
/Resources/Scripts/directory and rebuilds it from scratch
- This deletes the entire
- Check that the expected
.mosfiles were added to the/Resources/Scripts/directory. - Run
pip install buildingspy==1.6.0from the terminal if buildingspy is not already installed- Currently this process is tied to an older version of buildingspy in Windows OS. Uncertain about Linux.
- Run regression system from its location (i.e.,
TRANSFORM-Library\as the working directory). Indicateywhen prompted to add the results to testing system. These files are saved in/TRANSFORM-Library/TRANSFORM/Resources/ReferenceResults/.- Linux:
regtestsLinux.py - Windows:
regtestsWin_customBuildPy.py -
Note: By default running this file will go through all tests. To simulate a single test use the
TestSinglePackagefunction.
- Linux:
- If everything looks good, stage and push your changes to your repository and create a merge request.
That's it! Treat yourself 🍨
- If having issues with buildingspy regression test on Windows system replace buildingspy file
regressiontest.pywith the one from ModelicaPy (pip install modelicapyor download zip file from Github/Gitlab)-
regressiontest.pyin buildingspy is normally located atC:\Users\USERNAME\AppData\Local\Continuum\anaconda2\Lib\site-packages\buildingspy\development - Once replaced, delete the old
regressiontest.pycfile if present. - The new
regressiontest.pyfile from ModelicaPy may need to be compiled before it can be used. If so, change to thebuildingspy\developmentpath and run the following in python (i.e., IPython) to get a newregressiontest.pycfile.- import py_compile
- py_compile.compile('regressiontest.py')
-
- It is highly recommended to simulate the
runAll*.mosfile from Dymola to ensure all unit tests are able to simulate. The current regression system has little to no inspection ability in the event a model fails to simulate.