Repository: lbl-srg/BuildingsPy

Issue:
add test for Mismatched displayUnit
Add a test for `Mismatched displayUnit` to the regression testing

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.
 


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)):