def test_symlinked_dataset_properties(repo1, repo2, repo3, non_repo, symlink): ds = Dataset(repo1).create() # now, let ds be a symlink and change that symlink to point to different # things: ar2 = AnnexRepo(repo2) ar3 = AnnexRepo(repo3) assert_true(os.path.isabs(non_repo)) os.symlink(repo1, symlink) ds_link = Dataset(symlink) assert_is(ds_link.repo, ds.repo) # same Repo instance assert_is_not(ds_link, ds) # but not the same Dataset instance assert_is(ds_link.config, ds.repo.config) assert_true(ds_link._cfg_bound) assert_is_not_none(ds_link.id) # same id, although different Dataset instance: assert_equal(ds_link.id, ds.id) os.unlink(symlink) os.symlink(repo2, symlink) assert_is(ds_link.repo, ar2) # same Repo instance assert_is(ds_link.config, ar2.config) assert_true(ds_link._cfg_bound) # id is None again, since this repository is an annex but there was no # Dataset.create() called yet. assert_is_none(ds_link.id) os.unlink(symlink) os.symlink(repo3, symlink) assert_is(ds_link.repo, ar3) # same Repo instance assert_is(ds_link.config, ar3.config) assert_true(ds_link._cfg_bound) # id is None again, since this repository is an annex but there was no # Dataset.create() called yet. assert_is_none(ds_link.id) os.unlink(symlink) os.symlink(non_repo, symlink) assert_is_none(ds_link.repo) assert_is_not(ds_link.config, ar3.config) assert_false(ds_link._cfg_bound) assert_is_none(ds_link.id)
def test_property_reevaluation(repo1): ds = Dataset(repo1) assert_is_none(ds.repo) assert_is_not_none(ds.config) first_config = ds.config assert_false(ds._cfg_bound) assert_is_none(ds.id) ds.create() assert_repo_status(repo1) # after creation, we have `repo`, and `config` was reevaluated to point # to the repo's config: assert_is_not_none(ds.repo) assert_is_not_none(ds.config) second_config = ds.config assert_true(ds._cfg_bound) assert_is(ds.config, ds.repo.config) assert_is_not(first_config, second_config) assert_is_not_none(ds.id) first_id = ds.id ds.remove() # repo is gone, and config is again reevaluated to only provide user/system # level config: assert_false(lexists(ds.path)) assert_is_none(ds.repo) assert_is_not_none(ds.config) third_config = ds.config assert_false(ds._cfg_bound) assert_is_not(second_config, third_config) assert_is_none(ds.id) ds.create() assert_repo_status(repo1) # after recreation everything is sane again: assert_is_not_none(ds.repo) assert_is_not_none(ds.config) assert_is(ds.config, ds.repo.config) forth_config = ds.config assert_true(ds._cfg_bound) assert_is_not(third_config, forth_config) assert_is_not_none(ds.id) assert_not_equal(ds.id, first_id)