# 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 os
import pytest
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 pgctl.daemontools import SvStat
from pgctl.subprocess import check_call
from pgctl.subprocess import PIPE
from pgctl.subprocess import Popen
    from os import read



pytestmark = pytest.mark.usefixtures('in_example_dir')
greeter_service = pytest.mark.parametrize('service_name', ['greeter'])
unreliable_service = pytest.mark.parametrize('service_name', ['unreliable'])


def read_line(fd):
    # read one-byte-at-a-time to avoid deadlocking by reading too much
    line = ''
    byte = None
    while byte not in ('\n', ''):
        byte = read(fd, 1).decode('utf-8')
        line += byte
    return line


@greeter_service
def assert_works_interactively():
    read, write = os.openpty()
    pty.normalize_newlines(read)
    # setsid: this simulates the shell's job-control behavior

# 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/debug.py
import os
import pytest
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 pgctl.daemontools import SvStat
from pgctl.subprocess import check_call
from pgctl.subprocess import PIPE
from pgctl.subprocess import Popen
    from os import read




pytestmark = pytest.mark.usefixtures('in_example_dir')
greeter_service = pytest.mark.parametrize('service_name', ['greeter'])
unreliable_service = pytest.mark.parametrize('service_name', ['unreliable'])


def read_line(fd):
    # read one-byte-at-a-time to avoid deadlocking by reading too much
    line = ''
    byte = None
    while byte not in ('\n', ''):
        byte = read(fd, 1).decode('utf-8')
        line += byte
    return line


@greeter_service
def assert_works_interactively():
    read, write = os.openpty()
    pty.normalize_newlines(read)
    # setsid: this simulates the shell's job-control behavior

    proc = Popen(('setsid', 'pgctl', 'debug', 'greeter'), stdin=PIPE, stdout=write)