Ejemplo n.º 1
0
    def start(self, interval=1.0, refresh_factor=5):
        if refresh_factor < 1:
            raise RuntimeError("refresh_factor must be greater or eqaul to 1")
        if interval <= 0:
            raise RuntimeError("interval must not be negative or 0")

        descriptors = self.descriptors

        if LOGGER.isEnabledFor(logging.INFO):
            desc = "\n".join([
                desc.describe(indent=4)
                for desc in descriptors.itervalues()])
            LOGGER.info("Monitoring:\n%s" % desc)

        # Prior to Python 2.5, the ``yield`` statement is not
        # allowed in the ``try`` clause of a ``try ... finally``
        # construct.
        try:
            self.monitoring = True

            times = 0
            while descriptors and self.monitoring:

                time.sleep(interval)
                times += 1

                if times % refresh_factor == 0:
                    monitor = self.refresh()
                else:
                    monitor = self.monitor()

                for modified in monitor:
                    if not self.monitoring:
                        break
                    yield modified
            else:
                LOGGER.info("Terminating monitor %s" % str(self))
        except:
            self.monitoring = False
            raise
Ejemplo n.º 2
0
    def __call__(self):

        # Walking dependency graph in imported module to
        # module imports order.
        testables = []
        for desc in self.descriptor.walk_dependency_graph(reverse=True):
            LOGGER.info("-> Affected: %s" % desc.name)
            if has_subclass(desc, unittest.TestCase):
                LOGGER.debug("-> unittest.TestCase detected: %s" % desc.name)
                testables.append(desc)

        # Runntine tests
        if testables:
            # We can reload affected modules manually and run
            # all TestCase in same process. Running another process,
            # however, is simple and perfect solution.
            if LOGGER.isEnabledFor(logging.INFO):
                desc = ', '.join([x.name for x in testables])
                LOGGER.info("Running UnitTests: %s" % desc)
            # Propagates the level of modipyd.LOGGER to
            # the unittest runner subprocess.
            extra = ['--loglevel', LOGGER.getEffectiveLevel()]
            self.spawn_unittest_runner(testables, extra)