added unit tests
authorSteven Tobin <steventtobin (at) gmail.com>
Thu, 13 Jun 2013 10:35:47 +0000 (11:35 +0100)
committerSteven Tobin <steventtobin (at) gmail.com>
Thu, 13 Jun 2013 10:35:47 +0000 (11:35 +0100)
test_list.txt [new file with mode: 0644]
tests/xkcdp_tests.py [new file with mode: 0644]

diff --git a/test_list.txt b/test_list.txt
new file mode 100644 (file)
index 0000000..c1b2c65
--- /dev/null
@@ -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 (file)
index 0000000..ea1c9ef
--- /dev/null
@@ -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)
git clone https://git.99rst.org/PROJECT