old_contents: 
  from twisted.trial.unittest import TestCase
  from twisted.internet import reactor
  
  from game.functional.test_view3d import SceneMixin
  from game.player import Player
  from game.vector import Vector
  
  class StdoutReportingController(object):
      # XXX Make an interface for the controller and verify this fake.
      def __init__(self):
          self.player = Player(Vector(0, 0, 0), 0, reactor.seconds)
  
      def keyUp(self, key):
          pass
  
      def keyDown(self, key):
          pass
  
      def mouseMotion(self, pos, rel, buttons):
          """
          Report to standard out the direction of the mouse movement.
          """
          if rel[0] < 0:
              print 'left',
          elif rel[0] > 0:
              print 'right',
          if rel[1] < 0:
              print 'up',
          if rel[1] > 0:
              print 'down',
          print
  
  
  class MouseInputTests(SceneMixin, TestCase):
      """
      Tests for mouse input.
      """
      def test_movement(self):
          """
          When the mouse moves, the direction of movement is written to stdout.
          """
          self.window.submitTo(StdoutReportingController())
          reactor.callLater(2.0, self.window.stop)
          return self.window.go()
  
new_contents: 
  from pygame import K_q
  
  from twisted.trial.unittest import TestCase
  from twisted.internet import reactor
  
  from game.functional.test_view3d import SceneMixin
  from game.player import Player
  from game.vector import Vector
  
  
  class QuittableController(object):
      # XXX Make an interface for the controller and verify these fakes.
      def __init__(self, reactor, window):
          self.player = Player(Vector(0, 0, 0), 0, reactor.seconds)
          self.window = window
  
  
      def keyUp(self, key):
          if key == K_q:
              self.window.stop()
  
  
      def keyDown(self, key):
          pass
  
  
      def mouseMotion(self, pos, rel, buttons):
          pass
  
  
  
  class StdoutReportingController(QuittableController):
      def mouseMotion(self, pos, rel, buttons):
          """
          Report to standard out the direction of the mouse movement.
          """
          if rel[0] < 0:
              print 'left',
          elif rel[0] > 0:
              print 'right',
          if rel[1] < 0:
              print 'up',
          if rel[1] > 0:
              print 'down',
          print
  
  
  class MouseInputTests(SceneMixin, TestCase):
      """
      Tests for mouse input.
      """
      def test_movement(self):
          """
          When the mouse moves, the direction of movement is written to stdout.
          """
          self.window.submitTo(StdoutReportingController(reactor, self.window))
          return self.window.go()
  
  
      def test_grab(self):
          """
          Clicking on the window grabs the mouse.  Clicking again releases it.
          """
          self.window.submitTo(QuittableController(reactor, self.window))
          return self.window.go()
  
subject: Add a functional test for mouse grab.