# Path: pgctl/daemontools.py
# class SvStat(
#         namedtuple('SvStat', ['state', 'pid', 'exitcode', 'seconds', 'process'])
# ):
#     __slots__ = ()
#     UNSUPERVISED = 'could not get status, supervisor is down'
#     INVALID = 'no such service'
# 
#     def __repr__(self):
#         format = '{0.state}'
#         if self.pid is not None:
#             format += ' (pid {0.pid})'
#         if self.exitcode is not None:
#             format += ' (exitcode {0.exitcode})'
#         if self.seconds is not None:
#             format += ' {0.seconds} seconds'
#         if self.process is not None:
#             format += ', {0.process}'
# 
#         return format.format(self)
# 
# Path: pgctl/subprocess.py
# def set_defaults(func, **defaults):
#     def wrapped(cmd, **kwargs):
# PIPE = subprocess.PIPE
# STDOUT = subprocess.STDOUT
# 
# Path: pgctl/subprocess.py
# PIPE = subprocess.PIPE
# 
# Path: pgctl/subprocess.py
# def set_defaults(func, **defaults):
#     def wrapped(cmd, **kwargs):
# PIPE = subprocess.PIPE
# STDOUT = subprocess.STDOUT


import json
import os
import subprocess
import pytest
        import fcntl
                        import time
from unittest import mock
from testing import norm
from testing import pty
from testing.assertions import assert_svstat
from testing.assertions import wait_for
from testing.subprocess import assert_command
from testing.subprocess import ctrl_c
from testing.subprocess import run
from pgctl.daemontools import SvStat
from pgctl.subprocess import check_call
from pgctl.subprocess import PIPE
from pgctl.subprocess import Popen
        from testfixtures import StringComparison as S
            from testing import copy_example
''',
            '',
            0,
            norm=norm.pgctl,
        )

        check_call(('pgctl', 'restart', 'sweet'))

        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/ohhi/logs/current <==

==> playground/sweet/logs/current <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
''',
            '',
            0,
            norm=norm.pgctl,
        )

    def it_logs_continuously_when_run_interactively(self, in_example_dir):
        check_call(('pgctl', 'start'))

        # this pty simulates running in a terminal
        read, write = os.openpty()
        pty.normalize_newlines(read)

# Path: pgctl/daemontools.py
# class SvStat(
#         namedtuple('SvStat', ['state', 'pid', 'exitcode', 'seconds', 'process'])
# ):
#     __slots__ = ()
#     UNSUPERVISED = 'could not get status, supervisor is down'
#     INVALID = 'no such service'
# 
#     def __repr__(self):
#         format = '{0.state}'
#         if self.pid is not None:
#             format += ' (pid {0.pid})'
#         if self.exitcode is not None:
#             format += ' (exitcode {0.exitcode})'
#         if self.seconds is not None:
#             format += ' {0.seconds} seconds'
#         if self.process is not None:
#             format += ', {0.process}'
# 
#         return format.format(self)
# 
# Path: pgctl/subprocess.py
# def set_defaults(func, **defaults):
#     def wrapped(cmd, **kwargs):
# PIPE = subprocess.PIPE
# STDOUT = subprocess.STDOUT
# 
# Path: pgctl/subprocess.py
# PIPE = subprocess.PIPE
# 
# Path: pgctl/subprocess.py
# def set_defaults(func, **defaults):
#     def wrapped(cmd, **kwargs):
# PIPE = subprocess.PIPE
# STDOUT = subprocess.STDOUT


# Path: tests/spec/examples.py
import json
import os
import subprocess
import pytest
        import fcntl
                        import time
from unittest import mock
from testing import norm
from testing import pty
from testing.assertions import assert_svstat
from testing.assertions import wait_for
from testing.subprocess import assert_command
from testing.subprocess import ctrl_c
from testing.subprocess import run
from pgctl.daemontools import SvStat
from pgctl.subprocess import check_call
from pgctl.subprocess import PIPE
from pgctl.subprocess import Popen
        from testfixtures import StringComparison as S
            from testing import copy_example

''',
            '',
            0,
            norm=norm.pgctl,
        )

        check_call(('pgctl', 'restart', 'sweet'))

        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/ohhi/logs/current <==

==> playground/sweet/logs/current <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
''',
            '',
            0,
            norm=norm.pgctl,
        )

    def it_logs_continuously_when_run_interactively(self, in_example_dir):
        check_call(('pgctl', 'start'))

        # this pty simulates running in a terminal
        read, write = os.openpty()
        pty.normalize_newlines(read)

        p = Popen(('pgctl', 'log'), stdout=write, stderr=write)