Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
routersploit
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
czos-dpend
routersploit
Commits
16b1b03b
Commit
16b1b03b
authored
Jan 22, 2017
by
fwkz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing print_table() bug
parent
56067d93
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
5 deletions
+46
-5
test_utils.py
routersploit/test/test_utils.py
+42
-4
__init__.py
routersploit/utils/__init__.py
+4
-1
No files found.
routersploit/test/test_utils.py
View file @
16b1b03b
from
__future__
import
absolute_import
import
unittest
try
:
...
...
@@ -5,8 +7,8 @@ try:
except
ImportError
:
import
mock
from
routersploit.utils
import
index_module
s
from
routersploit.test
import
RoutersploitTestCase
from
..
import
util
s
from
.
import
RoutersploitTestCase
class
UtilsTest
(
RoutersploitTestCase
):
...
...
@@ -19,7 +21,7 @@ class UtilsTest(RoutersploitTestCase):
)
path
=
'path/to/module'
modules
=
index_modules
(
path
)
modules
=
utils
.
index_modules
(
path
)
mock_walk
.
assert_called_once_with
(
path
)
self
.
assertEqual
(
...
...
@@ -39,7 +41,7 @@ class UtilsTest(RoutersploitTestCase):
)
path
=
'path/to/module'
modules
=
index_modules
(
path
)
modules
=
utils
.
index_modules
(
path
)
mock_walk
.
assert_called_once_with
(
path
)
...
...
@@ -52,6 +54,42 @@ class UtilsTest(RoutersploitTestCase):
]
)
@mock.patch
(
'routersploit.utils.print_info'
)
def
test_print_table_01
(
self
,
mock_print
):
utils
.
print_table
(
[
"Name"
,
"Value"
,
"Description"
],
(
'foo'
,
'bar'
,
'baz'
),
(
1
,
2
,
3
),
(
"port"
,
80
,
"port number"
)
)
self
.
assertEqual
(
mock_print
.
mock_calls
,
[
mock
.
call
(),
mock
.
call
(
' Name Value Description '
),
mock
.
call
(
' ---- ----- ----------- '
),
mock
.
call
(
' foo bar baz '
),
mock
.
call
(
' 1 2 3 '
),
mock
.
call
(
' port 80 port number '
),
mock
.
call
()
]
)
@mock.patch
(
'routersploit.utils.print_info'
)
def
test_print_table_02
(
self
,
mock_print
):
utils
.
print_table
(
[
"Name"
,
"Value"
,
"Description"
],
)
self
.
assertEqual
(
mock_print
.
mock_calls
,
[
mock
.
call
(),
mock
.
call
(
' Name Value Description '
),
mock
.
call
(
' ---- ----- ----------- '
),
mock
.
call
()
]
)
if
__name__
==
'__main__'
:
unittest
.
main
()
routersploit/utils/__init__.py
View file @
16b1b03b
...
...
@@ -326,7 +326,10 @@ def print_table(headers, *args, **kwargs):
headers_line
=
' '
headers_separator_line
=
' '
for
idx
,
header
in
enumerate
(
headers
):
current_line_fill
=
max
(
len
(
header
),
*
map
(
lambda
x
:
custom_len
(
x
[
idx
]),
args
))
+
extra_fill
column
=
[
custom_len
(
arg
[
idx
])
for
arg
in
args
]
column
.
append
(
len
(
header
))
current_line_fill
=
max
(
column
)
+
extra_fill
fill
.
append
(
current_line_fill
)
headers_line
=
""
.
join
((
headers_line
,
"{header:<{fill}}"
.
format
(
header
=
header
,
fill
=
current_line_fill
)))
headers_separator_line
=
""
.
join
((
...
...
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