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

DM-12656: Deal with new flake8 warnings #20

Merged
merged 2 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/lsst/pex/config/configChoiceField.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def __getitem__(self, k, at=None, label="default"):
except KeyError:
try:
dtype = self._field.typemap[k]
except:
except Exception:
raise FieldValidationError(self._field, self._config,
"Unknown key %r in Registry/ConfigChoiceField" % k)
name = _joinNamePath(self._config._name, self._field.name, k)
Expand All @@ -238,7 +238,7 @@ def __setitem__(self, k, value, at=None, label="assignment"):

try:
dtype = self._field.typemap[k]
except:
except Exception:
raise FieldValidationError(self._field, self._config, "Unknown key %r" % k)

if value != dtype and type(value) != dtype:
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/pex/config/configurableField.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def validateTarget(self, target, ConfigClass):
if ConfigClass is None:
try:
ConfigClass = target.ConfigClass
except:
except Exception:
raise AttributeError("'target' must define attribute 'ConfigClass'")
if not issubclass(ConfigClass, Config):
raise TypeError("'ConfigClass' is of incorrect type %s."
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/pex/config/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def setDefaults(self):
# Indicate in the history that these values came from C++, even if we can't say which line
self.readControl(r, __at=[(ctrl.__name__ + " C++", 0, "setDefaults", "")], __label="defaults",
__reset=True)
except:
except Exception:
pass # if we can't instantiate the Control, don't set defaults

ctrl.ConfigClass = cls
Expand Down
20 changes: 10 additions & 10 deletions tests/test_Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class Simple(pexConfig.Config):
allowed={"Hello": "First choice", "World": "second choice"})
r = pexConfig.RangeField("Range test", float, default=3.0, optional=False,
min=3.0, inclusiveMin=True)
l = pexConfig.ListField("list test", int, default=[1, 2, 3], maxLength=5,
itemCheck=lambda x: x is not None and x > 0)
ll = pexConfig.ListField("list test", int, default=[1, 2, 3], maxLength=5,
itemCheck=lambda x: x is not None and x > 0)
d = pexConfig.DictField("dict test", str, str, default={"key": "value"},
itemCheck=lambda x: x.startswith('v'))
n = pexConfig.Field("nan test", float, default=float("NAN"))
Expand Down Expand Up @@ -100,7 +100,7 @@ def testInit(self):
self.assertEqual(self.simple.f, 3.0)
self.assertEqual(self.simple.b, False)
self.assertEqual(self.simple.c, "Hello")
self.assertEqual(list(self.simple.l), [1, 2, 3])
self.assertEqual(list(self.simple.ll), [1, 2, 3])
self.assertEqual(self.simple.d["key"], "value")
self.assertEqual(self.inner.f, 0.0)

Expand All @@ -124,7 +124,7 @@ def testValidate(self):
self.simple.d["failKey"] = "failValue"
except pexConfig.FieldValidationError:
pass
except:
except Exception:
raise "Validation error Expected"
self.simple.validate()

Expand Down Expand Up @@ -295,14 +295,14 @@ def testConvert(self):
self.assertEqual(pol.get("f"), self.simple.f)
self.assertEqual(pol.get("b"), self.simple.b)
self.assertEqual(pol.get("c"), self.simple.c)
self.assertEqual(pol.getArray("l"), list(self.simple.l))
self.assertEqual(pol.getArray("ll"), list(self.simple.ll))

ps = pexConfig.makePropertySet(self.simple)
self.assertEqual(ps.exists("i"), False)
self.assertEqual(ps.get("f"), self.simple.f)
self.assertEqual(ps.get("b"), self.simple.b)
self.assertEqual(ps.get("c"), self.simple.c)
self.assertEqual(list(ps.get("l")), list(self.simple.l))
self.assertEqual(list(ps.get("ll")), list(self.simple.ll))

pol = pexConfig.makePolicy(self.comp)
self.assertEqual(pol.get("c.f"), self.comp.c.f)
Expand Down Expand Up @@ -381,25 +381,25 @@ def testCompare(self):
def outFunc(msg):
outList.append(msg)
simple2.b = True
simple2.l.append(4)
simple2.ll.append(4)
simple2.d["foo"] = "var"
self.assertFalse(self.simple.compare(simple2, shortcut=True, output=outFunc))
self.assertEqual(len(outList), 1)
del outList[:]
self.assertFalse(self.simple.compare(simple2, shortcut=False, output=outFunc))
output = "\n".join(outList)
self.assertIn("Inequality in b", output)
self.assertIn("Inequality in size for l", output)
self.assertIn("Inequality in size for ll", output)
self.assertIn("Inequality in keys for d", output)
del outList[:]
self.simple.d["foo"] = "vast"
self.simple.l.append(5)
self.simple.ll.append(5)
self.simple.b = True
self.simple.f += 1E8
self.assertFalse(self.simple.compare(simple2, shortcut=False, output=outFunc))
output = "\n".join(outList)
self.assertIn("Inequality in f", output)
self.assertIn("Inequality in l[3]", output)
self.assertIn("Inequality in ll[3]", output)
self.assertIn("Inequality in d['foo']", output)
del outList[:]
comp2.r["BBB"].f = 1.0 # changing the non-selected item shouldn't break equality
Expand Down
8 changes: 4 additions & 4 deletions tests/test_configDictField.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@ def testConstructor(self):
try:
class BadKeytype(pexConfig.Config):
d = pexConfig.ConfigDictField("...", keytype=list, itemtype=Config1)
except:
except Exception:
pass
else:
raise SyntaxError("Unsupported keytypes should not be allowed")

