def test_write_to_socket(self):
     reader = SocketThread()
     reader.start()
     reader.wait_until_ready()
     self.assertEquals(0, patchviasocket.send_to_socket(reader.file(), self._key_file, CMD_DATA))
     reader.join()
     data = reader.data()
     self.assertIn(KEY_DATA, data)
     self.assertIn(CMD_DATA.replace("%", " "), data)
     self.assertNotIn("LUV", data)
     self.assertNotIn("very%quickly", data)  # Testing substitution
 def test_nonexistant_socket_error(self):
     reader = SocketThread()
     reader.start()
     reader.wait_until_ready()
     self.assertEquals(1, patchviasocket.send_to_socket(NON_EXISTING_FILE, self._key_file, CMD_DATA))
     reader.join()   # timeout
 def test_access_denied_socket_error(self):
     reader = SocketThread()
     reader.start()
     reader.wait_until_ready()
     self.assertEquals(1, patchviasocket.send_to_socket(self._unreadable, self._key_file, CMD_DATA))
     reader.join()   # timeout
 def test_host_key_error(self):
     reader = SocketThread()
     reader.start()
     reader.wait_until_ready()
     self.assertEquals(1, patchviasocket.send_to_socket(reader.file(), NON_EXISTING_FILE, CMD_DATA))
     reader.join()   # timeout