File: shm.py

package info (click to toggle)
kitty 0.42.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 28,564 kB
  • sloc: ansic: 82,787; python: 55,191; objc: 5,122; sh: 1,295; xml: 364; makefile: 143; javascript: 78
file content (30 lines) | stat: -rw-r--r-- 1,066 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)