def test_empty_tags(self): self.assertEqual(0, _FantasmLog.all().count()) self.assertEqual(0, sum(self.loggingDouble.count.values())) self.context.logger.info('a', tags=[]) runQueuedTasks(queueName=self.context.queueName, assertTasks=self.PERSISTENT_LOGGING) self.assertEqual({True: 1, False: 0}[self.PERSISTENT_LOGGING], _FantasmLog.all().count()) self.assertEqual(1, sum(self.loggingDouble.count.values()))
def test_logging_TypeError(self): self.context.logger.info('%s') if self.PERSISTENT_LOGGING: runQueuedTasks(queueName=self.context.queueName) self.assertEqual('%s', _FantasmLog.all(namespace='').get().message) self.assertEqual(logging.INFO, _FantasmLog.all(namespace='').get().level)
def test_TaskTooLargeError(self): self.assertEqual(0, _FantasmLog.all().count()) self.assertEqual(0, sum(self.loggingDouble.count.values())) self.context.logger.info('a' * 100000) runQueuedTasks(queueName=self.context.queueName, assertTasks=False) self.assertEqual({True: 0, False: 0}[self.PERSISTENT_LOGGING], _FantasmLog.all().count()) self.assertEqual({True: 2, False: 1}[self.PERSISTENT_LOGGING], sum(self.loggingDouble.count.values()))
def test_batchsize_10(self): self.context['batchsize'] = 10 self.context.initialize() # queues the first task runQueuedTasks(maxRetries=0) self.assertEqual(1 + self.EXTRA_COUNT, _FantasmFanIn.all().count()) self.assertEqual(self.EXTRA_VALUES + self.EXPECTED_VALUES, sorted(ContinuationFanInResult.get_by_key_name('test').values))
def test_logging_object(self): self.context.logger.info({'a': 'b'}) if self.PERSISTENT_LOGGING: runQueuedTasks(queueName=self.context.queueName) self.assertEqual("{'a': 'b'}", _FantasmLog.all().get().message) else: self.assertEqual("{'a': 'b'}", self.loggingDouble.messages['info'][0])
def test_batchsize_11(self): self.context['batchsize'] = 11 self.context.initialize() # queues the first task runQueuedTasks(maxRetries=0) self.assertEqual(1, _FantasmFanIn.all(namespace='').count()) self.assertEqual( self.EXPECTED_VALUES, sorted(ContinuationFanInResult.get_by_key_name('test').values))
def test_batchsize_3(self): self.context['batchsize'] = 3 self.context.initialize() # queues the first task runQueuedTasks() self.assertEqual(4, _FantasmFanIn.all().count()) self.assertEqual( self.EXPECTED_VALUES, sorted(ContinuationFanInResult.get_by_key_name('test').values))
def test_level_OFF(self): self.context.logger.setLevel(logging.CRITICAL+1) self.context.logger.critical('critical') self.context.logger.error('error') self.context.logger.warning('warning') self.context.logger.info('info') self.context.logger.debug('debug') runQueuedTasks(queueName=self.context.queueName, assertTasks=False) self.assertEqual({True: 0, False: 0}[self.PERSISTENT_LOGGING], _FantasmLog.all().count()) self.assertEqual(0, sum(self.loggingDouble.count.values()))
def test_maxLevel_WARNING(self): self.context.logger.setMaxLevel(logging.WARNING) self.context.logger.critical('critical') self.context.logger.error('error') self.context.logger.warning('warning') self.context.logger.info('info') self.context.logger.debug('debug') runQueuedTasks(queueName=self.context.queueName, assertTasks=self.PERSISTENT_LOGGING) self.assertEqual({True: 3, False: 0}[self.PERSISTENT_LOGGING], _FantasmLog.all().count()) self.assertEqual(3, sum(self.loggingDouble.count.values()))
def test_logging_bad_object(self): class StrRaises(object): def __str__(self): raise Exception() self.context.logger.info(StrRaises()) if self.PERSISTENT_LOGGING: runQueuedTasks(queueName=self.context.queueName) self.assertEqual(LOG_ERROR_MESSAGE, _FantasmLog.all().get().message) self.assertEqual(logging.INFO, _FantasmLog.all().get().level) else: self.assertEqual('logging error', self.loggingDouble.messages['info'][0])
def test_empty_tags(self): self.assertEqual(0, _FantasmLog.all(namespace='').count()) self.assertEqual(0, sum(self.loggingDouble.count.values())) self.context.logger.info('a', tags=[]) runQueuedTasks(queueName=self.context.queueName, assertTasks=self.PERSISTENT_LOGGING) self.assertEqual({ True: 1, False: 0 }[self.PERSISTENT_LOGGING], _FantasmLog.all(namespace='').count()) self.assertEqual(1, sum(self.loggingDouble.count.values()))
def test(self): self.context.initialize() # queues the first task self.assertEqual(0, _FantasmTaskSemaphore.all().count()) self.assertEqual(0, SimpleModel.all().count()) tq = apiproxy_stub_map.apiproxy.GetStub('taskqueue') tasks = tq.GetTasks('default') runQueuedTasks(tasksOverride=tasks) self.assertEqual(1, _FantasmTaskSemaphore.all().count()) self.assertEqual(1, SimpleModel.all().count()) runQueuedTasks(tasksOverride=tasks) logging.info([e.key().name() for e in _FantasmTaskSemaphore.all().fetch(100)]) self.assertEqual(1, _FantasmTaskSemaphore.all().count()) self.assertEqual(1, SimpleModel.all().count())
def test_maxLevel_OFF(self): self.context.logger.setMaxLevel(logging.DEBUG - 1) self.context.logger.critical('critical') self.context.logger.error('error') self.context.logger.warning('warning') self.context.logger.info('info') self.context.logger.debug('debug') runQueuedTasks(queueName=self.context.queueName, assertTasks=False) self.assertEqual({ True: 0, False: 0 }[self.PERSISTENT_LOGGING], _FantasmLog.all(namespace='').count()) self.assertEqual(0, sum(self.loggingDouble.count.values()))
def test_TaskTooLargeError(self): self.assertEqual(0, _FantasmLog.all(namespace='').count()) self.assertEqual(0, sum(self.loggingDouble.count.values())) self.context.logger.info('a' * 1000000) runQueuedTasks(queueName=self.context.queueName, assertTasks=False) self.assertEqual({ True: 0, False: 0 }[self.PERSISTENT_LOGGING], _FantasmLog.all(namespace='').count()) self.assertEqual({ True: 2, False: 1 }[self.PERSISTENT_LOGGING], sum(self.loggingDouble.count.values()))
def test(self): self.context.initialize() # queues the first task self.assertEqual(0, _FantasmTaskSemaphore.all().count()) self.assertEqual(0, SimpleModel.all().count()) tq = apiproxy_stub_map.apiproxy.GetStub('taskqueue') tasks = tq.GetTasks('default') runQueuedTasks(tasksOverride=tasks) self.assertEqual(1, _FantasmTaskSemaphore.all().count()) self.assertEqual(1, SimpleModel.all().count()) runQueuedTasks(tasksOverride=tasks) logging.info( [e.key().name() for e in _FantasmTaskSemaphore.all().fetch(100)]) self.assertEqual(1, _FantasmTaskSemaphore.all().count()) self.assertEqual(1, SimpleModel.all().count())
def test_level_WARNING(self): self.context.logger.setLevel(logging.WARNING) self.context.logger.critical('critical') self.context.logger.error('error') self.context.logger.warning('warning') self.context.logger.info('info') self.context.logger.debug('debug') runQueuedTasks(queueName=self.context.queueName, assertTasks=self.PERSISTENT_LOGGING) self.assertEqual({ True: 3, False: 0 }[self.PERSISTENT_LOGGING], _FantasmLog.all().count()) self.assertEqual(3, sum(self.loggingDouble.count.values()))
def test(self): self.context.initialize() # queues the first task self.assertEqual(20, SimpleModel.all().count()) runQueuedTasks(speedup=False) result = ResultModel.get_by_key_name('test') self.assertEqual(20, result.total)
def test_batchsize_3(self): self.context['batchsize'] = 3 self.context.initialize() # queues the first task runQueuedTasks() self.assertEqual(4, _FantasmFanIn.all().count()) self.assertEqual(self.EXPECTED_VALUES, sorted(ContinuationFanInResult.get_by_key_name('test').values))
def test_stateName(self): self.context.logger.info('info') if self.PERSISTENT_LOGGING: runQueuedTasks(queueName=self.context.queueName) log = _FantasmLog.all(namespace='').get() self.assertEqual('pseudo-init', log.stateName)
def test_machineName(self): self.context.logger.info('info') if self.PERSISTENT_LOGGING: runQueuedTasks(queueName=self.context.queueName) log = _FantasmLog.all(namespace='').get() self.assertEqual('FSMContextTests', log.machineName)
def test_transitionName(self): self.context.logger.info('info') if self.PERSISTENT_LOGGING: runQueuedTasks(queueName=self.context.queueName) log = _FantasmLog.all().get() self.assertEqual(None, log.transitionName)
def test_stateName(self): self.context.logger.info('info') if self.PERSISTENT_LOGGING: runQueuedTasks(queueName=self.context.queueName) log = _FantasmLog.all().get() self.assertEqual('pseudo-init', log.stateName)
def test_machineName(self): self.context.logger.info('info') if self.PERSISTENT_LOGGING: runQueuedTasks(queueName=self.context.queueName) log = _FantasmLog.all().get() self.assertEqual('FSMContextTests', log.machineName)
def test_logging_TypeError(self): self.context.logger.info('%s') if self.PERSISTENT_LOGGING: runQueuedTasks(queueName=self.context.queueName) self.assertEqual('%s', _FantasmLog.all().get().message) self.assertEqual(logging.INFO, _FantasmLog.all().get().level)
def test_transitionName(self): self.context.logger.info('info') if self.PERSISTENT_LOGGING: runQueuedTasks(queueName=self.context.queueName) log = _FantasmLog.all(namespace='').get() self.assertEqual(None, log.transitionName)