From: Steven Tobin Date: Thu, 13 Jun 2013 10:35:47 +0000 (+0100) Subject: added unit tests X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=37f4a4d553703666d0f2347c9967f175ba34d1c7;p=redacted-XKCD-password-generator.git added unit tests --- diff --git a/test_list.txt b/test_list.txt new file mode 100644 index 0000000..c1b2c65 --- /dev/null +++ b/test_list.txt @@ -0,0 +1,7 @@ +factual +captain +capricious +__$$$__ +amazing +exactly +define \ No newline at end of file diff --git a/tests/xkcdp_tests.py b/tests/xkcdp_tests.py new file mode 100644 index 0000000..ea1c9ef --- /dev/null +++ b/tests/xkcdp_tests.py @@ -0,0 +1,37 @@ +import unittest +import subprocess +import xkcd_password + + +class XkcdPasswordTests(unittest.TestCase): + def setUp(self): + self.wordlist_full = xkcd_password.generate_wordlist( + wordfile='3esl.txt', + min_length=5, + max_length=8,) + self.wordlist_small = xkcd_password.generate_wordlist( + wordfile='test_list.txt', + valid_chars='[a-z]') + + def test_loadwordfile(self): + self.assertEquals(len(self.wordlist_full), 10730) + + def test_regex(self): + self.assertNotIn("__$$$__", self.wordlist_small) + + def test_acrostic(self): + target = ["factual", "amazing", "captain", "exactly"] + result = xkcd_password.generate_xkcdpassword( + self.wordlist_small, + acrostic="face") + self.assertEquals(result.split(), target) + + def test_commandlineCount(self): + count = 5 + result = subprocess.check_output( + ["python", "xkcd_password.py", "-w", "3esl.txt", "-c", str(count)]) + self.assertTrue(result.count("\n"), count) + +if __name__ == '__main__': + suite = unittest.TestLoader().loadTestsFromTestCase(XkcdPasswordTests) + unittest.TextTestRunner(verbosity=2).run(suite)