def test_lostFileDescriptor(self):
        """
        The file descriptor underlying a FileDescriptor may be closed and
        replaced by another at some point.  Bytes which arrive on the new
        descriptor must not be delivered to the FileDescriptor which was
        originally registered with the original descriptor of the same number.

        Practically speaking, this is difficult or impossible to detect.  The
        implementation relies on C{fileno} raising an exception if the original
        descriptor has gone away.  If C{fileno} continues to return the original
        file descriptor value, the reactor may deliver events from that
        descriptor.  This is a best effort attempt to ease certain debugging
        situations.  Applications should not rely on it intentionally.
        """
        reactor = self.buildReactor()

        name = reactor.__class__.__name__
        if name in ('EPollReactor', 'KQueueReactor', 'CFReactor'):
            # Closing a file descriptor immediately removes it from the epoll
            # set without generating a notification.  That means epollreactor
            # will not call any methods on Victim after the close, so there's
            # no chance to notice the socket is no longer valid.
            raise SkipTest("%r cannot detect lost file descriptors" % (name, ))

        client, server = self._connectedPair()

        class Victim(FileDescriptor):
            """
            This L{FileDescriptor} will have its socket closed out from under it
            and another socket will take its place.  It will raise a
            socket.error from C{fileno} after this happens (because socket
            objects remember whether they have been closed), so as long as the
            reactor calls the C{fileno} method the problem will be detected.
            """
            def fileno(self):
                return server.fileno()

            def doRead(self):
                raise Exception("Victim.doRead should never be called")

            def connectionLost(self, reason):
                """
                When the problem is detected, the reactor should disconnect this
                file descriptor.  When that happens, stop the reactor so the
                test ends.
                """
                reactor.stop()

        reactor.addReader(Victim())

        # Arrange for the socket to be replaced at some unspecified time.
        # Significantly, this will not be while any I/O processing code is on
        # the stack.  It is something that happens independently and cannot be
        # relied upon to happen at a convenient time, such as within a call to
        # doRead.
        def messItUp():
            newC, newS = self._connectedPair()
            fileno = server.fileno()
            server.close()
            os.dup2(newS.fileno(), fileno)
            newC.send("x")

        reactor.callLater(0, messItUp)

        self.runReactor(reactor)

        # If the implementation feels like logging the exception raised by
        # MessedUp.fileno, that's fine.
        self.flushLoggedErrors(socket.error)
Beispiel #2
0
 def setUp(self):
     if FILETYPE_PEM is None:
         raise SkipTest("OpenSSL not available.")
Beispiel #3
0
def assert_gcs_environ():
    if 'GCS_PROJECT_ID' not in os.environ:
        raise SkipTest("GCS_PROJECT_ID not found")
Beispiel #4
0
        return newfunc
    else:
        return testfunction


def assert_aws_environ():
    """Asserts the current environment is suitable for running AWS testsi.
    Raises SkipTest with the reason if it's not.
    """
    try:
        import boto
    except ImportError, e:
        raise SkipTest(str(e))

    if 'AWS_ACCESS_KEY_ID' not in os.environ:
        raise SkipTest("AWS keys not found")


def get_crawler(settings_dict=None):
    """Return an unconfigured Crawler object. If settings_dict is given, it
    will be used as the settings present in the settings module of the
    CrawlerSettings.
    """
    from scrapy.crawler import Crawler
    from scrapy.settings import CrawlerSettings

    class SettingsModuleMock(object):
        pass

    settings_module = SettingsModuleMock()
    if settings_dict:
