# Path: pygopherd/testutil.py
# def getconfig():
# def getstringlogger():
# def gettestingserver(config = None):
# def gettestinghandler(rfile, wfile, config = None):
#         def __init__(self, rfile, wfile):
#         def makefile(self, mode, bufsize):
#         def __init__(self, request, client_address, server):
# def gettestingprotocol(request, config = None):
#     class requestClass:
#     class handlerClass(initialization.GopherRequestHandler):


import unittest
import pygopherd.protocols
from io import StringIO
from pygopherd.protocols import ProtocolMultiplexer
from pygopherd import testutil

class ProtocolMultiplexerTestCase(unittest.TestCase):
    def setUp(self):
        self.config = testutil.getconfig()

    # Just a bunch of test cases for each different protocol -- make
    # sure we find the right one.

    def getproto(self, request):
        rfile = StringIO(request)
        wfile = StringIO()
        handler = testutil.gettestinghandler(rfile, wfile,
                                             self.config)
        return ProtocolMultiplexer.getProtocol(file.readline(),
                                               handler.server,
                                               handler,
                                               handler.rfile,
                                               handler.wfile,
                                               self.config)

    def testGoToGopher(self):

# Path: pygopherd/testutil.py
# def getconfig():
# def getstringlogger():
# def gettestingserver(config = None):
# def gettestinghandler(rfile, wfile, config = None):
#         def __init__(self, rfile, wfile):
#         def makefile(self, mode, bufsize):
#         def __init__(self, request, client_address, server):
# def gettestingprotocol(request, config = None):
#     class requestClass:
#     class handlerClass(initialization.GopherRequestHandler):


# Path: pygopherd/protocols/ProtocolMultiplexerTest.py
import unittest
import pygopherd.protocols
from io import StringIO
from pygopherd.protocols import ProtocolMultiplexer
from pygopherd import testutil


class ProtocolMultiplexerTestCase(unittest.TestCase):
    def setUp(self):
        self.config = testutil.getconfig()

    # Just a bunch of test cases for each different protocol -- make
    # sure we find the right one.

    def getproto(self, request):
        rfile = StringIO(request)
        wfile = StringIO()
        handler = testutil.gettestinghandler(rfile, wfile,
                                             self.config)
        return ProtocolMultiplexer.getProtocol(file.readline(),
                                               handler.server,
                                               handler,
                                               handler.rfile,
                                               handler.wfile,
                                               self.config)

    def testGoToGopher(self):

        assert isinstance(testutil.gettestingprotocol("/gopher0-request.txt\n"), pygopherd.protocols.rfc1436.GopherProtocol)