# Path: seaworthy/containers/nginx.py
# class NginxContainer(ContainerDefinition):
#     """
#     Nginx container definition.
# 
#     .. todo:
#         Write more docs.
#     """
# 
#     DEFAULT_NAME = 'nginx'
#     DEFAULT_IMAGE = 'nginx:alpine'
# 
#     def __init__(self, name=DEFAULT_NAME, image=DEFAULT_IMAGE, **kwargs):
#         super().__init__(name, image, **kwargs)
# 
#     def base_kwargs(self):
#         """
#         Publish all exposed ports to the host.
#         """
#         return {'publish_all_ports': True}
# 
#     def wait_for_start(self):
#         """
#         Wait for Nginx to return any valid HTTP response.
#         """
#         wait_for_response(self.http_client(), self.wait_timeout)
# 
#     def exec_nginx(self, args):
#         """
#         Execute a ``nginx`` command inside a running container.
# 
#         :params args: a list of args for the command
#         """
#         return self.inner().exec_run(['nginx'] + args)
# 
#     def exec_signal(self, signal='reload'):
#         """
#         Send a signal to the Nginx master process (``nginx -s``).
# 
#         :param signal: one of: stop, quit, reopen, or reload
#         """
#         return self.exec_nginx(['-s', signal])
# 
# Path: seaworthy/pytest/checks.py
# def dockertest():
#     """
#     Skip tests that require Docker to be available.
# 
#     This is a function that returns a decorator so that we don't run arbitrary
#     Docker client code on import. Unlike :func:`seaworthy.checks.dockertest`,
#     this implementation doesn't require :class:`unittest.TestCase`. It does,
#     however, require pytest.
#     """
#     return pytest.mark.skipif(
#         not docker_available(), reason='Docker not available.')
# 
# 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 string
import textwrap
import time
import pytest
from seaworthy.containers.nginx import NginxContainer
from seaworthy.pytest import dockertest
from seaworthy.utils import output_lines




@pytest.fixture(scope='module')
def nginx(docker_helper):
    with NginxContainer(helper=docker_helper) as container:
        yield container


@dockertest()
class TestNginxContainer:
    def test_inspection(self, nginx):
        """
        Inspecting the Nginx container should show that the default image
        and name has been used, a forwarded port has been set up and the
        network aliases are correct.
        """
        attrs = nginx.inner().attrs


# Path: seaworthy/containers/nginx.py
# class NginxContainer(ContainerDefinition):
#     """
#     Nginx container definition.
# 
#     .. todo:
#         Write more docs.
#     """
# 
#     DEFAULT_NAME = 'nginx'
#     DEFAULT_IMAGE = 'nginx:alpine'
# 
#     def __init__(self, name=DEFAULT_NAME, image=DEFAULT_IMAGE, **kwargs):
#         super().__init__(name, image, **kwargs)
# 
#     def base_kwargs(self):
#         """
#         Publish all exposed ports to the host.
#         """
#         return {'publish_all_ports': True}
# 
#     def wait_for_start(self):
#         """
#         Wait for Nginx to return any valid HTTP response.
#         """
#         wait_for_response(self.http_client(), self.wait_timeout)
# 
#     def exec_nginx(self, args):
#         """
#         Execute a ``nginx`` command inside a running container.
# 
#         :params args: a list of args for the command
#         """
#         return self.inner().exec_run(['nginx'] + args)
# 
#     def exec_signal(self, signal='reload'):
#         """
#         Send a signal to the Nginx master process (``nginx -s``).
# 
#         :param signal: one of: stop, quit, reopen, or reload
#         """
#         return self.exec_nginx(['-s', signal])
# 
# Path: seaworthy/pytest/checks.py
# def dockertest():
#     """
#     Skip tests that require Docker to be available.
# 
#     This is a function that returns a decorator so that we don't run arbitrary
#     Docker client code on import. Unlike :func:`seaworthy.checks.dockertest`,
#     this implementation doesn't require :class:`unittest.TestCase`. It does,
#     however, require pytest.
#     """
#     return pytest.mark.skipif(
#         not docker_available(), reason='Docker not available.')
# 
# 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/containers/test_nginx.py
import string
import textwrap
import time
import pytest
from seaworthy.containers.nginx import NginxContainer
from seaworthy.pytest import dockertest
from seaworthy.utils import output_lines





@pytest.fixture(scope='module')
def nginx(docker_helper):
    with NginxContainer(helper=docker_helper) as container:
        yield container


@dockertest()
class TestNginxContainer:
    def test_inspection(self, nginx):
        """
        Inspecting the Nginx container should show that the default image
        and name has been used, a forwarded port has been set up and the
        network aliases are correct.
        """
        attrs = nginx.inner().attrs


        assert attrs['Config']['Image'] == NginxContainer.DEFAULT_IMAGE