Example #1
0
    def test_main_multi_proc(self):
        # requires: POSIX environment, color-cat command
        def f(bs):
            return b'\x1b[7m\x1b[35mtests/resources/test_color_ssh_01.sh\x1b[0m|\x1b[0m\x1b[35m' + bs + b'\x1b[0m\n'

        def g(bs):
            return b'\x1b[7m\x1b[35mtests/resources/test_color_ssh_01.sh\x1b[0m+\x1b[0m\x1b[35m' + bs + b'\x1b[0m\n'

        with self.__with_temp_output() as (out, err):
            path = os.path.join('tests', 'resources', 'test_color_ssh_01.sh')
            args = ['color-ssh', '--ssh', str('bash'), '-H', '%s %s' % (path, path), 'abc', 'def']

            self.assertFalse(out.closed)
            self.assertFalse(err.closed)

            ret = color_ssh.main(args, stdout=out, stderr=err)
            self.assertEqual(ret, 0)

            out.seek(0)
            err.seek(0)

            self.assertEqual(sorted(out.read()),
                             sorted((f(b'abc') + f(b'foo') + f('あいうえお'.encode('utf-8')) + f(b'\xff\xfe')) * 2))
            self.assertEqual(sorted(err.read()),
                             sorted((g(b'def') + g(b'bar') + g('かきくけこ'.encode('utf-8')) + g(b'\xfd\xfc')) * 2))
Example #2
0
    def test_main_task_error(self):
        with self.__with_temp_output() as (out, err):
            args = ['color-ssh', '--ssh', str('./tests/resources/not_exist_command'), 'x', 'y']
            ret = color_ssh.main(args, stdout=out, stderr=err)
            self.assertEqual(ret, 1)

            out.seek(0)
            err.seek(0)

            self.assertEqual(out.read(), b'')
            self.assertTrue(b'No such file or directory' in err.read())
Example #3
0
    def test_main_single_proc(self):
        # requires: POSIX environment, color-cat command
        def f(bs):
            return b'\x1b[7m\x1b[35mtests/resources/test_color_ssh_01.sh\x1b[0m|\x1b[0m\x1b[35m' + bs + b'\x1b[0m\n'

        def g(bs):
            return b'\x1b[7m\x1b[35mtests/resources/test_color_ssh_01.sh\x1b[0m+\x1b[0m\x1b[35m' + bs + b'\x1b[0m\n'

        with self.__with_temp_output() as (out, err):
            args = ['color-ssh', '--ssh', str('bash'),
                    os.path.join('tests', 'resources', 'test_color_ssh_01.sh'), 'abc', 'def']
            ret = color_ssh.main(args, stdout=out, stderr=err)
            self.assertEqual(ret, 0)

            out.seek(0)
            err.seek(0)

            self.assertEqual(out.read(), f(b'abc') + f(b'foo') + f('あいうえお'.encode('utf-8')) + f(b'\xff\xfe'))
            self.assertEqual(err.read(), g(b'def') + g(b'bar') + g('かきくけこ'.encode('utf-8')) + g(b'\xfd\xfc'))