def main(basepath, targetpath, user, group):
    batch = intake.ImportBatch(basepath, user, group)
    batch.validate_batch()
    targetpath = Path(targetpath)
    batch.set_target_path(targetpath)
    batch.write_files()
    return
Exemplo n.º 2
0
def test_load_targets(md_dict):
    batch = intake.ImportBatch('noconn', './jax_omeroutils/tests/data/')
    batch.md = deepcopy(md_dict)
    batch.md['file_metadata'][0]['filename'] = 'valid_test.tif'
    batch.md['file_metadata'][1]['filename'] = 'invalid_test.tif'
    assert len(batch.import_target_list) == 0
    batch.load_targets()
    assert len(batch.import_target_list) == 1
def test_ImportBatch_missing_other(tmp_path):
    d = _tmp_builder(tmp_path, 5)
    batch = intake.ImportBatch(d, 'djme', 'research_it')
    del batch.md['dataset']
    del batch.md['project']
    batch.md.iloc[3, 3] = None
    batch.validate_batch()
    assert batch.valid_batch is False
Exemplo n.º 4
0
def test_validate_import_md_dataset_errors(md_dict):
    # Check dataset error
    batch = intake.ImportBatch('test', 'test')
    batch.md = deepcopy(md_dict)
    batch.md['file_metadata'][0]['dataset'] = nan
    assert not batch.validate_import_md()
    batch.md['file_metadata'][0].pop('dataset')
    assert not batch.validate_import_md()
Exemplo n.º 5
0
def test_validate_import_md_filename_errors(md_dict):
    # Check filename errors
    batch = intake.ImportBatch('test', 'test')
    batch.md = deepcopy(md_dict)
    batch.md['file_metadata'][0]['filename'] = nan
    assert not batch.validate_import_md()
    batch.md['file_metadata'][0].pop('filename')
    assert not batch.validate_import_md()
Exemplo n.º 6
0
def test_ImportBatch_load_md(conn):
    import_path = Path('./jax_omeroutils/tests/data')
    batch = intake.ImportBatch(conn, import_path)
    assert batch.md is None
    batch.load_md(sheet_name="Example Form")
    assert batch.md['omero_user'] == 'djme'
    assert batch.md['omero_group'] == 'Research IT'
    assert batch.md['file_metadata'][0]['filename'] == 'my_image.tif'
Exemplo n.º 7
0
def test_set_server_path():
    batch = intake.ImportBatch('test', 'test')
    batch.user = '******'
    batch.group = 'Group Name'
    batch.set_server_path()
    group_path = Path('group_name')
    base = intake.BASE_SERVER_PATH
    assert batch.server_path.parents[0] == base / group_path
    assert batch.server_path.name.split('_')[0] == batch.user
Exemplo n.º 8
0
def test_ImportBatch_validate_ug(conn, users_groups):
    batch = intake.ImportBatch(conn, 'test')
    check = batch.validate_user_group(user='******', group='test_group_1')
    assert check
    assert batch.user == 'test_user1'
    assert batch.group == 'test_group_1'
    assert batch.user_email == '*****@*****.**'
    with pytest.raises(ValueError):
        batch.validate_user_group(user='******', group='bad_group')
    with pytest.raises(ValueError):
        batch.validate_user_group(user='******', group='test_group_1')
def test_ImportBatch_write_files(tmp_path):
    d = _tmp_builder(tmp_path, 5)
    batch = intake.ImportBatch(d, 'djme', 'research_it')
    batch.write_files()
    assert not os.path.exists(tmp_path / 'files.tsv')
    batch.validate_batch()
    batch.write_files()
    assert not os.path.exists(tmp_path / 'files.tsv')
    batch.set_target_path('/path/to/target/dir')
    batch.write_files()
    assert os.path.exists(tmp_path / 'files.tsv')
    assert os.path.exists(tmp_path / 'import_md.json')
    assert os.path.exists(tmp_path / 'import.yml')
Exemplo n.º 10
0
def test_write_json(md_dict, tmp_path):
    batch = intake.ImportBatch('noconn', tmp_path)
    batch.md = deepcopy(md_dict)
    batch.user = '******'
    batch.group = 'testgroup'
    batch.user_email = '*****@*****.**'
    batch.server_path = '/server_path'
    batch.valid_md = True
    batch.import_target_list = []
    for md_entry in batch.md['file_metadata']:
        import_target = intake.ImportTarget(tmp_path, md_entry)
        batch.import_target_list.append(import_target)
    batch.write_json()
    with open(tmp_path / 'import.json', 'r') as fp:
        test_json = json.load(fp)
    assert test_json['user'] == 'testuser'
    assert test_json['import_targets'][0]['project'] == 'proj'
def test_ImportBatch_missing_filename(tmp_path):
    d = _tmp_builder(tmp_path, 5)
    batch = intake.ImportBatch(d, 'djme', 'research_it')
    del batch.md['filename']
    batch.validate_batch()
    assert batch.valid_batch is False
def test_ImportBatch_too_many_files(tmp_path):
    d = _tmp_builder(tmp_path, 7)
    batch = intake.ImportBatch(d, 'djme', 'research_it')
    batch.validate_batch()
    assert batch.valid_batch is False
def test_ImportBatch_valid(tmp_path):
    d = _tmp_builder(tmp_path, 5)
    batch = intake.ImportBatch(d, 'djme', 'research_it')
    valid = batch.validate_batch()
    assert valid is True
    assert batch.valid_batch is True
def test_ImportBatch_init(tmp_path):
    d = _tmp_builder(tmp_path, 5)
    batch = intake.ImportBatch(d, 'djme', 'research_it')
    assert batch.user == 'djme'
    assert batch.md.filename[0] == 'image0.tif'
def test_ImportBatch_no_metadata(tmp_path):
    d = _tmp_builder(tmp_path, 5)
    os.remove(d / 'md.tsv')
    batch = intake.ImportBatch(d, 'djme', 'research_it')
    batch.validate_batch()
    assert batch.valid_batch is False
Exemplo n.º 16
0
def test_validate_import_md_duplicate_fn(md_dict):
    batch = intake.ImportBatch('test', 'test')
    batch.md = deepcopy(md_dict)
    batch.md['file_metadata'].append(batch.md['file_metadata'][0])
    assert not batch.validate_import_md()
Exemplo n.º 17
0
def test_validate_import_md_good(md_dict):
    batch = intake.ImportBatch('test', 'test')
    batch.md = deepcopy(md_dict)
    assert batch.validate_import_md()