示例#1
0
 def test_init_from_rack_and_invalid_position(self, tube_fac,
                                              tube_rack,
                                              rack_position_fac):
     kw = tube_fac.init_kw
     kw['rack'] = tube_rack
     kw['position'] = rack_position_fac(row_index=0, column_index=12)
     with pytest.raises(ValueError):
         Tube.create_from_rack_and_position(**kw)
     kw['position'] = rack_position_fac(row_index=8, column_index=0)
     with pytest.raises(ValueError):
         Tube.create_from_rack_and_position(**kw)
示例#2
0
 def __make_new_tube(self, sample_registration_item):
     self.add_debug('Creating new tube with barcode %s'
                    % sample_registration_item.tube_barcode)
     kw = dict(specs=self.__container_specs,
               status=self.__status)
     kw['barcode'] = sample_registration_item.tube_barcode
     pos = sample_registration_item.rack_position
     if not pos is None:
         kw['rack'] = sample_registration_item.rack
         kw['position'] = pos
         tube = Tube.create_from_rack_and_position(**kw)
     else:
         tube = Tube(**kw)
     return tube
示例#3
0
 def test_init_from_rack_and_position(self, tube_fac,
                                      tube_rack, rack_position11):
     kw = tube_fac.init_kw
     kw['rack'] = tube_rack
     kw['position'] = rack_position11
     tube = Tube.create_from_rack_and_position(**kw)
     check_attributes(tube, kw)
     assert not tube.slug is None
     assert tube.position == kw['position']
示例#4
0
 def __prepare_pool_stock_rack(self, empty_rack, sector_idx):
     tube_specs_agg = get_root_aggregate(ITubeSpecs)
     ts_matrix = tube_specs_agg.get_by_slug('matrix0500')
     is_managed = get_item_status_managed()
     pos_idxs_96 = zip([1, 1, 0, 0], [1, 1, 1, 1])
     (row_idx, col_idx) = pos_idxs_96[sector_idx]
     tube = Tube.create_from_data(
         dict(barcode=str(9999999990 + tube_counter.next()),
              status=is_managed,
              specs=ts_matrix))
     pos = get_rack_position_from_indices(row_idx, col_idx)
     empty_rack.add_tube(tube, pos)
示例#5
0
 def run(self):
     rack_agg = get_root_aggregate(IRack)
     is_agg = get_root_aggregate(IItemStatus)
     status = is_agg.get_by_slug(self.STATUS)
     cnt_specs_agg = get_root_aggregate(IContainerSpecs)
     cnt_specs = cnt_specs_agg.get_by_slug(self.SPECS)
     tubes = []
     for scan_fn in glob.glob("%s/*.txt" % self.__scanfile_directory):
         strm = open(scan_fn, 'r')
         try:
             prs = RackScanningParser(strm, parent=self)
             prs.run()
         finally:
             strm.close()
         if prs.has_errors():
             raise RuntimeError('Could not parse rack scan file "%s". '
                                'Error messages: %s' %
                                (scan_fn, self.get_messages()))
         rack_agg.filter = eq(barcode=prs.rack_barcode)
         try:
             rack = rack_agg.iterator().next()
         except StopIteration:
             self.add_error('Rack with barcode "%s" does not exist.' %
                            prs.rack_barcode)
             continue
         if not rack.specs.has_tubes:
             self.add_error('Rack with barcode "%s" is not a tube '
                            'rack.' % rack.barcode)
             continue
         for pos_label, barcode in prs.position_map.iteritems():
             if barcode is None:
                 continue
             pos = get_rack_position_from_label(pos_label)
             # FIXME: Enable this test once pulling a tube by barcode is
             #        fast.
             #                if tube_agg.get_by_slug(barcode):
             #                    self.add_error('Tube with barcode "%s" already '
             #                                   'exists.' % barcode)
             #                    continue
             if not rack.is_empty(pos):
                 self.add_error('Trying to place a tube in an occupied '
                                'position (%s on rack %s).' %
                                (pos_label, rack.barcode))
                 continue
             tube = Tube.create_from_rack_and_position(
                 cnt_specs, status, barcode, rack, pos)
             tubes.append(tube)
             self.add_info('Creating tube with barcode %s at '
                           'position %s in rack %s.' %
                           (barcode, pos_label, rack.barcode))
     if not self.has_errors():
         self.return_value = tubes
