shm.py 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python
  2. # License: GPLv3 Copyright: 2023, Kovid Goyal <kovid at kovidgoyal.net>
  3. import os
  4. import subprocess
  5. from kitty.constants import kitten_exe
  6. from kitty.fast_data_types import shm_unlink
  7. from kitty.shm import SharedMemory
  8. from . import BaseTest
  9. class SHMTest(BaseTest):
  10. def test_shm_with_kitten(self):
  11. data = os.urandom(333)
  12. with SharedMemory(size=363) as shm:
  13. shm.write_data_with_size(data)
  14. cp = subprocess.run([kitten_exe(), '__pytest__', 'shm', 'read', shm.name], stdout=subprocess.PIPE)
  15. self.assertEqual(cp.returncode, 0)
  16. self.assertEqual(cp.stdout, data)
  17. self.assertRaises(FileNotFoundError, shm_unlink, shm.name)
  18. cp = subprocess.run([kitten_exe(), '__pytest__', 'shm', 'write'], input=data, stdout=subprocess.PIPE)
  19. self.assertEqual(cp.returncode, 0)
  20. name = cp.stdout.decode().strip()
  21. with SharedMemory(name=name, unlink_on_exit=True) as shm:
  22. q = shm.read_data_with_size()
  23. self.assertEqual(data, q)