Skip to content
Snippets Groups Projects
Commit e20181f0 authored by ulif's avatar ulif
Browse files

Add a argparser.

parent c48d97d4
No related branches found
No related tags found
No related merge requests found
import argparse
import os
import re
from random import SystemRandom
......@@ -13,6 +14,14 @@ RE_ASCII_CHARS = re.compile('^[a-zA-Z]{2}$')
SPECIAL_CHARS = "~!#$%^&*()-=+[]\{}:;\"'<>?/0123456789"
def handle_options(args):
"""Handle commandline options.
"""
parser = argparse.ArgumentParser(description="Create a passphrase")
args = parser.parse_args(args)
return args
def get_wordlist(path):
"""Parse file at `path` and build a word list of it.
......
import os
import pytest
import sys
from diceware.diceware import (
SRC_DIR, get_wordlist, get_wordlist_path, get_passphrase,
SRC_DIR, get_wordlist, get_wordlist_path, get_passphrase, handle_options,
)
......@@ -53,3 +54,20 @@ class TestDicewareModule(object):
r1 = get_passphrase()
r2 = get_passphrase()
assert r1 != r2
def test_handle_options(self, capsys):
# we can get help
with pytest.raises(SystemExit) as exc_info:
handle_options(['--help'])
assert exc_info.value.code == 0
out, err = capsys.readouterr()
out = out.replace(
os.path.basename(sys.argv[0]), 'diceware')
assert out == (
'usage: diceware [-h]\n'
'\n'
'Create a passphrase\n'
'\n'
'optional arguments:\n'
' -h, --help show this help message and exit\n'
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment