for self-test: handle TypeErrors nicely

This commit is contained in:
lars 2008-04-07 02:57:33 +00:00
parent 43a5c83ea8
commit 81e5a2e8fd

View file

@ -741,8 +741,12 @@ class Blockdevice:
output += "\tflags:\t\t" output += "\tflags:\t\t"
for funcname in [ func for func in dir(self) for funcname in [ func for func in dir(self)
if func.startswith("is_") and callable(getattr(self, func))]: if func.startswith("is_") and callable(getattr(self, func))]:
if getattr(self, funcname)(): try:
output += "%s " % funcname[3:] if getattr(self, funcname)():
output += "%s " % funcname[3:]
except TypeError:
# skip tests that need arguments (e.g. "is_parent_of")
pass
output += "\n" output += "\n"
return output return output
@ -1003,7 +1007,11 @@ if __name__ == '__main__':
for check in flag_checker: for check in flag_checker:
show("List of '%s' devices:" % check[3:]) show("List of '%s' devices:" % check[3:])
for device in blocks: for device in blocks:
if getattr(device, check)(): try:
show("\t%s" % device) if getattr(device, check)():
show("\t%s" % device)
except TypeError:
# ignore tests that need a second argument
pass
show() show()