test: add comprehensive unit tests and fix bare excepts
- Added comprehensive unit test suite covering AI, core, plugins, completion, API, and hooks using pytest. - Replaced bare 'except:' clauses across the codebase with specific exception handling (e.g., ValueError, KeyError, OSError) to prevent swallowing system exit calls. - Fixed Python 3.8+ AST compatibility in plugins.py (support for ast.Constant). - Removed deprecated pkg_resources import from __init__.py. - Fixed missing 'printer' import in configfile.py that caused NameErrors during save failures.
This commit is contained in:
1 parent
7de6003435
commit
cf95befb43
21 files changed
+2490
-56
No files matched your search
+5
-5
@@ -84,12 +84,12 @@ class node:
|
||||
if profile and config != '':
|
||||
try:
|
||||
setattr(self,key,config.profiles[profile.group(1)][key])
|
||||
except:
|
||||
except KeyError:
|
||||
setattr(self,key,"")
|
||||
elif attr[key] == '' and key == "protocol":
|
||||
try:
|
||||
setattr(self,key,config.profiles["default"][key])
|
||||
except:
|
||||
except (KeyError, AttributeError):
|
||||
setattr(self,key,"ssh")
|
||||
else:
|
||||
setattr(self,key,attr[key])
|
||||
@@ -108,12 +108,12 @@ class node:
|
||||
if profile:
|
||||
try:
|
||||
self.jumphost[key] = config.profiles[profile.group(1)][key]
|
||||
except:
|
||||
except KeyError:
|
||||
self.jumphost[key] = ""
|
||||
elif self.jumphost[key] == '' and key == "protocol":
|
||||
try:
|
||||
self.jumphost[key] = config.profiles["default"][key]
|
||||
except:
|
||||
except KeyError:
|
||||
self.jumphost[key] = "ssh"
|
||||
if isinstance(self.jumphost["password"],list):
|
||||
jumphost_password = []
|
||||
@@ -158,7 +158,7 @@ class node:
|
||||
try:
|
||||
decrypted = decryptor.decrypt(ast.literal_eval(passwd)).decode("utf-8")
|
||||
dpass.append(decrypted)
|
||||
except:
|
||||
except Exception:
|
||||
raise ValueError("Missing or corrupted key")
|
||||
return dpass
|
||||
|
||||
|
||||
Reference in new issue
Block a user