Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nejucomo.add-partial-test-coverage-to-passphrase #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions pyutil/test/current/test_passphrase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8-with-signature-unix; fill-column: 77 -*-
# -*- indent-tabs-mode: nil -*-

# This file is part of pyutil; see README.rst for licensing terms.

import unittest
from cStringIO import StringIO

from mock import patch, call, ANY

from pyutil.scripts import passphrase


class Passphrase(unittest.TestCase):

@patch('argparse.ArgumentParser')
@patch('pyutil.scripts.passphrase.gen_passphrase')
@patch('sys.stdout')
def test_main(self, m_stdout, m_gen_passphrase, m_ArgumentParser):
m_args = m_ArgumentParser.return_value.parse_args.return_value
m_args.dictionary = StringIO('alpha\nbeta\n')
m_args.bits = 42

m_gen_passphrase.return_value = ('wombat', 43)

passphrase.main()

self.assertEqual(
m_ArgumentParser.mock_calls,
[call(
prog='passphrase',
description=('Create a random passphrase by ' +
'picking a few random words.')),
call().add_argument(
'-d',
'--dictionary',
help=('what file to read a list of words from ' +
"(or omit this option to use passphrase's " +
'bundled dictionary)'),
type=ANY,
metavar="DICT"),
call().add_argument(
'bits',
help="how many bits of entropy minimum",
type=float,
metavar="BITS"),
call().parse_args()])

self.assertEqual(
m_gen_passphrase.mock_calls,
[call(42, {u'alpha', u'beta'})])

self.assertEqual(
m_stdout.mock_calls,
[call.write(u"Your new password is: 'wombat'. " +
"It is worth about 43 bits."),
call.write('\n')])
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
(os.path.join(u'pyutil', u'data'), [os.path.join(u'pyutil', u'data', u'wordlist.txt')])
]

install_requires=[u'zbase32 >= 1.0']
install_requires = [
u'zbase32 >= 1.0',
u'simplejson >= 2.1.0',
]

readmetext_bytes = open(u'README.rst').read()
readmetext_unicode = readmetext_bytes.decode('utf-8')
Expand All @@ -68,6 +71,10 @@
data_files=data_files,
extras_require={u'jsonutil': [u'simplejson >= 2.1.0',]},
install_requires=install_requires,
tests_require=[
u'twisted >= 15.5.0', # for trial (eg user: test_observer)
u'mock >= 1.3.0',
],
classifiers=trove_classifiers,
entry_points = {
u'console_scripts': [
Expand Down