How to use force_link method in autotest

Best Python code snippet using autotest_python

init_zshrc.py

Source:init_zshrc.py Github

copy

Full Screen

1import os2from pathlib import Path3import re4import shutil5def link_zshrc_file(force_link=False):6 zshrc_source = Path(__file__).resolve().parent/"rc_dotfiles"/".zshrc"7 zshrc_destination = Path().home()/".zshrc"8 if not zshrc_source.exists():9 raise Exception(f".zshrc source file not found")10 if zshrc_destination.exists():11 if force_link:12 old_zshrc_destination = Path().home()/".zshrc.old"13 shutil.move(zshrc_destination, old_zshrc_destination)14 print(f"moved existing ~/.zshrc file to {old_zshrc_destination}")15 else:16 raise Exception(f".zshrc file already exists at {zshrc_destination}")17 print(f"symlinking {zshrc_source} to {zshrc_destination}")18 os.system(f"ln -sf {zshrc_source} {zshrc_destination}")19def link_oh_my_zsh_packages():20 # symlinking oh-my-zsh packages in .setup21 source_plugins = Path(__file__).resolve().parent/'oh-my-zsh-plugins'22 dest_plugins = Path('~/.oh-my-zsh/custom/plugins')23 os.system(f"rm -r {dest_plugins}")24 os.system(f"ln -s {source_plugins} {dest_plugins}")25 # symlinking oh-my-zsh themes26 source_themes = Path(__file__).resolve().parent/'oh-my-zsh-themes'27 dest_themes = Path("~/.oh-my-zsh/custom/themes")28 os.system(f"rm -r {dest_themes}")29 os.system(f"ln -s {source_themes} {dest_themes}")30def install_oh_my_zsh():31 oh_my_zsh_install_location = os.environ.get("ZSH", False)32 if not oh_my_zsh_install_location or not Path(oh_my_zsh_install_location).exists():33 print("installing oh_my_zsh")34 os.system('sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) --unattended --keep-zshrc"')35 else:36 print("skipping oh-my-zsh install - already detected")37def link_p10krc_file(force_link=False):38 p10krc_source = Path(__file__).resolve().parent/"rc_dotfiles"/".p10k.zsh"39 p10krc_destination = Path().home()/".p10k.zsh"40 if not p10krc_source.exists():41 raise Exception(f".p10k.zsh source file not found")42 if p10krc_destination.exists():43 if force_link:44 old_p10krc_destination = Path().home()/".p10k.zsh.old"45 shutil.move(p10krc_destination, old_p10krc_destination)46 print(f"moved existing ~/.p10k.zsh file to {old_p10krc_destination}")47 else:48 raise Exception(f".p10k.zsh file already exists at {p10krc_destination}")49 print(f"symlinking {p10krc_source} to {p10krc_destination}")50 os.system(f"ln -sf {p10krc_source} {p10krc_destination}")51def link_tmux_rc_file(force_link=True):52 tmux_rc_source = Path(__file__).resolve().parent/"rc_dotfiles"/".tmux.conf"53 tmux_rc_destination = Path().home()/".tmux.conf"54 if not tmux_rc_source.exists():55 raise Exception(f".tmux.conf source file not found")56 if tmux_rc_destination.exists():57 if force_link:58 old_tmux_rc_destination = Path().home()/".tmux.conf.old"59 shutil.move(tmux_rc_destination, old_tmux_rc_destination)60 print(f"moved existing ~/.tmux.conf file to {old_tmux_rc_destination}")61 else:62 raise Exception(f".tmux.conf file already exists at {tmux_rc_destination}")63 print(f"symlinking {tmux_rc_source} to {tmux_rc_destination}")...

Full Screen

Full Screen

test_fs.py

Source:test_fs.py Github

copy

Full Screen

...49 with open(path) as f:50 content: str = f.read()51 assert content == ("INIT=true\n" if preexisting else "") + "HELLO=world\nCHENV=testing\n"52@pytest.mark.parametrize("preexisting", [False, True])53def test_force_link(preexisting: bool) -> None:54 """Test `force_link`."""55 filename: str = ".env.source"56 side_effect: Optional[Exception] = FileNotFoundError() if preexisting else None57 with patch("os.remove", side_effect=side_effect) as remove, patch("os.symlink") as symlink:58 chenv.fs.force_link(filename)59 remove.assert_called_once_with(chenv.settings.DOTENV)60 symlink.assert_called_once_with(filename, chenv.settings.DOTENV)61@pytest.mark.parametrize("path, expected", [(_SAMPLE_FILE, ["HELLO=world", 'CHENV="testing"']), (".env.missing", [])])62def test_load_lines(path: str, expected: Optional[Dict[str, str]]) -> None:63 """Test `load_lines`."""...

Full Screen

Full Screen

setup.py

Source:setup.py Github

copy

Full Screen

1from install_scripts import install_system_packages2from zshrc_src import init_zshrc3from ssh import init_ssh, decrypt_ssh_folder4from pathlib import Path5import subprocess6import argparse7parser = argparse.ArgumentParser()8parser.add_argument('--disable-ssh', help='disable ssh install', action='store_true')9parser.add_argument('--disable-zshrc', help='disable linking zshrc', action='store_true')10parser.add_argument('--overwrite-ssh', help='deletes saved ssh/encrypted.ssh and replaces it with existing ~/.ssh', action='store_true')11parser.add_argument('--disable-system-installs', help='skips installing packages', action='store_true')12args = parser.parse_args()13if not args.disable_system_installs:14 install_system_packages.install_zsh()15 install_system_packages.install_curl()16 install_system_packages.install_vim()17 install_system_packages.install_ripgrep()18 install_system_packages.install_fzf()19if not args.disable_zshrc:20 init_zshrc.install_oh_my_zsh()21 init_zshrc.link_oh_my_zsh_packages()22 init_zshrc.link_zshrc_file(force_link=True)23 init_zshrc.link_p10krc_file(force_link=True)24 init_zshrc.link_tmux_rc_file(force_link=True)25if args.overwrite_ssh:26 init_ssh.overwrite_ssh()27elif not args.disable_ssh:28 decrypt_ssh_folder.decrypt_ssh_folder()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful