Skip to content

Commit

Permalink
Move imports to the top and lint a bit in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HacKanCuBa committed Sep 23, 2018
1 parent 3b5bb1c commit b1ff574
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
12 changes: 2 additions & 10 deletions passphrase/tests/tests_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#
# ***************************************************************************

from string import digits, punctuation, ascii_lowercase, ascii_uppercase
from unittest import TestCase

import passphrase.calc
Expand Down Expand Up @@ -52,9 +53,7 @@ def test_entropy_bits_nrange(self):
self.assertAlmostEqual(bits, val[2], places=2)

def test_password_length_needed(self):
from string import digits, ascii_letters, punctuation

chars = digits + ascii_letters + punctuation
chars = digits + ascii_lowercase + ascii_uppercase + punctuation
values = (
(52, 8),
(53, 9),
Expand Down Expand Up @@ -84,13 +83,6 @@ def test_words_amount_needed(self):
self.assertEqual(result, val[4])

def test_password_entropy(self):
from string import (
digits,
ascii_lowercase,
ascii_uppercase,
punctuation
)

values = (
(0, digits, 0.0),
(10, ascii_lowercase + ascii_uppercase, 57.00),
Expand Down
8 changes: 2 additions & 6 deletions passphrase/tests/tests_passphrase.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,9 @@ def test_generate_uuid4(self):

def test_import_words_from_file(self):
passp = Passphrase()

ret = passp.import_words_from_file(self.words_file, False)
self.assertIsNone(ret)
self.assertIsNone(passp.import_words_from_file(self.words_file, False))
self.assertEqual(passp.wordlist, constants.WORDS)

ret = passp.import_words_from_file(self.wordsd_file, True)
self.assertIsNone(ret)
self.assertIsNone(passp.import_words_from_file(self.wordsd_file, True))
self.assertEqual(
passp.wordlist,
[word.split()[1] for word in constants.WORDSD]
Expand Down
2 changes: 1 addition & 1 deletion passphrase/tests/tests_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_randbytes_subprocess(self, count):
'import sys',
'import importlib.util',
'spec = importlib.util.spec_from_file_location'
'("passphrase.random", "%s")' % (random_module_path),
'("passphrase.random", "%s")' % random_module_path,
'random = importlib.util.module_from_spec(spec)',
'spec.loader.exec_module(random)',
'data = random.randbytes(%s)' % count,
Expand Down
5 changes: 2 additions & 3 deletions passphrase/tests/tests_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# ***************************************************************************

from unittest import TestCase
from string import hexdigits

import passphrase.secrets
import passphrase.tests.constants as constants
Expand Down Expand Up @@ -48,7 +49,7 @@ def test_randbelow(self):
repeat += 1
self.assertTrue(
repeat < 2,
'randbelow(%d) returned the same number twice in a row!' % (i)
'randbelow(%d) returned the same number twice in a row!' % i
)
prev = rand

Expand All @@ -61,8 +62,6 @@ def test_randbetween(self):
lower = upper

def test_randhex(self):
from string import hexdigits

for i in (1, 10, 100):
rand = passphrase.secrets.randhex(i)
self.assertIsInstance(rand, str)
Expand Down

0 comments on commit b1ff574

Please sign in to comment.