Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exclude mos from file #160

Merged
merged 16 commits into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 49 additions & 44 deletions buildingspy/development/regressiontest.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def __init__(self, check_html=True, executable="dymola", cleanup=True):
self._pedanticModelica = False

# List of scripts that should be excluded from the regression tests
# self._excludeMos=['Resources/Scripts/Dymola/Airflow/Multizone/Examples/OneOpenDoor.mos']
self._excludeMos = []
# self._exclude_tests=['Resources/Scripts/Dymola/Airflow/Multizone/Examples/OneOpenDoor.mos']
self._exclude_tests = []

# Number of data points that are used
self._nPoi = 101
Expand Down Expand Up @@ -410,55 +410,61 @@ def checkPythonModuleAvailability(self):
raise ImportError(msg)

def _checkKey(self, key, fileName, counter):
''' Check whether the file ``fileName`` contains the string ``key``
as the first string on the first or second line.
If ``key`` is found, increase the counter.
''' Checks whether ``key`` is contained in the header of the file ``fileName``
If the first line starts with ``within``
and the second line starts with ``key``
the counter is increased by one.
'''

with open(fileName, mode="rt", encoding="utf-8-sig") as filObj:
filTex = filObj.readline()
# Strip white spaces so we can test strpos for zero.
# This test returns non-zero for partial classes.
filTex.strip()
strpos = filTex.find("within")
if strpos == 0:
# first line is "within ...
# get second line
filTex = filObj.readline()
filTex.strip()
strpos = filTex.find(key)
if strpos == 0:
counter += 1
return counter
# filObj is an iterable object, so we can use next(filObj)
line0 = next(filObj).strip()
if line0.startswith("within"):
line1 = next(filObj).strip()
if line1.startswith(key):
counter += 1
return counter

def setExcludeTest(self, excludeFile):
''' Exclude from the regression tests all tests specified in ``excludeFile``.

:param excludeFile: The text file with files that shall be excluded from regression tests
'''
if os.path.isfile(excludeFile):
with open(excludeFile, mode="r", encoding="utf-8-sig") as f:
for line in f:
if line.rstrip().endswith('.mos') and not line.startswith('#'):
filNamTup = line.rpartition(self.getLibraryName())
filNam = filNamTup[2].rstrip().replace('\\', '/').lstrip('/')
self._exclude_tests.append(filNam)
else:
self._reporter.writeError("Could not find file {!s}".format(excludeFile))

def _includeFile(self, fileName):
''' Returns true if the file need to be included in the list of scripts to run

:param fileName: The name of the ``*.mos`` file.

The parameter *fileName* need to be of the form
*Resources/Scripts/Dymola/Fluid/Actuators/Examples/Damper.mos*
or *Resources/Scripts/someOtherFile.ext*.
This function checks if *fileName* exists in the global list
self._excludeMos. During this check, all backward slashes will
be replaced by a forward slash.
'''
pos = fileName.endswith('.mos')
if pos > -1: # This is an mos file
The parameter ``fileName`` need to be of the form
``Resources/Scripts/Dymola/Fluid/Actuators/Examples/Damper.mos``
or ``Resources/Scripts/someOtherFile.ext``.
This function checks if ``fileName`` exists in the global list
``self._exclude_tests``. For checking, ``fileName`` will be normalized (strip
whitespace, convert backslash to slash, strip path).
'''
if fileName.rstrip().endswith('.mos'):
# This is a mos file, normalize the name
filNamTup = fileName.rpartition(self.getLibraryName())
filNam = filNamTup[2].rstrip().replace('\\', '/').lstrip('/')
# Check whether the file is in the exclude list
fileName = fileName.replace('\\', '/')
# Remove all files, except a few for testing
# test=os.path.join('Resources','Scripts','Dymola','Controls','Continuous','Examples')
## test=os.path.join('Resources', 'Scripts', 'Dymola', 'Fluid', 'Movers', 'Examples')
# if fileName.find(test) != 0:
# return False

if (self._excludeMos.count(fileName) == 0):
return True
else:
print("*** Warning: Excluded file {} from the regression tests.".format(fileName))
if filNam in self._exclude_tests:
self._reporter.writeWarning(
"*** Warning: Excluded file {} from the regression tests.".format(filNam))
return False
else:
return True
else:
# This is not a mos file, do not include it
return False

@staticmethod
Expand Down Expand Up @@ -717,8 +723,7 @@ def _get_attribute_value(line, keyword, dat):
_get_attribute_value(lin, attr, dat)

# Check if this model need to be translated as an FMU.
pos = lin.find("translateModelFMU")
if pos > -1:
if "translateModelFMU" in lin:
dat['mustExportFMU'] = True
if dat['mustExportFMU']:
for attr in ["modelToOpen", "modelName"]:
Expand Down Expand Up @@ -2209,7 +2214,7 @@ def run(self):
# Remove all data that do not require a simulation or an FMU export.
# Otherwise, some processes may have no simulation to run and then
# the json output file would have an invalid syntax
for ele in self._data:
for ele in self._data[:]:
if not (ele['mustSimulate'] or ele['mustExportFMU']):
self._data.remove(ele)

Expand Down Expand Up @@ -2340,9 +2345,9 @@ def run(self):
self._checkSimulationError(self._simulator_log_file)

# Print list of files that may be excluded from unit tests
if len(self._excludeMos) > 0:
if len(self._exclude_tests) > 0:
print("*** Warning: The following files may be excluded from the regression tests:\n")
for fil in self._excludeMos:
for fil in self._exclude_tests:
print(" {}".format(fil))

# Print time
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# skip some mos tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this file doing? I don't see it anywhere else used in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used it locally to test whether the new function works, will write a proper test instead and use it there.

MyModelicaLibrary\Resources\Scripts\Dymola\Examples\BooleanParameters.mos
# MyModelicaLibrary\Resources\Scripts\Dymola\Examples\Constants.mos
MyModelicaLibrary\Resources\Scripts\Dymola\Examples\MyStep.mos
MyModelicaLibrary\Resources\Scripts\Dymola\Examples\FMUs\Gain.mos
MyModelicaLibrary\Resources\Scripts\Dymola\Examples\FMUs\Integrator_Underscore.mos
MyModelicaLibrary\Resources\Scripts\Dymola\Examples\FMUs\IntegratorGain.mos
10 changes: 10 additions & 0 deletions buildingspy/tests/test_development_regressiontest.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ def test_setSinglePackage_4(self):
self.assertRaises(ValueError, rt.setSinglePackage,
"MyModelicaLibrary.Examples,MyModelicaLibrary.Examples.FMUs")

def test_setExcludeTest(self):
import buildingspy.development.regressiontest as r
rt = r.Tester(check_html=False)
myMoLib = os.path.join("buildingspy", "tests", "MyModelicaLibrary")
skpFil = os.path.join(myMoLib, "Resources", "Scripts", "skipUnitTestList.txt")
rt.setLibraryRoot(myMoLib)
rt.setExcludeTest(skpFil)
rt.run()
self.assertEqual(1, rt.get_number_of_tests())

def test_runSimulation(self):
import buildingspy.development.regressiontest as r
self.assertRaises(OSError,
Expand Down