def test_write_file_wrong_args(self, args): """ `OpenSSL.rand.write_file` raises `TypeError` when called with a non-`str` argument. """ with pytest.raises(TypeError): rand.write_file(*args)
def test_files(self): """ Test reading and writing of files via rand functions. """ # Write random bytes to a file tmpfile = self.mktemp() # Make sure it exists (so cleanup definitely succeeds) fObj = file(tmpfile, 'w') fObj.close() try: rand.write_file(tmpfile) # Verify length of written file size = os.stat(tmpfile)[stat.ST_SIZE] self.assertEquals(size, 1024) # Read random bytes from file rand.load_file(tmpfile) rand.load_file(tmpfile, 4) # specify a length finally: # Cleanup os.unlink(tmpfile)
def test_files(self): """ Test reading and writing of files via rand functions. """ # Write random bytes to a file tmpfile = self.mktemp() # Make sure it exists (so cleanup definitely succeeds) fObj = open(tmpfile, 'w') fObj.close() try: rand.write_file(tmpfile) # Verify length of written file size = os.stat(tmpfile)[stat.ST_SIZE] self.assertEqual(1024, size) # Read random bytes from file rand.load_file(tmpfile) rand.load_file(tmpfile, 4) # specify a length finally: # Cleanup os.unlink(tmpfile)
def _read_write_test(self, path): """ Verify that ``rand.write_file`` and ``rand.load_file`` can be used. """ # Create the file so cleanup is more straightforward with open(path, "w"): pass try: # Write random bytes to a file rand.write_file(path) # Verify length of written file size = os.stat(path)[stat.ST_SIZE] self.assertEqual(1024, size) # Read random bytes from file rand.load_file(path) rand.load_file(path, 4) # specify a length finally: # Cleanup os.unlink(path)
def _read_write_test(self, path): """ Verify that ``rand.write_file`` and ``rand.load_file`` can be used. """ # Create the file so cleanup is more straightforward with open(path, "w"): pass try: # Write random bytes to a file rand.write_file(path) # Verify length of written file size = os.stat(path)[stat.ST_SIZE] assert size == 1024 # Read random bytes from file rand.load_file(path) rand.load_file(path, 4) # specify a length finally: # Cleanup os.unlink(path)