try:
class BadItemtype(pexConfig.Config):
d = pexConfig.ConfigDictField("...", keytype=int, itemtype=dict)
except:
except Exception:
pass
else:
raise SyntaxError("Unsupported itemtypes should not be allowed")

try:
class BadItemCheck(pexConfig.Config):
d = pexConfig.ConfigDictField("...", keytype=str, itemtype=Config1, itemCheck=4)
except:
except Exception:
pass
else:
raise SyntaxError("Non-callable itemCheck should not be allowed")

try:
class BadDictCheck(pexConfig.Config):
d = pexConfig.DictField("...", keytype=int, itemtype=Config1, dictCheck=4)
except:
except Exception:
pass
else:
raise SyntaxError("Non-callable dictCheck should not be allowed")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_configurableField.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,23 @@ def testConstructor(self):
try:
class BadTarget(pexConf.Config):
d = pexConf.ConfigurableField("...", target=None)
except:
except Exception:
pass
else:
raise SyntaxError("Uncallable targets should not be allowed")

try:
class NoConfigClass(pexConf.Config):
d = pexConf.ConfigurableField("...", target=Target2)
except:
except Exception:
pass
else:
raise SyntaxError("Missing ConfigClass should not be allowed")

try:
class BadConfigClass(pexConf.Config):
d = pexConf.DictField("...", target=Target2, ConfigClass=Target2)
except:
except Exception:
pass
else:
raise SyntaxError("ConfigClass that are not subclasses of Config should not be allowed")
Expand Down
8 changes: 4 additions & 4 deletions tests/test_dictField.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ def testConstructor(self):
try:
class BadKeytype(pexConfig.Config):
d = pexConfig.DictField("...", keytype=list, itemtype=int)
except:
except Exception:
pass
else:
raise SyntaxError("Unsupported keyptype DictFields should not be allowed")

try:
class BadItemtype(pexConfig.Config):
d = pexConfig.DictField("...", keytype=int, itemtype=dict)
except:
except Exception:
pass
else:
raise SyntaxError("Unsupported itemtype DictFields should not be allowed")

try:
class BadItemCheck(pexConfig.Config):
d = pexConfig.DictField("...", keytype=int, itemtype=int, itemCheck=4)
except:
except Exception:
pass
else:
raise SyntaxError("Non-callable itemCheck DictFields should not be allowed")

try:
class BadDictCheck(pexConfig.Config):
d = pexConfig.DictField("...", keytype=int, itemtype=int, dictCheck=4)
except:
except Exception:
pass
else:
raise SyntaxError("Non-callable dictCheck DictFields should not be allowed")
Expand Down
14 changes: 7 additions & 7 deletions tests/test_listField.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,32 @@ class ListFieldTest(unittest.TestCase):
def testConstructor(self):
try:
class BadDtype(pexConfig.Config):
l = pexConfig.ListField("...", list)
except:
ll = pexConfig.ListField("...", list)
except Exception:
pass
else:
raise SyntaxError("Unsupported dtype ListFields should not be allowed")

try:
class BadLengths(pexConfig.Config):
l = pexConfig.ListField("...", int, minLength=4, maxLength=2)
ll = pexConfig.ListField("...", int, minLength=4, maxLength=2)
except ValueError:
pass
else:
raise SyntaxError("minLnegth <= maxLength should not be allowed")

try:
class BadLength(pexConfig.Config):
l = pexConfig.ListField("...", int, length=-1)
except:
ll = pexConfig.ListField("...", int, length=-1)
except Exception:
pass
else:
raise SyntaxError("negative length should not be allowed")

try:
class BadLength2(pexConfig.Config):
l = pexConfig.ListField("...", int, maxLength=-1)
except:
ll = pexConfig.ListField("...", int, maxLength=-1)
except Exception:
pass
else:
raise SyntaxError("negative max length should not be allowed")
Expand Down