test_rpoolcompat.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. #
  3. # SelfTest/Util/test_winrandom.py: Self-test for the winrandom module
  4. #
  5. # Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>
  6. #
  7. # ===================================================================
  8. # The contents of this file are dedicated to the public domain. To
  9. # the extent that dedication to the public domain is not available,
  10. # everyone is granted a worldwide, perpetual, royalty-free,
  11. # non-exclusive license to exercise all rights associated with the
  12. # contents of this file for any purpose whatsoever.
  13. # No rights are reserved.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. # SOFTWARE.
  23. # ===================================================================
  24. """Self-test for the Crypto.Util.randpool.RandomPool wrapper class"""
  25. __revision__ = "$Id$"
  26. import sys
  27. import unittest
  28. class SimpleTest(unittest.TestCase):
  29. def runTest(self):
  30. """Crypto.Util.randpool.RandomPool"""
  31. # Import the winrandom module and try to use it
  32. from Crypto.Util.randpool import RandomPool
  33. sys.stderr.write("SelfTest: You can ignore the RandomPool_DeprecationWarning that follows.\n")
  34. rpool = RandomPool()
  35. x = rpool.get_bytes(16)
  36. y = rpool.get_bytes(16)
  37. self.assertNotEqual(x, y)
  38. self.assertNotEqual(rpool.entropy, 0)
  39. rpool.randomize()
  40. rpool.stir('foo')
  41. rpool.add_event('foo')
  42. def get_tests(config={}):
  43. return [SimpleTest()]
  44. if __name__ == '__main__':
  45. suite = lambda: unittest.TestSuite(get_tests())
  46. unittest.main(defaultTest='suite')
  47. # vim:set ts=4 sw=4 sts=4 expandtab: