def test_unlink(self, tmpdir, debug, verbose, name, links): """ Tests that: 1. Each symlink is moved back to its original location. 2. Symlinks are removed from bootstrap. 3. Cache is updated with targets removed. 4. Symlink directory is removed if empty. Expected errors: - StowError is raised if no symlink was found. - SymlinkError is raised if target already exists. """ cider = Cider(False, debug, verbose, cider_dir=str(tmpdir.join("cider")), support_dir=str(tmpdir.join("cider", ".cache"))) cider.remove_symlink = MagicMock() stow_dir = os.path.abspath(os.path.join(cider.symlink_dir, name)) os.makedirs(stow_dir) for link in links: source = os.path.join(stow_dir, link) target = str(tmpdir.join(link)) touch(source) os.symlink(source, target) cider.add_symlink(name, target) cider.unlink(name) new_cache = cider._cached_targets() # pylint:disable=W0212 for link in links: source = os.path.join(stow_dir, link) target = str(tmpdir.join(link)) assert os.path.exists(target) assert not os.path.islink(target) assert not os.path.exists(source) assert target not in new_cache cider.remove_symlink.assert_called_with(name) assert not os.path.exists(stow_dir)
def test_unlink(self, tmpdir, debug, verbose, name, links): """ Tests that: 1. Each symlink is moved back to its original location. 2. Symlinks are removed from bootstrap. 3. Cache is updated with targets removed. 4. Symlink directory is removed if empty. Expected errors: - StowError is raised if no symlink was found. - SymlinkError is raised if target already exists. """ cider = Cider( False, debug, verbose, cider_dir=str(tmpdir.join("cider")), support_dir=str(tmpdir.join("cider", ".cache")) ) cider.remove_symlink = MagicMock() stow_dir = os.path.abspath(os.path.join(cider.symlink_dir, name)) os.makedirs(stow_dir) for link in links: source = os.path.join(stow_dir, link) target = str(tmpdir.join(link)) touch(source) os.symlink(source, target) cider.add_symlink(name, target) cider.unlink(name) new_cache = cider._cached_targets() # pylint:disable=W0212 for link in links: source = os.path.join(stow_dir, link) target = str(tmpdir.join(link)) assert os.path.exists(target) assert not os.path.islink(target) assert not os.path.exists(source) assert target not in new_cache cider.remove_symlink.assert_called_with(name) assert not os.path.exists(stow_dir)
def test_addlink(self, tmpdir, debug, verbose, name): """ Tests that: 1. Symlink directory is created & file is moved there. 2. Symlink is created. 3. Symlink is added to bootstrap. 4. Cache is updated with new target. Expected errors: - StowError is raised if target does not exist. - StowError is raised if target already exists. """ cider = Cider( False, debug, verbose, cider_dir=str(tmpdir), support_dir=str(tmpdir.join(".cache")) ) cider.add_symlink = MagicMock() source = os.path.abspath(str(tmpdir.join(random_str(min_length=1)))) basename = os.path.basename(source) stow_dir = os.path.abspath(os.path.join(cider.symlink_dir, name)) stow = os.path.join(stow_dir, basename) # StowError should be raised if source does not exist. with pytest.raises(StowError): cider.addlink(name, source) touch(source) cider.addlink(name, source) assert os.path.isdir(stow_dir) assert os.path.isfile(stow) assert os.path.islink(source) assert os.path.samefile( os.path.realpath(stow), os.path.realpath(source) ) cider.add_symlink.assert_called_with(name, source) new_cache = cider._cached_targets() # pylint:disable=W0212 assert source in new_cache # StowError should be raised if source already exists. os.remove(source) touch(source) with pytest.raises(StowError): cider.addlink(source, name)
def test_addlink(self, tmpdir, debug, verbose, name): """ Tests that: 1. Symlink directory is created & file is moved there. 2. Symlink is created. 3. Symlink is added to bootstrap. 4. Cache is updated with new target. Expected errors: - StowError is raised if target does not exist. - StowError is raised if target already exists. """ cider = Cider(False, debug, verbose, cider_dir=str(tmpdir), support_dir=str(tmpdir.join(".cache"))) cider.add_symlink = MagicMock() source = os.path.abspath(str(tmpdir.join(random_str(min_length=1)))) basename = os.path.basename(source) stow_dir = os.path.abspath(os.path.join(cider.symlink_dir, name)) stow = os.path.join(stow_dir, basename) # StowError should be raised if source does not exist. with pytest.raises(StowError): cider.addlink(name, source) touch(source) cider.addlink(name, source) assert os.path.isdir(stow_dir) assert os.path.isfile(stow) assert os.path.islink(source) assert os.path.samefile(os.path.realpath(stow), os.path.realpath(source)) cider.add_symlink.assert_called_with(name, source) new_cache = cider._cached_targets() # pylint:disable=W0212 assert source in new_cache # StowError should be raised if source already exists. os.remove(source) touch(source) with pytest.raises(StowError): cider.addlink(source, name)