# Path: seaworthy/utils.py
# def output_lines(output, encoding='utf-8', error_exc=None):
#     """
#     Convert bytestring container output or the result of a container exec
#     command into a sequence of unicode lines.
# 
#     :param output:
#         Container output bytes or an
#         :class:`docker.models.containers.ExecResult` instance.
#     :param encoding:
#         The encoding to use when converting bytes to unicode
#         (default ``utf-8``).
#     :param error_exc:
#         Optional exception to raise if ``output`` is an ``ExecResult`` with a
#         nonzero exit code.
# 
#     :returns: list[str]
# 
#     """
#     if isinstance(output, ExecResult):
#         exit_code, output = output
#         if exit_code != 0 and error_exc is not None:
#             raise error_exc(output.decode(encoding))
# 
#     return output.decode(encoding).splitlines()


import unittest
from docker.models.containers import ExecResult
from seaworthy.utils import output_lines




class TestOutputLinesFunc(unittest.TestCase):
    def test_bytes(self):
        """String lines are parsed from output bytes."""
        self.assertEqual(output_lines(b'foo\nbar\n'), ['foo', 'bar'])

    def test_exec_result(self):
        """String lines are parsed from an ExecResult."""
        self.assertEqual(output_lines(ExecResult(128, b'foo\r\nbar\r\n')),
                         ['foo', 'bar'])

    def test_custom_encoding(self):
        """String lines can be parsed using a custom encoding."""
        self.assertEqual(output_lines(b'\xe1', encoding='latin1'), ['á'])

    def test_exec_result_error_exc(self):
        """ExecResult with nonzero exit code can raise exception."""
        with self.assertRaisesRegex(TimeoutError, 'x\r\ny'):

# Path: seaworthy/utils.py
# def output_lines(output, encoding='utf-8', error_exc=None):
#     """
#     Convert bytestring container output or the result of a container exec
#     command into a sequence of unicode lines.
# 
#     :param output:
#         Container output bytes or an
#         :class:`docker.models.containers.ExecResult` instance.
#     :param encoding:
#         The encoding to use when converting bytes to unicode
#         (default ``utf-8``).
#     :param error_exc:
#         Optional exception to raise if ``output`` is an ``ExecResult`` with a
#         nonzero exit code.
# 
#     :returns: list[str]
# 
#     """
#     if isinstance(output, ExecResult):
#         exit_code, output = output
#         if exit_code != 0 and error_exc is not None:
#             raise error_exc(output.decode(encoding))
# 
#     return output.decode(encoding).splitlines()


# Path: seaworthy/tests-core/test_utils.py
import unittest
from docker.models.containers import ExecResult
from seaworthy.utils import output_lines





class TestOutputLinesFunc(unittest.TestCase):
    def test_bytes(self):
        """String lines are parsed from output bytes."""
        self.assertEqual(output_lines(b'foo\nbar\n'), ['foo', 'bar'])

    def test_exec_result(self):
        """String lines are parsed from an ExecResult."""
        self.assertEqual(output_lines(ExecResult(128, b'foo\r\nbar\r\n')),
                         ['foo', 'bar'])

    def test_custom_encoding(self):
        """String lines can be parsed using a custom encoding."""
        self.assertEqual(output_lines(b'\xe1', encoding='latin1'), ['á'])

    def test_exec_result_error_exc(self):
        """ExecResult with nonzero exit code can raise exception."""
        with self.assertRaisesRegex(TimeoutError, 'x\r\ny'):

            output_lines(ExecResult(128, b'x\r\ny'), error_exc=TimeoutError)