Add return code to test command

This commit is contained in:
Tim Van Baak 2022-08-12 21:25:46 -07:00
parent 1379e5f8a3
commit 66b0fb1b60
1 changed files with 20 additions and 5 deletions

View File

@ -16,6 +16,7 @@ def command_test(args):
nargs="+",
help="Providers to test.",
metavar="name",
dest="providers",
default=[])
parser.add_argument("--path",
nargs="+",
@ -25,37 +26,44 @@ def command_test(args):
default=[])
args = parser.parse_args(args)
ret = 0
search_path = args.path
if args.provider:
print("INTAKEPATH:")
for path in search_path:
print(f" {path}")
for provider_name in args.provider:
for provider_name in args.providers:
print(f"Checking provider {provider_name}")
provider = load_provider(search_path, provider_name)
if not provider:
print(" x Not found")
ret = 1
continue
# Settings class
if not hasattr(provider, "Settings"):
print(" x Missing Settings class")
ret = 1
else:
settings = getattr(provider, "Settings")
if not issubclass(settings, BaseSettings):
print(" x Settings class does not inherit from intake.BaseSettings")
ret = 1
else:
print(" o Settings")
# update function
if not hasattr(provider, "Settings"):
print(" x Missing update(config, state)")
ret = 1
else:
update = getattr(provider, "update")
if not callable(update):
print(" x update is not callable")
ret = 1
else:
update_sig = inspect.signature(update)
if list(update_sig.parameters) != ["config", "state"]:
print(" x update does not have signature (config, state)")
ret = 1
else:
print(" o update")
# on-create hook
@ -63,10 +71,12 @@ def command_test(args):
on_create = getattr(provider, "on_create")
if not callable(on_create):
print(" x on_create is not callable")
ret = 1
else:
create_sig = inspect.signature(on_create)
if list(create_sig.parameters) != ["config", "state", "item"]:
print(" x on_create does not have signature (config, state, item)")
ret = 1
else:
print(" o on_create")
# on-delete hook
@ -74,10 +84,12 @@ def command_test(args):
on_delete = getattr(provider, "on_delete")
if not callable(on_delete):
print(" x on_delete is not callable")
ret = 1
else:
delete_sig = inspect.signature(on_delete)
if list(delete_sig.parameters) != ["config", "state", "item"]:
print(" x on_delete does not have signature (config, state, item)")
ret = 1
else:
print(" o on_delete")
# actions
@ -86,13 +98,16 @@ def command_test(args):
action = getattr(provider, action_name)
if not callable(action):
print(f" x {action_name} is not callable")
ret = 1
else:
action_sig = inspect.signature(action)
if list(action_sig.parameters) != ["config", "state", "item"]:
print(f" x {action_name} does not have signature (config, state, item)")
ret = 1
else:
print(f" o {action_name}")
print("Done")
return ret
def command_help(args):