def test_create(self, mock_kernel32): mock_kernel32.CreateNamedPipeW.return_value = NamedPipeWindows.INVALID_HANDLE_VALUE mock_kernel32.GetLastError.return_value = 12345 with self.assertRaises(OSError) as cm: NamedPipeWindows() self.assertEqual(str(cm.exception), "Named pipe error code 0x00003039") self.assertEqual(mock_kernel32.CreateNamedPipeW.call_args[0][1:], (0x00000002, 0x00000000, 255, 8192, 8192, 0, None))
def test_named_pipe(self): pipe = NamedPipeWindows() reader = ReadNamedPipeThreadWindows(pipe) reader.start() pipe.open() self.assertEqual(pipe.write(b"foo"), 3) self.assertEqual(pipe.write(b"bar"), 3) self.assertEqual(pipe.write(b"\0"), 1) reader.done.wait(4000) self.assertEqual(reader.error, None) self.assertEqual(reader.data, b"foobar") self.assertFalse(reader.is_alive()) pipe.close()
def test_close_before_open(self): pipe = NamedPipeWindows() handle = windll.kernel32.CreateFileW(str(pipe.path), GENERIC_READ, 0, None, OPEN_EXISTING, 0, None) self.assertNotEqual(handle, NamedPipeWindows.INVALID_HANDLE_VALUE) windll.kernel32.CloseHandle(handle) pipe.close() handle = windll.kernel32.CreateFileW(str(pipe.path), GENERIC_READ, 0, None, OPEN_EXISTING, 0, None) self.assertEqual(handle, NamedPipeWindows.INVALID_HANDLE_VALUE) # closing twice doesn't raise pipe.close()