mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-20 23:44:59 +02:00
Go SHM API to read simple data with size from SHM name
This commit is contained in:
30
kitty_tests/shm.py
Normal file
30
kitty_tests/shm.py
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python
|
||||
# License: GPLv3 Copyright: 2023, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from kitty.constants import kitten_exe
|
||||
from kitty.fast_data_types import shm_unlink
|
||||
from kitty.shm import SharedMemory
|
||||
|
||||
from . import BaseTest
|
||||
|
||||
|
||||
class SHMTest(BaseTest):
|
||||
|
||||
def test_shm_with_kitten(self):
|
||||
data = os.urandom(333)
|
||||
with SharedMemory(size=363) as shm:
|
||||
shm.write_data_with_size(data)
|
||||
cp = subprocess.run([kitten_exe(), '__pytest__', 'shm', 'read', shm.name], stdout=subprocess.PIPE)
|
||||
self.assertEqual(cp.returncode, 0)
|
||||
self.assertEqual(cp.stdout, data)
|
||||
self.assertRaises(FileNotFoundError, shm_unlink, shm.name)
|
||||
cp = subprocess.run([kitten_exe(), '__pytest__', 'shm', 'write'], input=data, stdout=subprocess.PIPE)
|
||||
self.assertEqual(cp.returncode, 0)
|
||||
name = cp.stdout.decode().strip()
|
||||
with SharedMemory(name=name, unlink_on_exit=True) as shm:
|
||||
q = shm.read_data_with_size()
|
||||
self.assertEqual(data, q)
|
||||
Reference in New Issue
Block a user