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
e144f582
Commit
e144f582
authored
Apr 20, 2017
by
Mariusz Kupidura
Committed by
Marcin Bury
Apr 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integer validator (#235)
* Add ability to cast Option's value to integer * Fix formatting.
parent
416a7661
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
test_validators.py
routersploit/test/test_validators.py
+10
-0
validators.py
routersploit/validators.py
+8
-0
No files found.
routersploit/test/test_validators.py
View file @
e144f582
...
@@ -136,6 +136,16 @@ class ValidatorsTest(RoutersploitTestCase):
...
@@ -136,6 +136,16 @@ class ValidatorsTest(RoutersploitTestCase):
value
=
"t"
value
=
"t"
self
.
assertEqual
(
validators
.
boolify
(
value
),
True
)
self
.
assertEqual
(
validators
.
boolify
(
value
),
True
)
def
test_integer_1
(
self
):
self
.
assertEqual
(
validators
.
integer
(
'1'
),
1
)
def
test_integer_2
(
self
):
self
.
assertEqual
(
validators
.
integer
(
'123'
),
123
)
def
test_integer_3
(
self
):
with
self
.
assertRaises
(
OptionValidationError
):
validators
.
integer
(
'foobar'
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
routersploit/validators.py
View file @
e144f582
...
@@ -55,3 +55,11 @@ def boolify(value):
...
@@ -55,3 +55,11 @@ def boolify(value):
return
False
return
False
else
:
else
:
return
bool
(
value
)
return
bool
(
value
)
def
integer
(
number
):
""" Cast Option value to the integer using int() """
try
:
return
int
(
number
)
except
ValueError
:
raise
OptionValidationError
(
"Invalid option. can't cast '{}' to integer."
.
format
(
number
))
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