Repository: lbl-srg/BuildingsPy

Issue:
In reference results, exclude CPUtime and EventCounter in FMI dependencies
These are only written based on the configuration of Dymola. As they are only output of the solver, they should be excluded from the reference results.

Comments:

Patch:
diff --git a/buildingspy/development/error_dictionary.py b/buildingspy/development/error_dictionary.py
index 2304f63..4a3c8d3 100644
--- a/buildingspy/development/error_dictionary.py
+++ b/buildingspy/development/error_dictionary.py
@@ -138,6 +138,13 @@ class ErrorDictionary(object):
             'model_message': "\"inner Modelica.StateGraph.StateGraphRoot\" is missing in '{}'.\n",
             'summary_message': "Number of models with missing StateGraphRoot                 : {}\n"}
 
+        self._error_dict["mismatched displayUnits"] = {
+            'tool_message': "Mismatched displayUnit",
+            'counter': 0,
+            'buildingspy_var': "iMisDisUni",
+            'model_message': "\"Mismatched displayUnit in '{}'.\n",
+            'summary_message': "Number of models with mismatched displayUnit                 : {}\n"}
+
     def get_dictionary(self):
         """ Return the dictionary with all error data
         """
diff --git a/buildingspy/development/refactor.py b/buildingspy/development/refactor.py
index ba4d363..2c064b0 100644
--- a/buildingspy/development/refactor.py
+++ b/buildingspy/development/refactor.py
@@ -637,6 +637,10 @@ def move_class(source, target):
 
     """
     ##############################################################
+    # First, remove empty subdirectories
+    _remove_empty_folders(source.replace(".", os.path.sep),
+                          removeRoot=False)
+    ##############################################################
     # Check if it is a directory with a package.mo file
     if os.path.isdir(source.replace(".", os.path.sep)):
         _move_class_directory(source, target)
@@ -665,6 +669,26 @@ def move_class(source, target):
     _update_all_references(source, target)
 
 
+def _remove_empty_folders(path, removeRoot=True):
+    ''' Remove empty directories
+    '''
+    if not os.path.isdir(path):
+        return
+
+    # remove empty subfolders
+    files = os.listdir(path)
+    if len(files):
+        for f in files:
+            fullpath = os.path.join(path, f)
+            if os.path.isdir(fullpath):
+                _remove_empty_folders(fullpath)
+
+    # if folder empty, delete it
+    files = os.listdir(path)
+    if len(files) == 0 and removeRoot:
+        os.rmdir(path)
+
+
 def _update_all_references(source, target):
     """ Updates all references in `.mo` and `.mos` files.
 
diff --git a/buildingspy/fmi/__init__.py b/buildingspy/fmi/__init__.py
index 4efbae7..7bb1d9d 100644
--- a/buildingspy/fmi/__init__.py
+++ b/buildingspy/fmi/__init__.py
@@ -58,8 +58,6 @@ def get_dependencies(fmu_file_name):
            ]
          },
          "InitialUnknowns": {
-           "CPUtime": [],
-           "EventCounter": [],
            "der(x)": [
              "u"
            ],
@@ -72,8 +70,6 @@ def get_dependencies(fmu_file_name):
            ]
          },
          "Outputs": {
-           "CPUtime": [],
-           "EventCounter": [],
            "y1": [
              "x"
            ],
@@ -120,8 +116,13 @@ def get_dependencies(fmu_file_name):
             #this_root = outputs
             for child in children:
                 variable = variable_names[int(child.attrib['index'])]
-                dependencies[typ][variable] = []
-                for ind_var in child.attrib['dependencies'].split(' '):
-                    if ind_var.strip() != "":  # If variables depend on nothing, there will be an empty string
-                        dependencies[typ][variable].append(variable_names[int(ind_var)])
+                # Exclude CPUtime and EventCounter, which are written
+                # depending on the Dymola 2018FD01 configuration.
+                if variable not in ["CPUtime", "EventCounter"]:
+                    dependencies[typ][variable] = []
+                    for ind_var in child.attrib['dependencies'].split(' '):
+                        # If variables depend on nothing, there will be an empty string, these
+                        # are therefore excluded.
+                        if ind_var.strip() != "":
+                            dependencies[typ][variable].append(variable_names[int(ind_var)])
     return dependencies


Test patch:
diff --git a/buildingspy/tests/test_development_error_dictionary.py b/buildingspy/tests/test_development_error_dictionary.py
index 393e2cc..ee9d12b 100644
--- a/buildingspy/tests/test_development_error_dictionary.py
+++ b/buildingspy/tests/test_development_error_dictionary.py
@@ -39,7 +39,8 @@ class Test_development_error_dictionary(unittest.TestCase):
                              'type inconsistent definition equations',
                              'unspecified initial conditions',
                              'unused connector',
-                             'stateGraphRoot missing'])
+                             'stateGraphRoot missing',
+                             'mismatched displayUnits'])
 
         self.assertEqual(len(k), len(k_expected), "Wrong number of keys.")
         for i in range(len(k)):
@@ -63,7 +64,8 @@ class Test_development_error_dictionary(unittest.TestCase):
                              'Type inconsistent definition equation',
                              'Dymola has selected default initial condition',
                              'Warning: The following connector variables are not used in the model',
-                             "A \\\"stateGraphRoot\\\" component was automatically introduced."])
+                             "A \\\"stateGraphRoot\\\" component was automatically introduced.",
+                             "Mismatched displayUnit"])
 
         self.assertEqual(len(k), len(k_expected), "Wrong number of tool messages.")
         for i in range(len(k)):