2022-12-20 11:54:34 +13:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from bdfr.completion import Completion
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(sys.platform == "win32", reason="Completions are not currently supported on Windows.")
|
|
|
|
def test_cli_completion_all(tmp_path: Path):
|
2022-12-21 07:05:50 +13:00
|
|
|
tmp_path = str(tmp_path)
|
|
|
|
with patch("appdirs.user_data_dir", return_value=tmp_path):
|
2022-12-20 11:54:34 +13:00
|
|
|
Completion("all").install()
|
2022-12-21 07:05:50 +13:00
|
|
|
assert Path(tmp_path + "/bash-completion/completions/bdfr").exists() == 1
|
|
|
|
assert Path(tmp_path + "/fish/vendor_completions.d/bdfr.fish").exists() == 1
|
|
|
|
assert Path(tmp_path + "/zsh/site-functions/_bdfr").exists() == 1
|
2022-12-20 11:54:34 +13:00
|
|
|
Completion("all").uninstall()
|
2022-12-21 07:05:50 +13:00
|
|
|
assert Path(tmp_path + "/bash-completion/completions/bdfr").exists() == 0
|
|
|
|
assert Path(tmp_path + "/fish/vendor_completions.d/bdfr.fish").exists() == 0
|
|
|
|
assert Path(tmp_path + "/zsh/site-functions/_bdfr").exists() == 0
|
2022-12-20 11:54:34 +13:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(sys.platform == "win32", reason="Completions are not currently supported on Windows.")
|
|
|
|
def test_cli_completion_bash(tmp_path: Path):
|
2022-12-21 07:05:50 +13:00
|
|
|
tmp_path = str(tmp_path)
|
|
|
|
with patch("appdirs.user_data_dir", return_value=tmp_path):
|
2022-12-20 11:54:34 +13:00
|
|
|
Completion("bash").install()
|
2022-12-21 07:05:50 +13:00
|
|
|
assert Path(tmp_path + "/bash-completion/completions/bdfr").exists() == 1
|
2022-12-20 11:54:34 +13:00
|
|
|
Completion("bash").uninstall()
|
2022-12-21 07:05:50 +13:00
|
|
|
assert Path(tmp_path + "/bash-completion/completions/bdfr").exists() == 0
|
2022-12-20 11:54:34 +13:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(sys.platform == "win32", reason="Completions are not currently supported on Windows.")
|
|
|
|
def test_cli_completion_fish(tmp_path: Path):
|
2022-12-21 07:05:50 +13:00
|
|
|
tmp_path = str(tmp_path)
|
|
|
|
with patch("appdirs.user_data_dir", return_value=tmp_path):
|
2022-12-20 11:54:34 +13:00
|
|
|
Completion("fish").install()
|
2022-12-21 07:05:50 +13:00
|
|
|
assert Path(tmp_path + "/fish/vendor_completions.d/bdfr.fish").exists() == 1
|
2022-12-20 11:54:34 +13:00
|
|
|
Completion("fish").uninstall()
|
2022-12-21 07:05:50 +13:00
|
|
|
assert Path(tmp_path + "/fish/vendor_completions.d/bdfr.fish").exists() == 0
|
2022-12-20 11:54:34 +13:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(sys.platform == "win32", reason="Completions are not currently supported on Windows.")
|
|
|
|
def test_cli_completion_zsh(tmp_path: Path):
|
2022-12-21 07:05:50 +13:00
|
|
|
tmp_path = str(tmp_path)
|
|
|
|
with patch("appdirs.user_data_dir", return_value=tmp_path):
|
2022-12-20 11:54:34 +13:00
|
|
|
Completion("zsh").install()
|
2022-12-21 07:05:50 +13:00
|
|
|
assert Path(tmp_path + "/zsh/site-functions/_bdfr").exists() == 1
|
2022-12-20 11:54:34 +13:00
|
|
|
Completion("zsh").uninstall()
|
2022-12-21 07:05:50 +13:00
|
|
|
assert Path(tmp_path + "/zsh/site-functions/_bdfr").exists() == 0
|