Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
cef6ac35
Commit
cef6ac35
authored
Apr 24, 2019
by
Никита Ефремов
Committed by
Nick Yefremov
May 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgraded testing utility
parent
37b92264
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
15 deletions
+69
-15
test.py
test.py
+69
-15
No files found.
test.py
View file @
cef6ac35
from
unittest
import
TestCase
,
main
from
pprint
import
pprint
as
pp
from
dbus
import
SystemBus
import
os
,
sys
sep
=
"
\n
"
+
"-"
*
30
+
"
\n
"
SEPARATOR
=
"
\n
"
+
"-"
*
30
+
"
\n
"
list_
=
[
"common_info"
,
"date_time"
,
"dnsmasq_config"
,
"example"
,
"local_groups"
,
"local_users"
,
"network"
,
"nss_roles"
,
...
...
@@ -14,32 +16,84 @@ class TestSettingsdMain():
self
.
dbus
=
SystemBus
()
self
.
log_file
=
open
(
"test_log.log"
,
"w"
)
def
test_
all
(
self
):
def
test_
interactive
(
self
):
for
module_name
in
list_
:
#### auto
print
(
"Module name:
%
s
\n
Want 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
.
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
:
if
method_name
.
rsplit
(
"."
,
1
)[
1
]
==
"Introspect"
:
continue
if
auto
:
if
args
!=
""
and
args
!=
" "
:
print
(
"Test with arguments:"
,
"."
.
join
((
method_name
.
rsplit
(
"."
,
3
)[
1
:])),
args
)
print
(
"
\n
Proceed 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
:])),
"
\n
Proceed test? (y/n)"
)
confirmaion
=
input
()
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
:
print
(
"Skipped...."
+
sep
)
continue
print
(
"Skipped...."
+
SEPARATOR
)
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
:
print
(
sep
,
str
(
e
),
sep
)
self
.
log_file
.
write
(
sep
+
str
(
e
)
+
sep
)
print
(
SEPARATOR
,
str
(
e
),
SEPARATOR
)
self
.
log_file
.
write
(
SEPARATOR
+
str
(
e
)
+
SEPARATOR
)
self
.
log_file
.
close
()
dbus
=
SystemBus
()
t
=
TestSettingsdMain
()
t
.
test_all
()
if
__name__
==
"__main__"
:
test_interface
=
TestSettingsdMain
()
if
len
(
sys
.
argv
)
>
1
:
if
sys
.
argv
[
1
]
==
"-i"
or
sys
.
argv
[
1
]
==
"--interactive"
:
test_interface
.
test_interactive
()
elif
sys
.
argv
[
1
]
==
'-h'
or
sys
.
argv
[
1
]
==
"--help"
:
print
(
"Usage:
\
\n\t
python3 test.py [OPTION]
\n
\
\n\t
Options:
\
\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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment