From 65203312c16e34399f4067060be0e2f420d79013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Mon, 25 Nov 2024 14:32:54 +0800 Subject: [PATCH] Revert "feat: add ruff linter with ci check (#1178)" (#1181) This reverts commit a2c424aadaac31f17e4c956251e724360705999f. --- .github/workflows/ci.yml | 2 - tests/conftest.py | 6 +- tests/helper.py | 14 ++--- tests/pyproject.toml | 63 ------------------- tests/test_git_abort.py | 1 - tests/test_git_archive_file.py | 32 +++++----- tests/test_git_authors.py | 5 +- tests/test_git_browse.py | 108 +++++++++------------------------ tests/test_git_browse_ci.py | 84 +++++++------------------ 9 files changed, 74 insertions(+), 241 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b6da920c..cbe0153f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,8 +27,6 @@ jobs: readarray -t changed_files <<<"$(jq -r '.[]' <<<'${{ steps.files.outputs.added_modified }}')" ~/go/bin/editorconfig-checker ${changed_files[@]} - - name: Lint and format Python with Ruff - uses: astral-sh/ruff-action@v1 typo: runs-on: ubuntu-latest diff --git a/tests/conftest.py b/tests/conftest.py index 3f39517f2..74c91c8aa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,15 +4,13 @@ import pytest from helper import TempRepository - -def create_repo(dirname=None): +def create_repo(dirname = None): repo = TempRepository(dirname) tmp_file_a = repo.create_tmp_file() tmp_file_b = repo.create_tmp_file() repo.switch_cwd_under_repo() return repo - def init_repo_git_status(repo): git = repo.get_repo_git() git.add(".") @@ -20,14 +18,12 @@ def init_repo_git_status(repo): git.config("--local", "user.email", "test@git-extras.com") git.commit("-m", "chore: initial commit") - @pytest.fixture(scope="module") def temp_repo(): repo = create_repo() init_repo_git_status(repo) return repo - @pytest.fixture(scope="module") def named_temp_repo(request): dirname = request.param diff --git a/tests/helper.py b/tests/helper.py index d71ed8d6d..1c9349f9e 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -10,16 +10,15 @@ GITLAB_ORIGIN = "https://gitlab.com/tj/git-extras.git" BITBUCKET_ORIGIN = "https://bitbucket.org/tj/git-extras.git" - class TempRepository: - def __init__(self, repo_work_dir=None): + def __init__(self, repo_work_dir = None): self._system_tmpdir = tempfile.gettempdir() if repo_work_dir == None: repo_work_dir = tempfile.mkdtemp() else: repo_work_dir = os.path.join(self._system_tmpdir, repo_work_dir) self._cwd = repo_work_dir - self._tempdirname = self._cwd[len(self._system_tmpdir) + 1 :] + self._tempdirname = self._cwd[len(self._system_tmpdir) + 1:] self._git_repo = Repo.init(repo_work_dir, b="default") self._files = [] self.change_origin_to_github() @@ -51,7 +50,7 @@ def create_tmp_dir(self): tmp_dir = tempfile.mkdtemp() return tmp_dir - def create_tmp_file(self, temp_dir=None): + def create_tmp_file(self, temp_dir = None): if temp_dir == None: temp_dir = self._cwd @@ -87,9 +86,8 @@ def invoke_installed_extras_command(self, name, *params): origin_extras_command = os.path.join(GIT_EXTRAS_BIN, command_name) temp_extras_command = os.path.join(self._cwd, command_name) helpers = [ - os.path.join(GIT_EXTRAS_HELPER, "git-extra-utility"), - os.path.join(GIT_EXTRAS_HELPER, "is-git-repo"), - ] + os.path.join(GIT_EXTRAS_HELPER, "git-extra-utility"), + os.path.join(GIT_EXTRAS_HELPER, "is-git-repo")] if not os.path.exists(temp_extras_command): whole = [] @@ -108,7 +106,7 @@ def invoke_installed_extras_command(self, name, *params): os.chmod(temp_extras_command, 0o775) script = [temp_extras_command, *params] - print(f'Run the script "{script}"') + print(f"Run the script \"{script}\"") return subprocess.run(script, capture_output=True) def change_origin(self, origin_url): diff --git a/tests/pyproject.toml b/tests/pyproject.toml index f12d4871f..43266570e 100644 --- a/tests/pyproject.toml +++ b/tests/pyproject.toml @@ -21,66 +21,3 @@ testpaths = ["."] [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" - -[tool.ruff] -# Exclude a variety of commonly ignored directories. -exclude = [ - ".bzr", - ".direnv", - ".eggs", - ".git", - ".git-rewrite", - ".hg", - ".ipynb_checkpoints", - ".mypy_cache", - ".nox", - ".pants.d", - ".pyenv", - ".pytest_cache", - ".pytype", - ".ruff_cache", - ".svn", - ".tox", - ".venv", - ".vscode", - "__pypackages__", - "_build", - "buck-out", - "build", - "dist", - "node_modules", - "site-packages", - "venv", -] - -# Same as Black. -line-length = 88 -indent-width = 4 - -# Assume Python 3.9 -target-version = "py39" - -[tool.ruff.lint] -# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. -select = ["E4", "E7", "E9", "F"] -ignore = [] - -# Allow fix for all enabled rules (when `--fix`) is provided. -fixable = ["ALL"] -unfixable = [] - -# Allow unused variables when underscore-prefixed. -dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" - -[tool.ruff.format] -# Like Black, use double quotes for strings. -quote-style = "double" - -# Like Black, indent with spaces, rather than tabs. -indent-style = "space" - -# Like Black, respect magic trailing commas. -skip-magic-trailing-comma = false - -# Like Black, automatically detect the appropriate line ending. -line-ending = "auto" diff --git a/tests/test_git_abort.py b/tests/test_git_abort.py index 1e3785fe4..38e52c574 100644 --- a/tests/test_git_abort.py +++ b/tests/test_git_abort.py @@ -1,6 +1,5 @@ from git import GitCommandError - class TestGitAbort: def test_init(self, temp_repo): git = temp_repo.get_repo_git() diff --git a/tests/test_git_archive_file.py b/tests/test_git_archive_file.py index 86ef5323a..687432221 100644 --- a/tests/test_git_archive_file.py +++ b/tests/test_git_archive_file.py @@ -1,6 +1,5 @@ import os, pytest - class TestGitArchiveFile: def test_init(self, temp_repo): git = temp_repo.get_repo_git() @@ -17,17 +16,14 @@ def test_archive_file_on_tags_branch(self, temp_repo): filename = "{0}.{1}.zip".format(temp_repo.get_repo_dirname(), git.describe()) assert filename in os.listdir() - def test_archive_file_on_any_not_tags_branch_without_default_branch( - self, temp_repo - ): + def test_archive_file_on_any_not_tags_branch_without_default_branch(self, temp_repo): git = temp_repo.get_repo_git() git.checkout("-b", "not-tags-branch") temp_repo.invoke_installed_extras_command("archive-file") filename = "{0}.{1}.{2}.zip".format( - temp_repo.get_repo_dirname(), - git.describe("--always", "--long"), - "not-tags-branch", - ) + temp_repo.get_repo_dirname(), + git.describe("--always", "--long"), + "not-tags-branch") assert filename in os.listdir() def test_archive_file_on_any_not_tags_branch_with_default_branch(self, temp_repo): @@ -36,8 +32,8 @@ def test_archive_file_on_any_not_tags_branch_with_default_branch(self, temp_repo git.config("git-extras.default-branch", "default") temp_repo.invoke_installed_extras_command("archive-file") filename = "{0}.{1}.zip".format( - temp_repo.get_repo_dirname(), git.describe("--always", "--long") - ) + temp_repo.get_repo_dirname(), + git.describe("--always", "--long")) assert filename in os.listdir() def test_archive_file_on_branch_name_has_slash(self, temp_repo): @@ -45,10 +41,9 @@ def test_archive_file_on_branch_name_has_slash(self, temp_repo): git.checkout("-b", "feature/slash") temp_repo.invoke_installed_extras_command("archive-file") filename = "{0}.{1}.{2}.zip".format( - temp_repo.get_repo_dirname(), - git.describe("--always", "--long"), - "feature-slash", - ) + temp_repo.get_repo_dirname(), + git.describe("--always", "--long"), + "feature-slash") assert filename in os.listdir() @pytest.mark.parametrize("named_temp_repo", ["backslash\\dir"], indirect=True) @@ -56,8 +51,9 @@ def test_archive_file_on_dirname_has_backslash(self, named_temp_repo): named_temp_repo.invoke_installed_extras_command("archive-file") git = named_temp_repo.get_repo_git() filename = "{0}.{1}.{2}.zip".format( - "backslash-dir", git.describe("--always", "--long"), "default" - ) + "backslash-dir", + git.describe("--always", "--long"), + "default") assert filename in os.listdir() def test_archive_file_on_tag_name_has_slash(self, temp_repo): @@ -69,6 +65,6 @@ def test_archive_file_on_tag_name_has_slash(self, temp_repo): temp_repo.invoke_installed_extras_command("archive-file") description_include_version = git.describe("--always", "--long") filename = "{0}.{1}.zip".format( - temp_repo.get_repo_dirname(), description_include_version.replace("/", "-") - ) + temp_repo.get_repo_dirname(), + description_include_version.replace("/", "-")) assert filename in os.listdir() diff --git a/tests/test_git_authors.py b/tests/test_git_authors.py index 45038c3e0..8eb3cf9ac 100644 --- a/tests/test_git_authors.py +++ b/tests/test_git_authors.py @@ -1,12 +1,9 @@ import os, subprocess -expected_authors_list = ( - "test \ntestagain \n" -) +expected_authors_list = "test \ntestagain \n" expected_authors_list_without_email = "test\ntestagain\n" authors_file = "AUTHORS" - class TestGitAuthors: def test_init(self, temp_repo): git = temp_repo.get_repo_git() diff --git a/tests/test_git_browse.py b/tests/test_git_browse.py index 1d015a22f..ff4b4db9c 100644 --- a/tests/test_git_browse.py +++ b/tests/test_git_browse.py @@ -3,22 +3,20 @@ UNKNOWN_SITE_ORIGIN = "https://unknown-site.com/tj/git-extras.git" - def get_file_uri(mode, filename, git): commit_hash = git.rev_parse("HEAD") if mode == "github": - return "https://github.com/tj/git-extras/blob/" + commit_hash + "/" + filename + return "https://github.com/tj/git-extras/blob/" + commit_hash + '/' + filename if mode == "gitlab": - return "https://gitlab.com/tj/git-extras/-/blob/" + commit_hash + "/" + filename + return "https://gitlab.com/tj/git-extras/-/blob/" + commit_hash + '/' + filename if mode == "bitbucket": - return "https://bitbucket.org/tj/git-extras/src/" + commit_hash + "/" + filename - + return "https://bitbucket.org/tj/git-extras/src/" + commit_hash + '/' + filename class TestGitBrowse: def test_browse_github_file_on_mac(self, temp_repo): git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with modified_env({"OSTYPE": "darwin"}), MockCommand("open") as openCommand: + with modified_env({ "OSTYPE": "darwin" }), MockCommand("open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("github", filename, git) openCommand.assert_called([expected_url]) @@ -27,7 +25,7 @@ def test_browse_gitlab_file_on_mac(self, temp_repo): temp_repo.change_origin_to_gitlab() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with modified_env({"OSTYPE": "darwin"}), MockCommand("open") as openCommand: + with modified_env({ "OSTYPE": "darwin" }), MockCommand("open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("gitlab", filename, git) openCommand.assert_called([expected_url]) @@ -36,7 +34,7 @@ def test_browse_bitbucket_file_on_mac(self, temp_repo): temp_repo.change_origin_to_bitbucket() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with modified_env({"OSTYPE": "darwin"}), MockCommand("open") as openCommand: + with modified_env({ "OSTYPE": "darwin" }), MockCommand("open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("bitbucket", filename, git) openCommand.assert_called([expected_url]) @@ -45,7 +43,7 @@ def test_browse_github_file_on_git_bash_on_window(self, temp_repo): temp_repo.change_origin_to_github() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with modified_env({"OSTYPE": "msys"}), MockCommand("start") as openCommand: + with modified_env({ "OSTYPE": "msys" }), MockCommand("start") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("github", filename, git) openCommand.assert_called([expected_url]) @@ -54,7 +52,7 @@ def test_browse_gitlab_file_on_git_bash_on_window(self, temp_repo): temp_repo.change_origin_to_gitlab() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with modified_env({"OSTYPE": "msys"}), MockCommand("start") as openCommand: + with modified_env({ "OSTYPE": "msys" }), MockCommand("start") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("gitlab", filename, git) openCommand.assert_called([expected_url]) @@ -63,7 +61,7 @@ def test_browse_bitbucket_file_on_git_bash_on_window(self, temp_repo): temp_repo.change_origin_to_bitbucket() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with modified_env({"OSTYPE": "msys"}), MockCommand("start") as openCommand: + with modified_env({ "OSTYPE": "msys" }), MockCommand("start") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("bitbucket", filename, git) openCommand.assert_called([expected_url]) @@ -72,12 +70,8 @@ def test_browse_github_file_on_WSL_with_microsoft_key(self, temp_repo): temp_repo.change_origin_to_github() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "linux"}), - MockCommand.fixed_output("uname", "microsoft"), - MockCommand.fixed_output("command", "/powershell.exe"), - MockCommand("powershell.exe") as openCommand, - ): + with modified_env({ "OSTYPE": "linux" }), MockCommand.fixed_output("uname", "microsoft"), \ + MockCommand.fixed_output("command", "/powershell.exe"), MockCommand("powershell.exe") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("github", filename, git) openCommand.assert_called(["-NoProfile", "start", expected_url]) @@ -86,12 +80,8 @@ def test_browse_gitlab_file_on_WSL_with_microsoft_key(self, temp_repo): temp_repo.change_origin_to_gitlab() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "linux"}), - MockCommand.fixed_output("uname", "microsoft"), - MockCommand.fixed_output("command", "/powershell.exe"), - MockCommand("powershell.exe") as openCommand, - ): + with modified_env({ "OSTYPE": "linux" }), MockCommand.fixed_output("uname", "microsoft"), \ + MockCommand.fixed_output("command", "/powershell.exe"), MockCommand("powershell.exe") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("gitlab", filename, git) openCommand.assert_called(["-NoProfile", "start", expected_url]) @@ -100,12 +90,8 @@ def test_browse_bitbucket_file_on_WSL_with_microsoft_key(self, temp_repo): temp_repo.change_origin_to_bitbucket() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "linux"}), - MockCommand.fixed_output("uname", "microsoft"), - MockCommand.fixed_output("command", "/powershell.exe"), - MockCommand("powershell.exe") as openCommand, - ): + with modified_env({ "OSTYPE": "linux" }), MockCommand.fixed_output("uname", "microsoft"), \ + MockCommand.fixed_output("command", "/powershell.exe"), MockCommand("powershell.exe") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("bitbucket", filename, git) openCommand.assert_called(["-NoProfile", "start", expected_url]) @@ -114,12 +100,8 @@ def test_browse_github_file_on_WSL_without_microsoft_key(self, temp_repo): temp_repo.change_origin_to_github() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "linux"}), - MockCommand.fixed_output("uname", "no-micro-soft"), - MockCommand.fixed_output("command", "/powershell.exe"), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "linux" }), MockCommand.fixed_output("uname", "no-micro-soft"), \ + MockCommand.fixed_output("command", "/powershell.exe"), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("github", filename, git) openCommand.assert_called([expected_url]) @@ -128,12 +110,8 @@ def test_browse_gitlab_file_on_WSL_without_microsoft_key(self, temp_repo): temp_repo.change_origin_to_gitlab() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "linux"}), - MockCommand.fixed_output("uname", "no-micro-soft"), - MockCommand.fixed_output("command", "/powershell.exe"), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "linux" }), MockCommand.fixed_output("uname", "no-micro-soft"), \ + MockCommand.fixed_output("command", "/powershell.exe"), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("gitlab", filename, git) openCommand.assert_called([expected_url]) @@ -142,12 +120,8 @@ def test_browse_bitbucket_file_on_WSL_without_microsoft_key(self, temp_repo): temp_repo.change_origin_to_bitbucket() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "linux"}), - MockCommand.fixed_output("uname", "no-micro-soft"), - MockCommand.fixed_output("command", "/powershell.exe"), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "linux" }), MockCommand.fixed_output("uname", "no-micro-soft"), \ + MockCommand.fixed_output("command", "/powershell.exe"), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("bitbucket", filename, git) openCommand.assert_called([expected_url]) @@ -156,10 +130,7 @@ def test_browse_github_file_not_mac_or_msys_or_linux(self, temp_repo): temp_repo.change_origin_to_github() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "unique-system"}), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("github", filename, git) openCommand.assert_called([expected_url]) @@ -168,10 +139,7 @@ def test_browse_gitlab_file_not_mac_or_msys_or_linux(self, temp_repo): temp_repo.change_origin_to_gitlab() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "unique-system"}), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("gitlab", filename, git) openCommand.assert_called([expected_url]) @@ -180,10 +148,7 @@ def test_browse_bitbucket_file_not_mac_or_msys_or_linux(self, temp_repo): temp_repo.change_origin_to_bitbucket() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "unique-system"}), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename) expected_url = get_file_uri("bitbucket", filename, git) openCommand.assert_called([expected_url]) @@ -192,10 +157,7 @@ def test_browse_github_file_with_line_number(self, temp_repo): temp_repo.change_origin_to_github() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "unique-system"}), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename, "10", "20") expected_url = get_file_uri("github", filename, git) openCommand.assert_called([expected_url + "#L10-L20"]) @@ -204,10 +166,7 @@ def test_browse_gitlab_file_with_line_number(self, temp_repo): temp_repo.change_origin_to_gitlab() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "unique-system"}), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename, "10", "20") expected_url = get_file_uri("gitlab", filename, git) openCommand.assert_called([expected_url + "#L10-20"]) @@ -216,10 +175,7 @@ def test_browse_bitbucket_file_with_line_number(self, temp_repo): temp_repo.change_origin_to_bitbucket() git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "unique-system"}), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename, "10", "20") expected_url = get_file_uri("bitbucket", filename, git) openCommand.assert_called([expected_url + "#lines-10:20"]) @@ -227,19 +183,13 @@ def test_browse_bitbucket_file_with_line_number(self, temp_repo): def test_browse_unknown_site_file(self, temp_repo): temp_repo.change_origin(UNKNOWN_SITE_ORIGIN) git = temp_repo.get_repo_git() - with ( - modified_env({"OSTYPE": "unique-system"}), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse", "origin") openCommand.assert_called([UNKNOWN_SITE_ORIGIN[0:-4]]) def test_browse_unknown_site_file_with_line_number(self, temp_repo): git = temp_repo.get_repo_git() filename = temp_repo.get_filename(0) - with ( - modified_env({"OSTYPE": "unique-system"}), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse", "origin", filename, "10", "20") openCommand.assert_called([UNKNOWN_SITE_ORIGIN[0:-4]]) diff --git a/tests/test_git_browse_ci.py b/tests/test_git_browse_ci.py index 66dea46f2..761d86d64 100644 --- a/tests/test_git_browse_ci.py +++ b/tests/test_git_browse_ci.py @@ -3,7 +3,6 @@ UNKNOWN_SITE_ORIGIN = "https://unknown-site.com/tj/git-extras.git" - def get_ci_uri_by_domain(mode): if mode == "github": return "https://github.com/tj/git-extras/actions" @@ -12,156 +11,119 @@ def get_ci_uri_by_domain(mode): if mode == "bitbucket": return "https://bitbucket.org/tj/git-extras/addon/pipelines/home" - class TestGitBrowse: def test_browse_github_ci_on_mac(self, temp_repo): - with modified_env({"OSTYPE": "darwin"}), MockCommand("open") as openCommand: + with modified_env({ "OSTYPE": "darwin" }), MockCommand("open") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("github") openCommand.assert_called([expected_url]) def test_browse_gitlab_ci_on_mac(self, temp_repo): temp_repo.change_origin_to_gitlab() - with modified_env({"OSTYPE": "darwin"}), MockCommand("open") as openCommand: + with modified_env({ "OSTYPE": "darwin" }), MockCommand("open") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("gitlab") openCommand.assert_called([expected_url]) def test_browse_bitbucket_ci_on_mac(self, temp_repo): temp_repo.change_origin_to_bitbucket() - with modified_env({"OSTYPE": "darwin"}), MockCommand("open") as openCommand: + with modified_env({ "OSTYPE": "darwin" }), MockCommand("open") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("bitbucket") openCommand.assert_called([expected_url]) def test_browse_github_ci_on_git_bash_on_window(self, temp_repo): temp_repo.change_origin_to_github() - with modified_env({"OSTYPE": "msys"}), MockCommand("start") as openCommand: + with modified_env({ "OSTYPE": "msys" }), MockCommand("start") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("github") openCommand.assert_called([expected_url]) def test_browse_gitlab_ci_on_git_bash_on_window(self, temp_repo): temp_repo.change_origin_to_gitlab() - with modified_env({"OSTYPE": "msys"}), MockCommand("start") as openCommand: + with modified_env({ "OSTYPE": "msys" }), MockCommand("start") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("gitlab") openCommand.assert_called([expected_url]) def test_browse_bitbucket_ci_on_git_bash_on_window(self, temp_repo): temp_repo.change_origin_to_bitbucket() - with modified_env({"OSTYPE": "msys"}), MockCommand("start") as openCommand: + with modified_env({ "OSTYPE": "msys" }), MockCommand("start") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("bitbucket") openCommand.assert_called([expected_url]) def test_browse_github_ci_on_WSL_with_microsoft_key(self, temp_repo): temp_repo.change_origin_to_github() - with ( - modified_env({"OSTYPE": "linux"}), - MockCommand.fixed_output("uname", "microsoft"), - MockCommand.fixed_output("command", "/powershell.exe"), - MockCommand("powershell.exe") as openCommand, - ): + with modified_env({ "OSTYPE": "linux" }), MockCommand.fixed_output("uname", "microsoft"), \ + MockCommand.fixed_output("command", "/powershell.exe"), MockCommand("powershell.exe") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("github") openCommand.assert_called(["-NoProfile", "start", expected_url]) def test_browse_gitlab_ci_on_WSL_with_microsoft_key(self, temp_repo): temp_repo.change_origin_to_gitlab() - with ( - modified_env({"OSTYPE": "linux"}), - MockCommand.fixed_output("uname", "microsoft"), - MockCommand.fixed_output("command", "/powershell.exe"), - MockCommand("powershell.exe") as openCommand, - ): + with modified_env({ "OSTYPE": "linux" }), MockCommand.fixed_output("uname", "microsoft"), \ + MockCommand.fixed_output("command", "/powershell.exe"), MockCommand("powershell.exe") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("gitlab") openCommand.assert_called(["-NoProfile", "start", expected_url]) def test_browse_bitbucket_ci_on_WSL_with_microsoft_key(self, temp_repo): temp_repo.change_origin_to_bitbucket() - with ( - modified_env({"OSTYPE": "linux"}), - MockCommand.fixed_output("uname", "microsoft"), - MockCommand.fixed_output("command", "/powershell.exe"), - MockCommand("powershell.exe") as openCommand, - ): + with modified_env({ "OSTYPE": "linux" }), MockCommand.fixed_output("uname", "microsoft"), \ + MockCommand.fixed_output("command", "/powershell.exe"), MockCommand("powershell.exe") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("bitbucket") openCommand.assert_called(["-NoProfile", "start", expected_url]) def test_browse_github_ci_on_WSL_without_microsoft_key(self, temp_repo): temp_repo.change_origin_to_github() - with ( - modified_env({"OSTYPE": "linux"}), - MockCommand.fixed_output("uname", "no-micro-soft"), - MockCommand.fixed_output("command", "/powershell.exe"), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "linux" }), MockCommand.fixed_output("uname", "no-micro-soft"), \ + MockCommand.fixed_output("command", "/powershell.exe"), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("github") openCommand.assert_called([expected_url]) def test_browse_gitlab_ci_on_WSL_without_microsoft_key(self, temp_repo): temp_repo.change_origin_to_gitlab() - with ( - modified_env({"OSTYPE": "linux"}), - MockCommand.fixed_output("uname", "no-micro-soft"), - MockCommand.fixed_output("command", "/powershell.exe"), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "linux" }), MockCommand.fixed_output("uname", "no-micro-soft"), \ + MockCommand.fixed_output("command", "/powershell.exe"), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("gitlab") openCommand.assert_called([expected_url]) def test_browse_bitbucket_ci_on_WSL_without_microsoft_key(self, temp_repo): temp_repo.change_origin_to_bitbucket() - with ( - modified_env({"OSTYPE": "linux"}), - MockCommand.fixed_output("uname", "no-micro-soft"), - MockCommand.fixed_output("command", "/powershell.exe"), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "linux" }), MockCommand.fixed_output("uname", "no-micro-soft"), \ + MockCommand.fixed_output("command", "/powershell.exe"), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("bitbucket") openCommand.assert_called([expected_url]) def test_browse_github_ci_not_mac_or_msys_or_linux(self, temp_repo): temp_repo.change_origin_to_github() - with ( - modified_env({"OSTYPE": "unique-system"}), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("github") openCommand.assert_called([expected_url]) def test_browse_gitlab_ci_not_mac_or_msys_or_linux(self, temp_repo): temp_repo.change_origin_to_gitlab() - with ( - modified_env({"OSTYPE": "unique-system"}), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("gitlab") openCommand.assert_called([expected_url]) def test_browse_bitbucket_ci_not_mac_or_msys_or_linux(self, temp_repo): temp_repo.change_origin_to_bitbucket() - with ( - modified_env({"OSTYPE": "unique-system"}), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") expected_url = get_ci_uri_by_domain("bitbucket") openCommand.assert_called([expected_url]) def test_browse_unknown_site_file(self, temp_repo): temp_repo.change_origin(UNKNOWN_SITE_ORIGIN) - with ( - modified_env({"OSTYPE": "unique-system"}), - MockCommand("xdg-open") as openCommand, - ): + with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand: temp_repo.invoke_extras_command("browse-ci", "origin") - openCommand.assert_called([""]) + openCommand.assert_called([''])