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)