Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
diceware-debian
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drebs
diceware-debian
Commits
a01755af
Commit
a01755af
authored
9 years ago
by
ulif
Browse files
Options
Downloads
Patches
Plain Diff
Add -r/--randomsource option.
The new option is not active yet.
parent
a1580b35
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
diceware/__init__.py
+7
-0
7 additions, 0 deletions
diceware/__init__.py
tests/exp_help_output.txt
+4
-1
4 additions, 1 deletion
tests/exp_help_output.txt
tests/test_diceware.py
+18
-0
18 additions, 0 deletions
tests/test_diceware.py
with
29 additions
and
1 deletion
diceware/__init__.py
+
7
−
0
View file @
a01755af
...
...
@@ -86,6 +86,7 @@ def get_random_sources():
def
handle_options
(
args
):
"""
Handle commandline options.
"""
random_sources
=
get_random_sources
().
keys
()
parser
=
argparse
.
ArgumentParser
(
description
=
"
Create a passphrase
"
)
parser
.
add_argument
(
'
-n
'
,
'
--num
'
,
default
=
6
,
type
=
int
,
...
...
@@ -103,6 +104,12 @@ def handle_options(args):
parser
.
add_argument
(
'
-d
'
,
'
--delimiter
'
,
default
=
''
,
help
=
"
Separate words by DELIMITER. Empty string by default.
"
)
parser
.
add_argument
(
'
-r
'
,
'
--randomsource
'
,
default
=
'
system
'
,
choices
=
random_sources
,
metavar
=
"
SOURCE
"
,
help
=
(
"
Get randomness from this source. Possible values: `%s
'
.
"
"
Default: system
"
%
"'
, `
"
.
join
(
random_sources
)))
parser
.
add_argument
(
'
infile
'
,
nargs
=
'
?
'
,
metavar
=
'
INFILE
'
,
default
=
None
,
type
=
argparse
.
FileType
(
'
r
'
),
...
...
This diff is collapsed.
Click to expand it.
tests/exp_help_output.txt
+
4
−
1
View file @
a01755af
usage: diceware [-h] [-n NUM] [-c | --no-caps] [-s NUM] [-d DELIMITER]
[--version]
[-r SOURCE]
[--version]
[INFILE]
Create a passphrase
...
...
@@ -16,4 +16,7 @@ optional arguments:
Insert NUM special chars into generated word.
-d DELIMITER, --delimiter DELIMITER
Separate words by DELIMITER. Empty string by default.
-r SOURCE, --randomsource SOURCE
Get randomness from this source. Possible values:
`system'. Default: system
--version output version information and exit.
This diff is collapsed.
Click to expand it.
tests/test_diceware.py
+
18
−
0
View file @
a01755af
...
...
@@ -211,6 +211,7 @@ class TestDicewareModule(object):
assert
options
.
infile
is
None
assert
options
.
version
is
False
assert
options
.
delimiter
==
""
assert
options
.
randomsource
==
"
system
"
def
test_handle_options_infile
(
self
,
tmpdir
):
# we can give an infile
...
...
@@ -235,6 +236,23 @@ class TestDicewareModule(object):
options
=
handle_options
([
'
-d
'
,
'
WOW
'
])
assert
options
.
delimiter
==
'
WOW
'
def
test_handle_options_randomsource
(
self
):
# we can choose the source of randomness
source_names
=
get_random_sources
().
keys
()
for
name
in
source_names
:
options
=
handle_options
([
'
-r
'
,
name
])
assert
options
.
randomsource
==
name
options
=
handle_options
([
'
--randomsource
'
,
name
])
assert
options
.
randomsource
==
name
def
test_handle_options_randomsource_rejects_invalid
(
self
,
capsys
):
# we can not choose illegal values for source of randomness
with
pytest
.
raises
(
SystemExit
):
handle_options
([
'
-r
'
,
'
not-a-valid-source-name
'
])
out
,
err
=
capsys
.
readouterr
()
assert
out
==
''
assert
"
invalid choice
"
in
err
def
test_main
(
self
,
capsys
):
# we can get a passphrase
main
([])
# call with default options in place
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment