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 1 commit
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
Prev Previous commit
Next Next commit
Add a mock-based passphrase main() test. It fails due to test bug, no…
…t app bug...
  • Loading branch information
nejucomo committed Jan 3, 2016
commit 9c642d26cbab782c80da3bf1efd523b09d5e2100
63 changes: 63 additions & 0 deletions pyutil/test/current/test_passphrase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- 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
import argparse
from cStringIO import StringIO

from mock import patch, call

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.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=argparse.FileType('rU'),
metavar="DICT"),
call().add_argument(
'bits',
help="how many bits of entropy minimum",
type=float,
metavar="BITS"),
call().parse_args(),

# BUG: Can we remove this layer of specificity?
# Why doesn't m_args remove this layer of specificity?
call().parse_args().__nonzero__(),
call().parse_args().readlines(),
call().parse_args().readlines().__iter__()])

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 42 bits.\n")])
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
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 = {
Expand Down