Re: [Pyunit-interest] More testing aid requested
Brought to you by:
purcell
From: Michal W. <sa...@ma...> - 2001-12-03 10:48:52
|
On Sun, 2 Dec 2001, Jesse W wrote: > files anywhere. How do I make a test that requires the > module to actually _send_ the files instead of simply > faking it as my class now does? (code enclosed below) > Thank you all for your time and answers, Hey Jesse, try it this way: ############### class Connection: def __init__(self, sender): self.sender = sender def send_file(self, file): self.sender.send(file) class MockSender: def __init__(self): self.files_sent=[] def send(self, file): self.files_sent.append(file) class ConnectionTestCase(unittest.TestCase): def testFileSent(self): s = MockSender() c = Connection (s) c.send_file(TEST_FILE) assert TEST_FILE in s.files_sent[], 'TEST_FILE not found in listfiles return value!' ########## See how you can now pass in a RealSender instance with a real send() method? Cheers, - Michal http://www.sabren.net/ sa...@ma... ------------------------------------------------------------ Give your ideas the perfect home: http://www.cornerhost.com/ cvs - weblogs - php - linux shell - perl/python/cgi - java ------------------------------------------------------------ |