Upgraded testing utility

parent bf5ec2a2
from unittest import TestCase, main from unittest import TestCase, main
from pprint import pprint as pp from pprint import pprint as pp
from dbus import SystemBus from dbus import SystemBus
import os, sys
sep = "\n" + "-"*30 + "\n"
SEPARATOR = "\n" + "-"*30 + "\n"
list_ = ["common_info", "date_time", "dnsmasq_config", "example", list_ = ["common_info", "date_time", "dnsmasq_config", "example",
"local_groups", "local_users", "network", "nss_roles", "local_groups", "local_users", "network", "nss_roles",
...@@ -14,32 +16,84 @@ class TestSettingsdMain(): ...@@ -14,32 +16,84 @@ class TestSettingsdMain():
self.dbus = SystemBus() self.dbus = SystemBus()
self.log_file = open("test_log.log", "w") self.log_file = open("test_log.log", "w")
def test_all(self): def test_interactive(self):
for module_name in list_: for module_name in list_:
#### auto
print("Module name: %s\nWant to run all methods of this module automatically? (y/n)" % module_name)
auto = False
confirmaion = input()
if confirmaion == "y":
auto = True
remote_object = dbus.get_object("org.etersoft.settingsd", "/org/etersoft/settingsd/functions/{}".format(module_name)) remote_object = dbus.get_object("org.etersoft.settingsd", "/org/etersoft/settingsd/functions/{}".format(module_name))
remote_object.Introspect() remote_object.Introspect()
for method_name, args in remote_object.__dict__['_introspect_method_map'].items(): for method_name, args in remote_object.__dict__['_introspect_method_map'].items():
if args != "" and args !=" ": if method_name.rsplit(".", 1)[1] == "Introspect":
print("Test with arguments:", ".".join((method_name.rsplit(".", 3)[1:]))) continue
try: if auto:
if args != "" and args !=" ":
print("Test with arguments:", ".".join((method_name.rsplit(".", 3)[1:])), args)
print( "\nProceed test? (y/n)")
confirmaion = input()
if confirmaion == "y":
print("Argument(%d) types: " % len(args), *args)
print("Enter arguments:\n")
in_args = input().split()
try:
print("Output: ", remote_object.__getattr__(method_name.rsplit(".", 1)[1])(*in_args), SEPARATOR)
except Exception as e:
print(SEPARATOR, str(e), SEPARATOR)
else:
continue
else:
try:
print("Testing: ", ".".join((method_name.rsplit(".", 3)[1:])))
print("Output: ", remote_object.__getattr__(method_name.rsplit(".", 1)[1])(), SEPARATOR)
except Exception as e:
print(SEPARATOR, str(e), SEPARATOR)
else:
print("Testing: ", ".".join((method_name.rsplit(".", 3)[1:])), "\nProceed test? (y/n)") print("Testing: ", ".".join((method_name.rsplit(".", 3)[1:])), "\nProceed test? (y/n)")
confirmaion = input() confirmaion = input()
if confirmaion == "y": if confirmaion == "y":
print("Output: ", remote_object.__getattr__(method_name.rsplit(".", 1)[1])(), sep) if args != "" and args != " ":
pass
try:
print("Output: ", remote_object.__getattr__(method_name.rsplit(".", 1)[1])(), SEPARATOR)
except Exception as e:
print(SEPARATOR, str(e), SEPARATOR)
else: else:
print("Skipped...." + sep) print("Skipped...." + SEPARATOR)
continue
def test_auto(self):
for module_name in list_:
remote_object = dbus.get_object("org.etersoft.settingsd", "/org/etersoft/settingsd/functions/{}".format(module_name))
remote_object.Introspect()
for method_name, args in remote_object.__dict__['_introspect_method_map'].items():
if args != "" and args !=" ":
print("Test with arguments:", ".".join((method_name.rsplit(".", 3)[1:])))
try:
print("Testing: ", ".".join((method_name.rsplit(".", 3)[1:])))
print("Output: ", remote_object.__getattr__(method_name.rsplit(".", 1)[1])(), SEPARATOR)
except Exception as e: except Exception as e:
print(sep, str(e), sep) print(SEPARATOR, str(e), SEPARATOR)
self.log_file.write(sep + str(e) + sep) self.log_file.write(SEPARATOR + str(e) + SEPARATOR)
self.log_file.close() self.log_file.close()
dbus = SystemBus() if __name__ == "__main__":
test_interface = TestSettingsdMain()
if len(sys.argv) > 1:
t = TestSettingsdMain() if sys.argv[1] == "-i" or sys.argv[1] == "--interactive":
t.test_all() test_interface.test_interactive()
elif sys.argv[1] == '-h' or sys.argv[1] == "--help":
print("Usage:\
\n\tpython3 test.py [OPTION]\n \
\n\tOptions:\
\n\t-i, --interactive : Interactive mode (Default: auto mode with skip of argumented methods)\
\n\t-h, --help: Get help\
")
exit(0)
test_interface.test_auto()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment