Exemplo n.º 1
0
class TestKB(KBObjectCreator):
    def __init__(self, name):
        super(TestKB, self).__init__(name)
        self.kill_list = []

    def setUp(self):
        self.kb = KB(driver='omero')(OME_HOST, OME_USER, OME_PASS)

    def tearDown(self):
        self.kill_list.reverse()
        for x in self.kill_list:
            self.kb.delete(x)
        self.kill_list = []

    def check_object(self, o, conf, otype):
        try:
            self.assertTrue(isinstance(o, otype))
            for k in conf.keys():
                v = conf[k]
                # FIXME this is omero specific...
                if hasattr(v, 'ome_obj'):
                    self.assertEqual(getattr(o, k).id, v.id)
                    self.assertEqual(type(getattr(o, k)), type(v))
                elif hasattr(v, '_id'):
                    self.assertEqual(getattr(o, k)._id, v._id)
                else:
                    self.assertEqual(getattr(o, k), v)
        except:
            pass

    def test_parallel_save(self):
        aconf, action = self.create_action()
        self.kill_list.append(action.save())
        N = 1000
        people = []
        for i in range(N):
            conf, i = self.create_individual(action=action,
                                             gender=self.kb.Gender.MALE)
            self.kill_list.append(i)
            people.append(i)
        start = time.time()
        self.kb.save_array(people)
        print ' \n\ttime needed to save %s object: %s' % (N,
                                                          time.time() - start)
Exemplo n.º 2
0
class TestKB(KBObjectCreator):

  def __init__(self, name):
    super(TestKB, self).__init__(name)
    self.kill_list = []

  def setUp(self):
    self.kb = KB(driver='omero')(OME_HOST, OME_USER, OME_PASS)

  def tearDown(self):
    self.kill_list.reverse()
    for x in self.kill_list:
      self.kb.delete(x)
    self.kill_list = []

  def check_object(self, o, conf, otype):
    try:
      self.assertTrue(isinstance(o, otype))
      for k in conf.keys():
        v = conf[k]
        # FIXME this is omero specific...
        if hasattr(v, 'ome_obj'):
          self.assertEqual(getattr(o, k).id, v.id)
          self.assertEqual(type(getattr(o, k)), type(v))
        elif hasattr(v, '_id'):
          self.assertEqual(getattr(o, k)._id, v._id)
        else:
          self.assertEqual(getattr(o, k), v)
    except:
      pass

  def test_parallel_save(self):
    aconf, action = self.create_action()
    self.kill_list.append(action.save())
    N = 1000
    people = []
    for i in range(N):
      conf, i = self.create_individual(action=action,
                                       gender=self.kb.Gender.MALE)
      self.kill_list.append(i)
      people.append(i)
    start =  time.time()
    self.kb.save_array(people)
    print' \n\ttime needed to save %s object: %s' % (N, time.time() - start)
Exemplo n.º 3
0
    for en_code1, en_code2 in couples:
        logger.info('Swapping couple %s - %s' % (en_code1, en_code2))
        try:
            en1 = en_lookup[en_code1]
            en2 = en_lookup[en_code2]
        except KeyError, ke:
            logger.error('Code %s not found in study %s' % (ke, args.study))
            sys.exit(2)

        logger.info('Starting swap procedure for couple %s -- %s' %
                    (en_code1, en_code2))
        logger.debug('Enrollment %s --- Individual ID %s' %
                     (en1.studyCode, en1.individual.id))
        logger.debug('Enrollment %s --- Individual ID %s' %
                     (en2.studyCode, en2.individual.id))

        en1.individual, en2.individual = en2.individual, en1.individual
        kb.save_array([en1, en2])

        logger.info('Swap completed')
        kb.reload_object(en1)
        logger.debug('Enrollment %s --- Individual ID %s' %
                     (en1.studyCode, en1.individual.id))
        kb.reload_object(en2)
        logger.debug('Enrollment %s --- Individual ID %s' %
                     (en2.studyCode, en2.individual.id))


if __name__ == '__main__':
    main(sys.argv[1:])
Exemplo n.º 4
0
    for en_code1, en_code2 in couples:
        logger.info('Swapping couple %s - %s' % (en_code1, en_code2))
        try:
            en1 = en_lookup[en_code1]
            en2 = en_lookup[en_code2]
        except KeyError, ke:
            logger.error('Code %s not found in study %s' % (ke, args.study))
            sys.exit(2)
            
        logger.info('Starting swap procedure for couple %s -- %s' % (en_code1, en_code2))
        logger.debug('Enrollment %s --- Individual ID %s' % (en1.studyCode,
                                                           en1.individual.id))
        logger.debug('Enrollment %s --- Individual ID %s' % (en2.studyCode,
                                                           en2.individual.id))

        en1.individual, en2.individual = en2.individual, en1.individual
        kb.save_array([en1, en2])

        logger.info('Swap completed')
        kb.reload_object(en1)
        logger.debug('Enrollment %s --- Individual ID %s' % (en1.studyCode,
                                                             en1.individual.id))
        kb.reload_object(en2)
        logger.debug('Enrollment %s --- Individual ID %s' % (en2.studyCode,
                                                             en2.individual.id))

        
if __name__ == '__main__':
    main(sys.argv[1:])