# Path: tests/base_test.py
# class SSH2TestCase(unittest.TestCase):
# 
#     @classmethod
#     def setUpClass(cls):
#         _mask = int('0600') if version_info <= (2,) else 0o600
#         os.chmod(PKEY_FILENAME, _mask)
#         cls.server = OpenSSHServer()
#         cls.server.start_server()
# 
#     @classmethod
#     def tearDownClass(cls):
#         cls.server.stop()
#         del cls.server
# 
#     def setUp(self):
#         self.host = '127.0.0.1'
#         self.port = 2222
#         self.cmd = 'echo me'
#         self.resp = u'me'
#         self.user_key = PKEY_FILENAME
#         self.user_pub_key = PUB_FILE
#         self.user = pwd.getpwuid(os.geteuid()).pw_name
#         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#         sock.connect((self.host, self.port))
#         self.sock = sock
#         self.session = Session()
#         self.session.handshake(self.sock)
# 
#     def tearDown(self):
#         self.session.disconnect()
#         self.sock.close()
# 
#     def _auth(self):
#         return self.session.userauth_publickey_fromfile(
#             self.user, self.user_key)


import os
from unittest import skipUnless
from subprocess import check_output
from .base_test import SSH2TestCase
from ssh2.exceptions import SocketSendError
from ssh2.session import Session
from ssh2.channel import Channel
        _in = u'writing to stdin'
        chan = self.session.open_session()
        chan.execute('cat')
        chan.write_ex(0, _in + '\n')
        self.assertEqual(chan.send_eof(), 0)
        size, data = chan.read()
        self.assertTrue(size > 0)
        lines = [line.decode('utf-8') for line in data.splitlines()]
        self.assertListEqual([_in], lines)

    def test_write_stderr(self):
        self.assertEqual(self._auth(), 0)
        chan = self.session.open_session()
        chan.execute('echo something')
        _in = u'stderr'
        self.assertTrue(chan.write_stderr(_in + '\n')[0] > 0)
        self.assertEqual(chan.close(), 0)

    def test_setenv(self):
        self.assertEqual(self._auth(), 0)
        chan = self.session.open_session()
        _var = 'LC_MY_VAR'
        _val = 'value'
        self.assertEqual(chan.setenv('LC_MY_VAR', _val), 0)
        chan.execute('env | grep LC_MY_VAR')
        expected = u'%s=%s\n' % (_var, _val)
        size, data = chan.read()
        self.assertTrue(size > 0)
        self.assertEqual(data.decode('utf-8'), expected)


# Path: tests/base_test.py
# class SSH2TestCase(unittest.TestCase):
# 
#     @classmethod
#     def setUpClass(cls):
#         _mask = int('0600') if version_info <= (2,) else 0o600
#         os.chmod(PKEY_FILENAME, _mask)
#         cls.server = OpenSSHServer()
#         cls.server.start_server()
# 
#     @classmethod
#     def tearDownClass(cls):
#         cls.server.stop()
#         del cls.server
# 
#     def setUp(self):
#         self.host = '127.0.0.1'
#         self.port = 2222
#         self.cmd = 'echo me'
#         self.resp = u'me'
#         self.user_key = PKEY_FILENAME
#         self.user_pub_key = PUB_FILE
#         self.user = pwd.getpwuid(os.geteuid()).pw_name
#         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#         sock.connect((self.host, self.port))
#         self.sock = sock
#         self.session = Session()
#         self.session.handshake(self.sock)
# 
#     def tearDown(self):
#         self.session.disconnect()
#         self.sock.close()
# 
#     def _auth(self):
#         return self.session.userauth_publickey_fromfile(
#             self.user, self.user_key)


# Path: tests/test_channel.py
import os
from unittest import skipUnless
from subprocess import check_output
from .base_test import SSH2TestCase
from ssh2.exceptions import SocketSendError
from ssh2.session import Session
from ssh2.channel import Channel

        _in = u'writing to stdin'
        chan = self.session.open_session()
        chan.execute('cat')
        chan.write_ex(0, _in + '\n')
        self.assertEqual(chan.send_eof(), 0)
        size, data = chan.read()
        self.assertTrue(size > 0)
        lines = [line.decode('utf-8') for line in data.splitlines()]
        self.assertListEqual([_in], lines)

    def test_write_stderr(self):
        self.assertEqual(self._auth(), 0)
        chan = self.session.open_session()
        chan.execute('echo something')
        _in = u'stderr'
        self.assertTrue(chan.write_stderr(_in + '\n')[0] > 0)
        self.assertEqual(chan.close(), 0)

    def test_setenv(self):
        self.assertEqual(self._auth(), 0)
        chan = self.session.open_session()
        _var = 'LC_MY_VAR'
        _val = 'value'
        self.assertEqual(chan.setenv('LC_MY_VAR', _val), 0)
        chan.execute('env | grep LC_MY_VAR')
        expected = u'%s=%s\n' % (_var, _val)
        size, data = chan.read()
        self.assertTrue(size > 0)
        self.assertEqual(data.decode('utf-8'), expected)


    def test_shell(self):