def test_handle_existing_path_existing_symlink_points_correctly(self, os, partials): os.path.lexists.return_value = True # test what it does when file exists os.path.islink.return_value = True # and is a symlink os.readlink.return_value = 'repo_path' # that points to where we want return_value = symlink.handle_existing_path(partials, 'repo_path', 'dest_path') assert bool(return_value) is True # nothing to do in this case
def test_handle_existing_path_existing_symlink_points_incorrectly(self, os, partials): os.path.lexists.return_value = True # test what it does when file exists os.path.islink.return_value = True # and is a symlink os.readlink.return_value = 'another_path' # this time it doesn't point where we want return_value = symlink.handle_existing_path(partials, 'repo_path', 'dest_path') os.remove.assert_called_with('dest_path') assert bool(return_value) is False # need to create
def test_handle_existing_path_existing_file_renamed(self, os, partials): # lastly, test the case where it's not a symlink but a real file, and test that # the file is renamed and that handle_existing_path returns True os.path.lexists.return_value = True os.path.islink.return_value = False with mock.patch('lib.symlink.backup_file') as backup_file: return_value = symlink.handle_existing_path(partials, 'repo_path', 'dest_path') assert bool(return_value) is False backup_file.assert_called_with('dest_path')
def test_handle_existing_path_regular_file(self, os, partials): # make sure it doesn't consider a regular file a partial and backs it up as normal os.path.lexists.return_value = True os.path.islink.return_value = False os.path.isdir.return_value = False with mock.patch('lib.symlink.backup_file') as backup_file: return_value = symlink.handle_existing_path( partials, 'repo/HOME/.config', '/Users/user/.config') assert bool(return_value) is False backup_file.assert_called_with('/Users/user/.config')
def test_handle_existing_path_partial_not_backed_up(self, os, partials): # make sure that it's *not* backed up if it's a partial directory os.path.lexists.return_value = True os.path.islink.return_value = False os.path.isdir.return_value = True with mock.patch('lib.symlink.backup_file') as backup_file: return_value = symlink.handle_existing_path( partials, 'repo/HOME/.config', '/Users/user/.config') assert bool(return_value) is False assert not backup_file.called
def test_handle_existing_path_no_existing_file(self, os, partials): os.path.lexists.return_value = False # no existing file case return_value = symlink.handle_existing_path(partials, 'repo_path', 'dest_path') # handle_existing_path returns falsy cause the symlink needs to be created assert bool(return_value) is False