LBL logo

Previous topic

Examples

Next topic

Copyright and License

Development

This module contains the class Tester that runs the unit tests of the Buildings library.

class buildingspy.development.unittest.Tester

Class that runs all unit tests using Dymola.

This class can be used to run all unit tests. It searches the directory Buildings\Resources\Scripts\Dymola for all *.mos files that contain the string simulate. All these files will be executed as part of the unit tests. Any variables or parameters that are plotted by these *.mos files will be compared to previous results that are stored in Buildings\Resources\ReferenceResults\Dymola. If no reference results exist, then they will be created. Otherwise, the accuracy of the new results is compared to the reference results. If they differ by more than a prescibed tolerance, a plot such as the one below is shown.

_images/unitTestPlot.png

Plot that compares the new results (solid line) of the unit test with the old results (dotted line). The blue line indicates the time where the largest error occurs.

In this plot, the vertical line indicates the time where the biggest error occurs. The user is then asked to accept or reject the new results.

To run the unit tests, type

>>> import buildingspy.development.unittest as u
>>> ut = u.Tester()
>>> ut.run()
batchMode(batchMode)

Set the batch mode flag.

Parameters:batchMode – Set to True to run without interactive prompts and without plot windows.

By default, the unit tests require the user to respond if results differ from previous simulations. This method can be used to run the script in batch mode, suppressing all prompts that require the user to enter a response. If run in batch mode, no new results will be stored. To run the unit tests in batch mode, enter

>>> import buildingspy.development.unittest as u
>>> ut = u.Tester()
>>> ut.batchMode(True)
>>> ut.run()
checkPythonModuleAvailability()

Check whether all required python modules are installed.

If some modules are missing, then an ImportError is raised.

deleteTemporaryDirectories(delete)

Flag, if set to False, then the temporary directories will not be deleted after the unit tests are run.

Parameters:delete – Flag, set to False to avoid the temporary directories to be deleted.

Unless this method is called prior to running the unit tests with delete=False, all temporary directories will be deleted after the unit tests.

getModelicaCommand()

Return the name of the modelica executable.

Returns:The name of the modelica executable.
run()

Run all unit tests and checks the results.

Returns:0 if no errros occurred during the unit tests, otherwise a non-zero value.

This method

  • creates temporary directories for each processors,
  • copies the directory ‘Buildings’ into these temporary directories,
  • creates run scripts that run all unit tests,
  • runs these unit tests,
  • collects the dymola log files from each process,
  • writes the combined log file dymola.log to the current directory,
  • compares the results of the new simulations with reference results that are stored in Resources/ReferenceResults,
  • writes the message Unit tests completed successfully. if no error occured,
  • returns 0 if no errors occurred, or non-zero otherwise.
setDataDictionary()

Build the data structures that are needed to parse the output files.

setNumberOfThreads(number)

Set the number of parallel threads that are used to run the unit tests.

Parameters:number – The number of parallel threads that are used to run the unit tests.

By default, the number of parallel threads are set to be equal to the number of processors of the computer.

useExistingResults(dirs)

This function allows to use existing results, as opposed to running a simulation.

Parameters:dirs – A non-empty list of directories that contain existing results.

This method can be used for testing and debugging. If called, then no simulation is run. If the directories ['/tmp/tmp-Buildings-0-zABC44', '/tmp/tmp-Buildings-0-zQNS41'] contain previous results, then this method can be used as

>>> import buildingspy.development.unittest as u
>>> l=['/tmp/tmp-Buildings-0-zABC44', '/tmp/tmp-Buildings-0-zQNS41']
>>> ut = u.Tester()
>>> ut.useExistingResults(l)
>>> ut.run()