From: Morgan R. <mor...@gm...> - 2008-10-17 13:07:37
|
I've started writing unit tests for my additions now, I've got an issue though, I've updated test_crypto.py changes summarised below; ================================================ from OpenSSL.crypto import RSA, RSAType ... class RSATests(TestCase, _Python23TestCaseHelper): def test_construction(self): """ L{RSA} takes no arguments and returns an instance of L{RSAType}. """ rsaobj = RSA() self.assertTrue( isinstance(rsaobj, RSAType), "%r is of type %r, should be %r" % (rsaobj, type(rsaobj), RSAType)) def test_generate_key(self): """ L{generate_key} generates a new RSA key the given size and stores it in the internal structure """ bits = 1024 rsaobj = RSA() rsaobj.generate_key(bits) self.assertEqual(rsaobj.key_bits(), bits) ================================================ When I execute the tests only test_construction is being executed (or it's the only one appearing in the log), is there anything I need to do besides defining the test method in the test class? (apologies for the basic questions, I've never done automated unit testing in python before) Thanks, Morgan |
From: Jean-Paul C. <ex...@di...> - 2008-10-17 13:34:14
|
On Sat, 18 Oct 2008 00:07:29 +1100, Morgan Reed <mor...@gm...> wrote: >I've started writing unit tests for my additions now, I've got an >issue though, I've updated test_crypto.py changes summarised below; > >================================================ > >from OpenSSL.crypto import RSA, RSAType > >... > >class RSATests(TestCase, _Python23TestCaseHelper): > > def test_construction(self): > """ > L{RSA} takes no arguments and returns an instance of L{RSAType}. > """ > rsaobj = RSA() > self.assertTrue( > isinstance(rsaobj, RSAType), > "%r is of type %r, should be %r" % (rsaobj, > type(rsaobj), > RSAType)) > > def test_generate_key(self): > """ > L{generate_key} generates a new RSA key the given size and stores it in > the internal structure > """ > bits = 1024 > rsaobj = RSA() > rsaobj.generate_key(bits) > self.assertEqual(rsaobj.key_bits(), bits) > >================================================ > >When I execute the tests only test_construction is being executed (or >it's the only one appearing in the log), is there anything I need to >do besides defining the test method in the test class? (apologies for >the basic questions, I've never done automated unit testing in python >before) > The code you included looks right. I would certainly expect two tests to be run, test_construction and test_generate_key, if I ran a command like "trial OpenSSL.test.test_crypto.RSATests", after doing the needed song and dance to get the code and tests into a state where they could be imported. Jean-Paul |
From: Morgan R. <mor...@gm...> - 2008-10-18 08:47:47
|
On Sat, Oct 18, 2008 at 12:33 AM, Jean-Paul Calderone <ex...@di...> wrote: > The code you included looks right. I would certainly expect two tests > to be run, test_construction and test_generate_key, if I ran a command > like "trial OpenSSL.test.test_crypto.RSATests", after doing the needed > song and dance to get the code and tests into a state where they could > be imported. Still no joy, I've written a couple of further tests and none of them are running (except test_construction as previously). ======================== ..... testPlaintext = "testing" ..... class RSATests(TestCase, _Python23TestCaseHelper): ..... def test_public_encrypt(self): """ L{public_encrypt} generates a new key and encrypts a static value with the public key, then decrypts it with the private and compare the result """ bits = 1024 rsaobj = RSA() rsaobj.generate_key(bits) crypt = rsaobj.public_encrypt(testPlaintext) decrypt = rsaobj.private_decrypt(crypt) self.assertEqual(decrypt, testPlaintext) def test_private_encrypt(self): """ L{private_encrypt} generates a new key and encrypts a static value with the private key, then decrypts it with the public and compares the result """ bits = 1024 rsaobj = RSA() rsaobj.generate_key(bits) crypt = rsaobj.private_encrypt(testPlaintext) decrypt = rsaobj.public_decrypt(crypt) self.assertEqual(decrypt, testPlaintext) ======================== This is the script I'm using to execute the tests ======================== #!/bin/sh python setup.py install --prefix=/tmp/pyOpenSSL-test PYTHONPATH=/tmp/pyOpenSSL-test/lib/python2.5/site-packages/:$PYTHONPATH python -c 'import OpenSSL; print OpenSSL' PYTHONPATH=/tmp/pyOpenSSL-test/lib/python2.5/site-packages/:$PYTHONPATH trial OpenSSL ======================== And the output ======================== ..... test_rsaGeneration ... [OK] RSATests test_construction ... [OK] X509NameTests ..... ======================== Any suggestions would be greatly appreciated, I've pushed the latest revision if anybody wants to look at the code in situ Thanks, Morgan |