Exemplo n.º 1
0
    def SetUp(self):
        self.StartPatch('fcntl.fcntl', autospec=True)
        self.StartPatch('sys.stdin', autospec=True)
        self.StartPatch('time.sleep', autospec=True)
        if six.PY2:
            self.stdin_mock = sys.stdin
        else:
            self.stdin_mock = sys.stdin.buffer

        self.sock = iap_tunnel._StdinSocket()
Exemplo n.º 2
0
 def testFlush(self):
     # Autospeccing sys.stdout should work, but Kokoro sets --capture=fd which
     # causes sys.stdout to be replaced with something that autospec can't handle
     # correctly.
     # This autospec makes sys.stdout look like python3, but that still works
     # well enough in python2 for the purpose of this test.
     self.StartPatch('sys.stdout',
                     autospec=io.TextIOWrapper(io.BufferedIOBase()))
     sock = iap_tunnel._StdinSocket()
     sock.send(b'data1')
     sock.send(b'a\na\0a\xffa')
     if six.PY2:
         self.assertEqual(sys.stdout.flush.call_count, 2)
     else:
         self.assertEqual(sys.stdout.buffer.flush.call_count, 2)
Exemplo n.º 3
0
    def SetUp(self):
        self.StartPatch('ctypes.windll.kernel32.GetStdHandle', autospec=True)
        self.StartPatch('ctypes.windll.kernel32.ReadFile', autospec=True)

        ctypes.windll.kernel32.GetStdHandle.return_value = self.STDIN_HANDLE
        self.sock = iap_tunnel._StdinSocket()
Exemplo n.º 4
0
 def testClose(self):
     sock = iap_tunnel._StdinSocket()
     sock.close()
Exemplo n.º 5
0
 def testSend(self):
     sock = iap_tunnel._StdinSocket()
     self.assertEqual(sock.send(b'data1'), 5)
     self.assertEqual(sock.send(b'a\na\0a\xffa'), 7)
     self.assertEqual(self.GetOutputBytes(), b'data1a\na\0a\xffa')