Beispiel #5
0
 def test_LOCK_UNLOCK(self):
     """
     LOCK, UNLOCK request
     """
     raise SkipTest("test unimplemented")
 def test_free_busy_recurring(self):
     """
     Free-busy on recurring events.
     (CalDAV-access-09, section 7.8)
     """
     raise SkipTest("test unimplemented")
 def test_free_busy_free_busy(self):
     """
     Free-busy on free busy components.
     (CalDAV-access-09, section 7.8)
     """
     raise SkipTest("test unimplemented")
 def test_adjustFloatingToTimezone(self):
     raise SkipTest("test unimplemented")
 def test_compareDateTime(self):
     raise SkipTest("test unimplemented")
 def test_datetimeMktime(self):
     raise SkipTest("test unimplemented")
 def test_floatoffset(self):
     raise SkipTest("test unimplemented")
 def test_clipPeriod(self):
     raise SkipTest("test unimplemented")
 def test_normalizePeriodList(self):
     raise SkipTest("test unimplemented")
Beispiel #14
0
 def test_reactor_stop_unblocks_EventualResult(self):
     """
     Any EventualResult.wait() calls still waiting when the reactor has
     stopped will get a ReactorStopped exception.
     """
     raise SkipTest("Not done yet.")
Beispiel #15
0
 def buildStore(*args, **kwargs):
     raise SkipTest(
         "buildStore is not available, because it's in txdav; duh.")
 def test_differenceDateTime(self):
     raise SkipTest("test unimplemented")
 def test_free_busy_basic(self):
     """
     Free-busy on plain events.
     (CalDAV-access-09, section 7.8)
     """
     raise SkipTest("test unimplemented")
Beispiel #18
0
 def setUp(self):
     if not numpy:
         raise SkipTest("numpy not available")
 def test_free_busy_statustransp(self):
     """
     SFree-busy on events with different STATUS/TRANSP property values.
     (CalDAV-access-09, section 7.8)
     """
     raise SkipTest("test unimplemented")
Beispiel #20
0
 def skipit(self):
     raise SkipTest("No private attribute tests.")
Beispiel #21
0
 def _checkForRpmbuild(self):
     """
     tap2rpm requires rpmbuild; skip tests if rpmbuild is not present.
     """
     if not procutils.which("rpmbuild"):
         raise SkipTest("rpmbuild must be present to test tap2rpm")
def skip_if_no_boto():
    if not is_botocore_available():
        raise SkipTest('missing botocore library')
Beispiel #23
0
    def test_disconnectWhileProducing(self):
        """
        If C{loseConnection} is called while a producer is registered with the
        transport, the connection is closed after the producer is unregistered.
        """
        reactor = self.buildReactor()

        # For some reason, pyobject/pygtk will not deliver the close
        # notification that should happen after the unregisterProducer call in
        # this test.  The selectable is in the write notification set, but no
        # notification ever arrives.  Probably for the same reason #5233 led
        # win32eventreactor to be broken.
        skippedReactors = ["Glib2Reactor", "Gtk2Reactor"]
        reactorClassName = reactor.__class__.__name__
        if reactorClassName in skippedReactors and platform.isWindows():
            raise SkipTest("A pygobject/pygtk bug disables this functionality "
                           "on Windows.")

        class Producer:
            def resumeProducing(self):
                log.msg("Producer.resumeProducing")

        self.listen(reactor, ServerFactory.forProtocol(Protocol))

        finished = Deferred()
        finished.addErrback(log.err)
        finished.addCallback(lambda ign: reactor.stop())

        class ClientProtocol(Protocol):
            """
            Protocol to connect, register a producer, try to lose the
            connection, unregister the producer, and wait for the connection to
            actually be lost.
            """
            def connectionMade(self):
                log.msg("ClientProtocol.connectionMade")
                self.transport.registerProducer(Producer(), False)
                self.transport.loseConnection()
                # Let the reactor tick over, in case synchronously calling
                # loseConnection and then unregisterProducer is the same as
                # synchronously calling unregisterProducer and then
                # loseConnection (as it is in several reactors).
                reactor.callLater(0, reactor.callLater, 0, self.unregister)

            def unregister(self):
                log.msg("ClientProtocol unregister")
                self.transport.unregisterProducer()
                # This should all be pretty quick.  Fail the test
                # if we don't get a connectionLost event really
                # soon.
                reactor.callLater(
                    1.0, finished.errback,
                    Failure(Exception("Connection was not lost")))

            def connectionLost(self, reason):
                log.msg("ClientProtocol.connectionLost")
                finished.callback(None)

        clientFactory = ClientFactory()
        clientFactory.protocol = ClientProtocol
        self.connect(reactor, clientFactory)
        self.runReactor(reactor)
 def test_c_encode_basestring_ascii(self):
     if not encoder.c_encode_basestring_ascii:
         raise SkipTest("no C extension speedups available to test")
     self._test_encode_basestring_ascii(encoder.c_encode_basestring_ascii)
