def test_two_concats(): config, paths, concats, extras = config_from_toml( DIR / 'two_concats.toml', path_guess='{0.stem}.csv', ) assert config == { 'well': { 'A1': { 'x': 2 }, } } assert row(concats[0], 'well == "A1"') == dict( path=DIR / 'one_well_xy.csv', well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, y=1, ) assert row(concats[1], 'well == "A1"') == dict( path=DIR / 'one_well_xyz.csv', well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=0, y=0, z=1, )
def test_two_plates(): df = bio96.load( DIR / 'two_plates.toml', data_loader=pd.read_csv, merge_cols={'well': 'Well'}, ) assert row(df, 'plate == "a"') == dict( path=DIR / 'two_plates_a.csv', plate='a', well='A1', Well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, Data=0, ) assert row(df, 'plate == "b"') == dict( path=DIR / 'two_plates_b.csv', plate='b', well='A1', Well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=2, Data=1, )
def test_named_plates_with_defaults(): config = { 'expt': { 'z': 1, }, 'well': { 'A1': { 'x': 1, 'y': 1 }, }, 'plate': { 'Q': { 'well': { 'A1': { 'x': 2 }, }, }, 'R': { 'well': { 'A1': { 'y': 2 }, }, }, }, } df = table_from_config(config, DummyPathManager()) assert row(df, 'plate == "Q"') == dict( plate='Q', path='/path/to/q', well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=2, y=1, z=1, ) assert row(df, 'plate == "R"') == dict( plate='R', path='/path/to/r', well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, y=2, z=1, )
def test_top_level(): config = { 'plate': { 'Q': { 'y': 3, 'well': { 'A1': { 'x': 1 }, }, }, 'R': { 'y': 4, 'well': { 'A1': { 'x': 2 }, }, }, }, } df = table_from_config(config, DummyPathManager()) assert row(df, 'plate == "Q"') == dict( plate='Q', path='/path/to/q', well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, y=3, ) assert row(df, 'plate == "R"') == dict( plate='R', path='/path/to/r', well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=2, y=4, )
def test_one_plate(): labels = bio96.load(DIR / 'one_plate.toml') assert row(labels, 'well == "A1"') == dict( path=DIR / 'one_plate.csv', plate='a', well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, )
def test_only_plate(): config = { 'expt': { 'y': 2, }, 'well': { 'A1': { 'x': 1 }, }, } df = table_from_config(config, DummyPathManager()) assert row(df, 'well == "A1"') == dict( path='/path/to/data', well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, y=2, )
def test_one_well(): labels = bio96.load(DIR / 'one_well_xy.toml') assert row(labels, 'well == "A1"') == dict( well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, y=1, ) labels = bio96.load(DIR / 'one_well_xy.toml', path_guess='{0.stem}.csv') assert row(labels, 'well == "A1"') == dict( path=DIR / 'one_well_xy.csv', well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, y=1, ) with raises(ConfigError, match='one_well_xy.toml'): bio96.load(DIR / 'one_well_xy.toml', path_required=True) with raises(ConfigError, match='one_well_xy.toml'): bio96.load(DIR / 'one_well_xy.toml', data_loader=pd.read_csv) labels, data = bio96.load( DIR / 'one_well_xy.toml', data_loader=pd.read_csv, path_guess='{0.stem}.csv', ) assert row(labels, 'well == "A1"') == dict( path=DIR / 'one_well_xy.csv', well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, y=1, ) assert row(data, 'Well == "A1"') == dict( Well='A1', path=DIR / 'one_well_xy.csv', Data='xy', ) df = bio96.load( DIR / 'one_well_xy.toml', data_loader=pd.read_csv, merge_cols={'well': 'Well'}, path_guess='{0.stem}.csv', ) assert row(df, 'well == "A1"') == dict( path=DIR / 'one_well_xy.csv', well='A1', Well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, y=1, Data='xy', ) df = bio96.load( DIR / 'one_well_xy.toml', data_loader=read_csv_and_rename, merge_cols=True, path_guess='{0.stem}.csv', ) assert row(df, 'well == "A1"') == dict( path=DIR / 'one_well_xy.csv', well='A1', Well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, y=1, Data='xy', )
def test_one_well_with_extras(extras_arg, expected): labels, extras = bio96.load( DIR / 'one_well_xy_extras.toml', extras=extras_arg, ) assert extras == expected assert row(labels, 'well == "A1"') == dict( well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, y=1, ) labels, data, extras = bio96.load( DIR / 'one_well_xy_extras.toml', data_loader=pd.read_csv, path_guess='{0.stem}.csv', extras=extras_arg, ) assert extras == expected assert row(labels, 'well == "A1"') == dict( path=DIR / 'one_well_xy_extras.csv', well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, y=1, ) assert row(data, 'Well == "A1"') == dict( Well='A1', path=DIR / 'one_well_xy_extras.csv', Data='xy', ) # Merged data a1_expected = dict( path=DIR / 'one_well_xy_extras.csv', well='A1', Well='A1', well0='A01', row='A', col='1', row_i=0, col_j=0, x=1, y=1, Data='xy', ) df, extras = bio96.load( DIR / 'one_well_xy_extras.toml', data_loader=pd.read_csv, merge_cols={'well': 'Well'}, path_guess='{0.stem}.csv', extras=extras_arg, ) assert extras == expected assert row(df, 'well == "A1"') == a1_expected df, extras = bio96.load( DIR / 'one_well_xy_extras.toml', data_loader=read_csv_and_rename, merge_cols=True, path_guess='{0.stem}.csv', extras=extras_arg, ) assert extras == expected assert row(df, 'well == "A1"') == a1_expected