def test_date_from_rundir(): run_dir = 'tests/fixtures/demux/150410_D00134_0189_BHF3GKADXX' run_date = date_from_rundir(run_dir) assert run_date.year == 2015 assert run_date.month == 4 assert run_date.day == 10 with pytest.raises(AttributeError): date_from_rundir('tests/D00134_0189_BHF3GKADXX')
def add_flowcell(flowcell_dir, samples=None): """Create a new instance of a Spof to the database.""" logger.debug('extracting info from run dir') flowcell_id = extract_flowcell(flowcell_dir) demux_date = date_from_rundir(flowcell_dir) run_folder = path(flowcell_dir).realpath().basename() logger.debug('check of the flowcell already exists') flowcell_obj = Flowcell.query.filter_by(flowcell_id=flowcell_id).first() if flowcell_obj is None: if samples is None: sample_rundirs = get_sample_rundirs(flowcell_dir) sample_ids = (sample_from_rundir(sample_dir) for sample_dir in sample_rundirs) samples = [Sample.query.filter_by(lims_id=sample_id).one() for sample_id in sample_ids] logger.debug('creating new Flowcell record') flowcell_obj = Flowcell(flowcell_id=flowcell_id, demux_folder=run_folder, demuxed_at=demux_date, samples=samples) logger.debug('committing to database') return flowcell_obj