Added more tests, made tests more reliable.

This commit is contained in:
Nick Daly 2012-05-01 07:46:43 -05:00
parent 832185338b
commit d499ea794c
2 changed files with 33 additions and 13 deletions

View File

@ -194,3 +194,6 @@ class Unwrapper(object):
return "\n".join([ return "\n".join([
"\n".join(x) for x in (self.start, self.header, self.body, "\n".join(x) for x in (self.start, self.header, self.body,
self.footer, self.end) ]) self.footer, self.end) ])
if __name__ == "__main__":
unittest.main()

View File

@ -8,13 +8,17 @@ can be no trustworthy trust.
""" """
from pprint import pprint import sys
sys.path.extend(["../..", ".", "/home/nick/programs/python-gnupg/python-gnupg-0.2.9"])
from pprint import pprint
import ConfigParser as configparser import ConfigParser as configparser
import gnupg import gnupg
import pgpprocessor import pgpprocessor
import unittest import unittest
ITERATIONS = 3
class ProcessorCase(unittest.TestCase): class ProcessorCase(unittest.TestCase):
"""The superclass for pgpprocessor tests, containing shared setup: """The superclass for pgpprocessor tests, containing shared setup:
@ -29,7 +33,7 @@ class ProcessorCase(unittest.TestCase):
KEYID = CONFIG.get("pgpprocessor", "keyid") KEYID = CONFIG.get("pgpprocessor", "keyid")
# sign the message a few times. # sign the message a few times.
for i in range(0, 3): for i in range(ITERATIONS):
MESSAGES.append(str(GPG.sign(MESSAGES[i], keyid = KEYID))) MESSAGES.append(str(GPG.sign(MESSAGES[i], keyid = KEYID)))
class UnwrapperTest(ProcessorCase): class UnwrapperTest(ProcessorCase):
@ -41,6 +45,16 @@ class UnwrapperTest(ProcessorCase):
self.unwrapper = pgpprocessor.Unwrapper(self.messages[-1], self.unwrapper = pgpprocessor.Unwrapper(self.messages[-1],
ProcessorCase.GPG) ProcessorCase.GPG)
def test_messages_wrapped(self):
"""Were the messages correctly wrapped in the first place?"""
self.assertEqual(len(self.messages), ITERATIONS + 1)
def test_unwrap_all_messages(self):
"""Do we actually hit all the messages?"""
self.assertEqual(len([self.unwrapper]), ITERATIONS + 1)
def test_creating_message_doesnt_unwrap(self): def test_creating_message_doesnt_unwrap(self):
"""Creating an unwrapper shouldn't unwrap the message. """Creating an unwrapper shouldn't unwrap the message.
@ -54,15 +68,18 @@ class UnwrapperTest(ProcessorCase):
def test_iterator_unwraps_correctly(self): def test_iterator_unwraps_correctly(self):
"""The iterator should correctly unwrap each stage of the message.""" """The iterator should correctly unwrap each stage of the message."""
for i, message in enumerate(self.unwrapper): for i, message in enumerate(self.messages):
self.assertEqual(message, self.messages[-i-2]) unwrapped = self.unwrapper.next()
self.assertEqual(message, unwrapped)
def test_original_message(self): def test_original_message(self):
"""Unwrapper.original_message actually returns the original message.""" """Unwrapper.original_message actually returns the original message."""
print (self.unwrapper.message) for i, message in enumerate(self.messages):
self.assertEqual(self.unwrapper.next(), self.messages[-1]) unwrapped = self.unwrapper.next()
self.assertEqual(self.unwrapper.original_message(), message)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()