Catch specific exception rather than anything
The bare "except" also catches exceptions like "NameError" and "SystemExit", which we really should not catch. In scour.py, use the most specific exception (NotFoundErr) and in the tests just catch any "regular" exception. Reported by flake8. Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
parent
f3d8936b5e
commit
843706be39
2 changed files with 6 additions and 6 deletions
|
|
@ -56,7 +56,7 @@ import re
|
|||
import sys
|
||||
import time
|
||||
import xml.dom.minidom
|
||||
from xml.dom import Node
|
||||
from xml.dom import Node, NotFoundErr
|
||||
from collections import namedtuple
|
||||
from decimal import Context, Decimal, InvalidOperation, getcontext
|
||||
|
||||
|
|
@ -3619,7 +3619,7 @@ def scourXmlFile(filename, options=None):
|
|||
for node in all_nodes:
|
||||
try:
|
||||
node.setIdAttribute('id')
|
||||
except:
|
||||
except NotFoundErr:
|
||||
pass
|
||||
|
||||
return doc
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class EmptyOptions(unittest.TestCase):
|
|||
try:
|
||||
scourString(self.MINIMAL_SVG, options)
|
||||
fail = False
|
||||
except:
|
||||
except Exception:
|
||||
fail = True
|
||||
self.assertEqual(fail, False,
|
||||
'Exception when calling "scourString" with empty options object')
|
||||
|
|
@ -76,7 +76,7 @@ class EmptyOptions(unittest.TestCase):
|
|||
try:
|
||||
scourXmlFile('unittests/minimal.svg', options)
|
||||
fail = False
|
||||
except:
|
||||
except Exception:
|
||||
fail = True
|
||||
self.assertEqual(fail, False,
|
||||
'Exception when calling "scourXmlFile" with empty options object')
|
||||
|
|
@ -91,7 +91,7 @@ class EmptyOptions(unittest.TestCase):
|
|||
try:
|
||||
start(options, input, output)
|
||||
fail = False
|
||||
except:
|
||||
except Exception:
|
||||
fail = True
|
||||
sys.stdout = stdout_temp
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ class InvalidOptions(unittest.TestCase):
|
|||
try:
|
||||
scourXmlFile('unittests/ids-to-strip.svg', options)
|
||||
fail = False
|
||||
except:
|
||||
except Exception:
|
||||
fail = True
|
||||
self.assertEqual(fail, False,
|
||||
'Exception when calling Scour with invalid options')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue