def test_times_out(self): """ Test it raises if it does not exceed """ func = lambda: False with self.assertRaises(TimeOutError): timed(func, time_out=1)
def test_times_success_want_opposite_return_value(self): """ Test it passes for a return value of False """ func = lambda: False response = timed(func, exit_on=False) self.assertIsNone(response)
def test_timed_sucess(self): """ Test it returns if suceeds """ func = lambda: True response = timed(func) self.assertIsNone(response)
def teardown(self): """ Stops and removes the docker container. :return: None """ response = self.client.stop(container=self.container['Id']) if response: self.logger.warning(response) response = self.client.remove_container(container=self.container['Id']) if response: self.logger.warning(response) try: timed(lambda: self.running, time_out=self.time_out, exit_on=False) except TimeOutError: self.logger.warning( 'Container teardown timed out, may still be running {}' .format(self.container) ) print 'Timeout'
def start(self, callback=None): """ Starts the container, and optionally executes a callback that is passed the container's info :param callback: Optional callback function that is called after the container is up. Useful for running more fine-grained container provisioning. :return: None """ self.logger.debug('Starting container {}'.format(self.image)) response = self.client.start(container=self.container['Id']) if response: self.logger.warning(response) self.logger.debug('Checking if {} service is ready'.format(self.name)) timed(lambda: self.running, time_out=30, exit_on=True) timed(lambda: self.ready, time_out=30, exit_on=True) self.logger.debug('Service {} is ready'.format(self.name)) if callable(callback): callback(container=self.container) self.logger.debug('Startup of {} complete'.format(self.name))