Ejemplo n.º 1
0
def setup_layer(options, layer, setup_layers):
    assert layer is not object
    output = options.output
    if layer not in setup_layers:
        for base in layer.__bases__:
            if base is not object:
                setup_layer(options, base, setup_layers)
        output.start_set_up(name_from_layer(layer))
        t = time.time()
        if hasattr(layer, 'setUp'):
            try:
                layer.setUp()
            except Exception:
                if options.post_mortem:
                    if options.resume_layer:
                        options.output.error_with_banner(
                            cant_pm_in_subprocess_message
                            % options.resume_layer)
                        raise
                    else:
                        zope.testrunner.debug.post_mortem(
                            sys.exc_info())
                else:
                    raise

        output.stop_set_up(time.time() - t)
        setup_layers[layer] = 1
Ejemplo n.º 2
0
def layer_sort_key(layer):
    """Compute sort key for layers.

    Based on the reverse MRO ordering in order to put layers with shared base
    layers next to each other.
    """
    seen = set([])
    key = []

    # Note: we cannot reuse gather_layers() here because it uses a
    # different traversal order.
    def _gather(layer):
        seen.add(layer)
        # We make the simplifying assumption that the order of initialization
        # of base layers does not matter.  Given that, traversing the bases
        # in reverse order here keeps the ordering of layers in
        # testrunner-layers.rst the same as it was in older versions of
        # zope.testrunner, so let's use that.
        for base in layer.__bases__[::-1]:
            if base is not object and base not in seen:
                _gather(base)
        key.append(layer)

    _gather(layer)
    return tuple(name_from_layer(l) for l in key if l != UnitTests)
Ejemplo n.º 3
0
    def ordered_layers(self):
        if (self.options.processes > 1 and not self.options.resume_layer):
            # if we want multiple processes, we need a fake layer as first
            # to start spreading out layers/tests to subprocesses
            # but only if this is not in the subprocess
            yield (name_from_layer(EmptyLayer), EmptyLayer, EmptySuite())

        layer_names = dict([(layer_from_name(layer_name), layer_name)
                            for layer_name in self.tests_by_layer_name])
        for layer in order_by_bases(layer_names):
            layer_name = layer_names[layer]
            yield layer_name, layer, self.tests_by_layer_name[layer_name]
Ejemplo n.º 4
0
def order_by_bases(layers):
    """Order the layers from least to most specific (bottom to top)
    """
    named_layers = [(name_from_layer(layer), layer) for layer in layers]
    named_layers.sort()
    named_layers.reverse()
    gathered = []
    for name, layer in named_layers:
        gather_layers(layer, gathered)
    gathered.reverse()
    seen = {}
    result = []
    for layer in gathered:
        if layer not in seen:
            seen[layer] = 1
            if layer in layers:
                result.append(layer)
    return result
Ejemplo n.º 5
0
def tear_down_unneeded(options, needed, setup_layers, optional=False):
    # Tear down any layers not needed for these tests. The unneeded layers
    # might interfere.
    unneeded = [l for l in setup_layers if l not in needed]
    unneeded = order_by_bases(unneeded)
    unneeded.reverse()
    output = options.output
    for l in unneeded:
        output.start_tear_down(name_from_layer(l))
        t = time.time()
        try:
            try:
                if hasattr(l, 'tearDown'):
                    l.tearDown()
            except NotImplementedError:
                output.tear_down_not_supported()
                if not optional:
                    raise CanNotTearDown(l)
            else:
                output.stop_tear_down(time.time() - t)
        finally:
            del setup_layers[l]
Ejemplo n.º 6
0
def tear_down_unneeded(options, needed, setup_layers, optional=False):
    # Tear down any layers not needed for these tests. The unneeded layers
    # might interfere.
    unneeded = [l for l in setup_layers if l not in needed]
    unneeded = order_by_bases(unneeded)
    unneeded.reverse()
    output = options.output
    for l in unneeded:
        output.start_tear_down(name_from_layer(l))
        t = time.time()
        try:
            try:
                if hasattr(l, 'tearDown'):
                    l.tearDown()
            except NotImplementedError:
                output.tear_down_not_supported()
                if not optional:
                    raise CanNotTearDown(l)
            else:
                output.stop_tear_down(time.time() - t)
        finally:
            del setup_layers[l]
Ejemplo n.º 7
0
 def __str__(self):
     return "Layer: %s" % (name_from_layer(self.layer))
Ejemplo n.º 8
0
 def __str__(self):
     return "Layer: %s" % (name_from_layer(self.layer))
Ejemplo n.º 9
0
 def __str__(self):
     return "Layer: %s.tearDown" % (name_from_layer(self.layer))