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

fix file ending, re-raise error with better message (#580) #581

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 16 additions & 12 deletions buildingspy/development/regressiontest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -3054,9 +3058,9 @@ 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)
Expand Down