From fdcab081c41e5d03773ca4fa89b559feafc5bccc Mon Sep 17 00:00:00 2001 From: FWuellhorst Date: Thu, 12 Dec 2024 18:52:45 +0100 Subject: [PATCH 1/2] fix file ending, re-raise error with better message (#580) --- buildingspy/development/regressiontest.py | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index 46b3b1b3..43b5cba7 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -676,15 +676,19 @@ def _checkKey(self, key, fileName, counter): and the second line starts with ``key`` the counter is increased by one. """ - - with open(fileName, mode="rt", encoding="utf-8-sig") as filObj: - # 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 + try: + with open(fileName, mode="rt", encoding="utf-8-sig") as filObj: + # 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 + except UnicodeDecodeError as err: + raise ValueError( + "Failed to read file %s with utf-8-sig encoding" % fileName + ) from err @staticmethod def expand_packages(packages): @@ -3054,9 +3058,8 @@ def printNumberOfClasses(self): # skip .svn folders if pos == -1: for filNam in files: - # find .mo files - pos = filNam.find('.mo') - if pos > -1 and (root.find('Examples') == -1 or root.find('Validation') == -1): + # find .mo files which are not in Examples or Validation packages + if filNam.endswith('.mo') and (root.find('Examples') == -1 or root.find('Validation') == -1): # find classes that are not partial filFulNam = os.path.join(root, filNam) iMod = self._checkKey("model", filFulNam, iMod) From 5dcdb859814adfb623f257a40387ed32a59123c5 Mon Sep 17 00:00:00 2001 From: Michael Wetter Date: Thu, 12 Dec 2024 09:54:07 -0800 Subject: [PATCH 2/2] Run pep8 --- buildingspy/development/regressiontest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index 43b5cba7..4463fe7f 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -3059,7 +3059,8 @@ def printNumberOfClasses(self): if pos == -1: for filNam in files: # find .mo files which are not in Examples or Validation packages - if filNam.endswith('.mo') and (root.find('Examples') == -1 or root.find('Validation') == -1): + if filNam.endswith('.mo') and ( + root.find('Examples') == -1 or root.find('Validation') == -1): # find classes that are not partial filFulNam = os.path.join(root, filNam) iMod = self._checkKey("model", filFulNam, iMod)