Beispiel #25
0
    def process_fds():
        path = FilePath(b"/dev/fd")
        if not path.exists():
            raise SkipTest("/dev/fd is not available.")

        return set([child.basename() for child in path.children()])
Beispiel #26
0
 def test_REPORT_expand_property(self):
     """
     DAV:expand-property REPORT request.
     """
     raise SkipTest("test unimplemeted")
Beispiel #27
0
 def test_scanstring(self):
     if not encoder.c_encode_basestring_ascii:
         raise SkipTest("no C extension speedups available to test")
     self.assertEquals(decoder.scanstring.__module__,
                       "simplejson._speedups")
     self.assert_(decoder.scanstring is decoder.c_scanstring)
 def addSQLToSchema(*args, **kwargs):
     raise SkipTest("addSQLToSchema is not available: {0}".format(e))
Beispiel #29
0
def skip_if_no_boto():
    try:
        is_botocore()
    except NotConfigured as e:
        raise SkipTest(e)
Beispiel #30
0
    def test_unexpected_device_discovered(self, device):
        """
        After attaching the volume, if a new device path is discovered that's
        not related to the path given by the ``device`` parameter in the
        expected way, ``AttachedUnexpectedDevice`` is raised giving details
        about the expected and received paths.
        """
        # The implementation is going to look at the real system to see what
        # block devices exist.  It would be nice to have an abstraction in
        # place to easily manipulate these results for the tests.  Lacking
        # that, just grab the actual block devices from the system and then
        # drop one to make it look like that one has just appeared as a result
        # of the attach operation.
        blockdevices = _get_blockdevices()

        # But there are complex criteria for selection.  So be careful which
        # device we select so as to fool the implementation.
        for wrong_device in blockdevices:
            # Don't pick the one that's actually the right result
            if wrong_device.basename().endswith(device[-1]):
                continue

            if wrong_device.basename().startswith((b"sd", b"xvd")):
                size = _get_device_size(wrong_device.basename())
                volume = self.volume.set("size", size)
                blockdevices.remove(wrong_device)
                break
        else:
            # Ideally we'd have more control over the implementation so we
            # wouldn't have to give up when running on a system lacking just
            # the right devices to let us exercise the code we want to
            # exercise.  Getting to that point involves fixing all of the
            # things in ebs.py like _get_blockdevices and _get_device_size that
            # pass around raw strings or FilePath instances representing
            # devices and then go off and interact directly with the underlying
            # system.
            #
            # We need control over (at least) what devices the code-under-test
            # can discover and what size it thinks they are.  Until then we
            # just have to give up.  If you can't get this test to run without
            # skipping, try adding another block device to your system (eg plug
            # in a usb device).
            #
            # With apologies,
            #  -jean-paul
            raise SkipTest(
                "Could not find a suitable device to use as a bad device.")

        exception = self.assertRaises(
            AttachedUnexpectedDevice,
            _attach_volume_and_wait_for_device,
            volume=volume,
            attach_to=self.compute_id,
            attach_volume=lambda *a, **kw: None,
            detach_volume=lambda *a, **kw: None,
            device=device,
            blockdevices=blockdevices,
        )
        self.assertEqual(
            AttachedUnexpectedDevice(
                requested=FilePath(device),
                discovered=FilePath(b"/dev/").child(wrong_device.basename()),
            ),
            exception,
        )