
from twisted.web.server import Site
from twisted.trial.unittest import SynchronousTestCase

from ..script import ControlOptions, ControlScript
from ...testtools import MemoryCoreReactor


class ControlOptionsTests():
    """
    Tests for ``ControlOptions``.
    """
    def test_default_port(self):
        """
        The default port configured by ``ControlOptions`` is 4523.
        """
        options = ControlOptions()
        options.parseOptions([])
        self.assertEqual(options["port"], 4523)

    def test_custom_port(self):
        """
        The ``--port`` command-line option allows configuring the port.
        """
        options = ControlOptions()
        options.parseOptions(["--port", 1234])
        self.assertEqual(options["port"], 1234)


class ControlScriptTests(SynchronousTestCase):
    """
    Tests for ``ControlScript``.
    """
    def test_starts_http_api_server(self):
        """
        ``ControlScript.main`` starts a HTTP server on the given port.
        """
        reactor = MemoryCoreReactor()
        ControlScript().main(reactor, {"port": 8001})
        server = reactor.tcpServers[0]
        port = server[0]
        factory = server[1].__class__
        self.assertEqual((port, factory), (8001, Site))


from twisted.web.server import Site
from twisted.trial.unittest import SynchronousTestCase

from ..script import ControlOptions, ControlScript
from ...testtools import MemoryCoreReactor, StandardOptionsTestsMixin


class ControlOptionsTests(StandardOptionsTestsMixin,
                          SynchronousTestCase):
    """
    Tests for ``ControlOptions``.
    """
    options = ControlOptions

    def test_default_port(self):
        """
        The default port configured by ``ControlOptions`` is 4523.
        """
        options = ControlOptions()
        options.parseOptions([])
        self.assertEqual(options["port"], 4523)

    def test_custom_port(self):
        """
        The ``--port`` command-line option allows configuring the port.
        """
        options = ControlOptions()
        options.parseOptions(["--port", 1234])
        self.assertEqual(options["port"], 1234)


class ControlScriptEffectsTests(SynchronousTestCase):
    """
    Tests for effects ``ControlScript``.
    """
    def test_starts_http_api_server(self):
        """
        ``ControlScript.main`` starts a HTTP server on the given port.
        """
        reactor = MemoryCoreReactor()
        ControlScript().main(reactor, {"port": 8001})
        server = reactor.tcpServers[0]
        port = server[0]
        factory = server[1].__class__
        self.assertEqual((port, factory), (8001, Site))

Make sure options tests run.
Make sure options tests run.

  
  from twisted.web.server import Site
  from twisted.trial.unittest import SynchronousTestCase
  
  from ..script import ControlOptions, ControlScript
- from ...testtools import MemoryCoreReactor
+ from ...testtools import MemoryCoreReactor, StandardOptionsTestsMixin
  
  
- class ControlOptionsTests():
+ class ControlOptionsTests(StandardOptionsTestsMixin,
+                           SynchronousTestCase):
      """
      Tests for ``ControlOptions``.
      """
+     options = ControlOptions
+ 
      def test_default_port(self):
          """
          The default port configured by ``ControlOptions`` is 4523.
          """
          options = ControlOptions()
          options.parseOptions([])
          self.assertEqual(options["port"], 4523)
  
      def test_custom_port(self):
          """
          The ``--port`` command-line option allows configuring the port.
          """
          options = ControlOptions()
          options.parseOptions(["--port", 1234])
          self.assertEqual(options["port"], 1234)
  
  
- class ControlScriptTests(SynchronousTestCase):
+ class ControlScriptEffectsTests(SynchronousTestCase):
      """
-     Tests for ``ControlScript``.
+     Tests for effects ``ControlScript``.
      """
      def test_starts_http_api_server(self):
          """
          ``ControlScript.main`` starts a HTTP server on the given port.
          """
          reactor = MemoryCoreReactor()
          ControlScript().main(reactor, {"port": 8001})
          server = reactor.tcpServers[0]
          port = server[0]
          factory = server[1].__class__
          self.assertEqual((port, factory), (8001, Site))
  
Make sure options tests run.
## Code Before:

from twisted.web.server import Site
from twisted.trial.unittest import SynchronousTestCase

from ..script import ControlOptions, ControlScript
from ...testtools import MemoryCoreReactor


class ControlOptionsTests():
    """
    Tests for ``ControlOptions``.
    """
    def test_default_port(self):
        """
        The default port configured by ``ControlOptions`` is 4523.
        """
        options = ControlOptions()
        options.parseOptions([])
        self.assertEqual(options["port"], 4523)

    def test_custom_port(self):
        """
        The ``--port`` command-line option allows configuring the port.
        """
        options = ControlOptions()
        options.parseOptions(["--port", 1234])
        self.assertEqual(options["port"], 1234)


class ControlScriptTests(SynchronousTestCase):
    """
    Tests for ``ControlScript``.
    """
    def test_starts_http_api_server(self):
        """
        ``ControlScript.main`` starts a HTTP server on the given port.
        """
        reactor = MemoryCoreReactor()
        ControlScript().main(reactor, {"port": 8001})
        server = reactor.tcpServers[0]
        port = server[0]
        factory = server[1].__class__
        self.assertEqual((port, factory), (8001, Site))

## Instruction:
Make sure options tests run.
## Code After:

from twisted.web.server import Site
from twisted.trial.unittest import SynchronousTestCase

from ..script import ControlOptions, ControlScript
from ...testtools import MemoryCoreReactor, StandardOptionsTestsMixin


class ControlOptionsTests(StandardOptionsTestsMixin,
                          SynchronousTestCase):
    """
    Tests for ``ControlOptions``.
    """
    options = ControlOptions

    def test_default_port(self):
        """
        The default port configured by ``ControlOptions`` is 4523.
        """
        options = ControlOptions()
        options.parseOptions([])
        self.assertEqual(options["port"], 4523)

    def test_custom_port(self):
        """
        The ``--port`` command-line option allows configuring the port.
        """
        options = ControlOptions()
        options.parseOptions(["--port", 1234])
        self.assertEqual(options["port"], 1234)


class ControlScriptEffectsTests(SynchronousTestCase):
    """
    Tests for effects ``ControlScript``.
    """
    def test_starts_http_api_server(self):
        """
        ``ControlScript.main`` starts a HTTP server on the given port.
        """
        reactor = MemoryCoreReactor()
        ControlScript().main(reactor, {"port": 8001})
        server = reactor.tcpServers[0]
        port = server[0]
        factory = server[1].__class__
        self.assertEqual((port, factory), (8001, Site))
