def launch(profile: Profile, strict: bool, foreground: bool, qb_args: List[str]) -> bool: if not profiles.ensure_profile_exists(profile, not strict): return False args = profile.cmdline() + qb_args if not shutil.which(args[0]): error("qutebrowser is not installed") return False if foreground: return subprocess.run(args).returncode == 0 else: p = subprocess.Popen(args, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) try: # give qb a chance to validate input before returning to shell stdout, stderr = p.communicate(timeout=0.1) print(stderr.decode(errors="ignore"), end="") except subprocess.TimeoutExpired: pass return True
def test_ensure_profile_exists_create(tmp_path: Path): profile = Profile("test", tmp_path) assert profiles.ensure_profile_exists(profile, True) check_new_profile(profile)
def test_ensure_profile_exists_not_dir(tmp_path: Path): profile = Profile("test", tmp_path) profile.root.touch() assert not profiles.ensure_profile_exists(profile, False) assert not profiles.ensure_profile_exists(profile, True)
def test_ensure_profile_exists_does_not_exist(tmp_path: Path): assert not profiles.ensure_profile_exists(Profile("test", tmp_path), False) check_is_empty(tmp_path)
def test_ensure_profile_exists_exists(tmp_path: Path): profile = Profile("test", tmp_path) profile.root.mkdir() assert profiles.ensure_profile_exists(profile, False) assert profiles.ensure_profile_exists(profile, True) check_is_empty(profile.root)