示例#6
0
    def run(self):
        rack_agg = get_root_aggregate(IRack)
        is_agg = get_root_aggregate(IItemStatus)
        status = is_agg.get_by_slug(self.STATUS)
        cnt_specs_agg = get_root_aggregate(IContainerSpecs)
        cnt_specs = cnt_specs_agg.get_by_slug(self.SPECS)
        tubes = []
        for scan_fn in glob.glob("%s/*.txt" % self.__scanfile_directory):
            strm = open(scan_fn, 'r')
            try:
                prs = RackScanningParser(strm, parent=self)
                prs.run()
            finally:
                strm.close()
            if prs.has_errors():
                raise RuntimeError('Could not parse rack scan file "%s". '
                                   'Error messages: %s'
                                   % (scan_fn, self.get_messages()))
            rack_agg.filter = eq(barcode=prs.rack_barcode)
            try:
                rack = rack_agg.iterator().next()
            except StopIteration:
                self.add_error('Rack with barcode "%s" does not exist.'
                               % prs.rack_barcode)
                continue
            if not rack.specs.has_tubes:
                self.add_error('Rack with barcode "%s" is not a tube '
                               'rack.' % rack.barcode)
                continue
            for pos_label, barcode in prs.position_map.iteritems():
                if barcode is None:
                    continue
                pos = get_rack_position_from_label(pos_label)
                # FIXME: Enable this test once pulling a tube by barcode is
                #        fast.
#                if tube_agg.get_by_slug(barcode):
#                    self.add_error('Tube with barcode "%s" already '
#                                   'exists.' % barcode)
#                    continue
                if not rack.is_empty(pos):
                    self.add_error('Trying to place a tube in an occupied '
                                   'position (%s on rack %s).' %
                                   (pos_label, rack.barcode))
                    continue
                tube = Tube.create_from_rack_and_position(cnt_specs, status,
                                                          barcode, rack, pos)
                tubes.append(tube)
                self.add_info('Creating tube with barcode %s at '
                              'position %s in rack %s.' %
                              (barcode, pos_label, rack.barcode))
        if not self.has_errors():
            self.return_value = tubes
示例#7
0
 def test_move_tube(self, tube_rack, item_status_managed,
                    tube_specs_matrix, rack_position11, rack_position_fac,
                    tube_rack_fac):
     tube = Tube.create_from_rack_and_position(
                 specs=tube_specs_matrix,
                 status=item_status_managed,
                 barcode='0111111111',
                 rack=tube_rack,
                 position=rack_position11)
     assert tube.location.position is rack_position11
     assert tube.location.rack is tube_rack
     assert tube.location.container is tube
     assert tube_rack.container_positions[rack_position11] is tube
     #
     empty_position = rack_position_fac(row_index=0, column_index=0)
     new_position = rack_position_fac(row_index=0, column_index=3)
     # Move within same rack.
     tube_rack.move_tube(rack_position11, new_position)
     assert tube.location.position is new_position
     # Move to other rack.
     new_rack = tube_rack_fac(label='TestDestTubeRack')
     tube_rack.remove_tube(tube)
     # Removing again raises error.
     with pytest.raises(ValueError):
         tube_rack.remove_tube(tube)
     new_rack.add_tube(tube, new_position)
     # Adding again raises error.
     with pytest.raises(ValueError):
         tube_rack.add_tube(tube, empty_position)
     assert tube.location.rack is new_rack
     # Moving from empty position raises ValueError.
     with pytest.raises(ValueError):
         new_rack.move_tube(empty_position, new_position)
     # Moving to occupied position raises ValueError.
     with pytest.raises(ValueError):
         new_rack.move_tube(new_position, new_position)