refactor: test utils and simplify the case code (#1136)

* doc(tests/README.md): explain the unit test process

* test(TempRepository): support to change origin and get filename

* refactor: simplify the case code

    * test_git_browse_ci.py
    * test_git_browse.py

* fix: rename `test_authors.py` to `test_git_authors.py`

* fix: typo

* fix: log the GitCommandError
This commit is contained in:
Leroy 2024-02-29 11:11:00 +08:00 committed by GitHub
parent 52897f73b9
commit a17d2fb15d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 256 additions and 299 deletions

View file

@ -12,7 +12,7 @@ The test part depends on:
So the versions are higher than above is recommended.
# How to test
# How to run the tests
1. Install `poetry`
2. Install the dependencies via `poetry install --no-root`
3. Run `poetry run pytest`
@ -26,6 +26,18 @@ It is done or go without `poetry`,
The second way maybe blocked the some missing dependencies at someday, so the first one is recommended.
# What and how to create a unit test
One command has a unit test, because one `git-*` command is just do one thing, so we can eat a piece of `git-*` command in one time.
For example,
1. The `git-alias` should have a test suite, so create `test_git_alias.py` in the directory `test`
2. Create a test class `TestGitAlias` in the `test_git_alias.py`
3. Create a test case `test_init`, and some test fixtures can be used, `temp_repo`, `named_temp_repo` etc.
* `temp_repo` is module scoped fixture which create a temporary directory and available in the test suite `test_git_alias.py`.
* `named_temp_repo` is just same as `temp_repo` except the custom directory renaming.
4. Loop the third step until the 100% coverage of the function of the `git-alias`
# References
* [poetry](https://github.com/python-poetry/poetry)
* [pytest](https://github.com/pytest-dev/pytest/)

View file

@ -1,10 +1,15 @@
import os, subprocess, shutil, tempfile
from git import Repo
from git import Repo, GitCommandError
from testpath import MockCommand, modified_env
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
GIT_EXTRAS_BIN = os.path.abspath(os.path.join(CURRENT_DIR, "..", "bin"))
GIT_EXTRAS_HELPER = os.path.abspath(os.path.join(CURRENT_DIR, "..", "helper"))
GITHUB_ORIGIN = "https://github.com/tj/git-extras.git"
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):
self._system_tmpdir = tempfile.gettempdir()
@ -16,6 +21,7 @@ class TempRepository:
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()
def switch_cwd_under_repo(self):
os.chdir(self._cwd)
@ -33,6 +39,10 @@ class TempRepository:
def get_file(self, index):
return self._files[index]
def get_filename(self, index):
file = self._files[index]
return file[1:]
def get_files(self):
return self._files
@ -98,3 +108,19 @@ class TempRepository:
script = [temp_extras_command, *params]
print(f"Run the script \"{script}\"")
return subprocess.run(script, capture_output=True)
def change_origin(self, origin_url):
try:
self._git_repo.git.remote("add", "origin", origin_url)
except GitCommandError as err:
print(err)
self._git_repo.git.remote("set-url", "origin", origin_url)
def change_origin_to_github(self):
self.change_origin(GITHUB_ORIGIN)
def change_origin_to_gitlab(self):
self.change_origin(GITLAB_ORIGIN)
def change_origin_to_bitbucket(self):
self.change_origin(BITBUCKET_ORIGIN)

View file

@ -1,231 +1,195 @@
import os, subprocess
from testpath import MockCommand, modified_env
github_origin = "https://github.com/tj/git-extras"
gitlab_origin = "https://gitlab.com/tj/git-extras"
bitbucket_origin = "https://bitbucket.org/tj/git-extras"
unknown_site_origin = "https://unknown-site.com/tj/git-extras"
UNKNOWN_SITE_ORIGIN = "https://unknown-site.com/tj/git-extras.git"
def set_origin_url(git, url):
git.remote("set-url", "origin", url + ".git")
def create_expected_filename(git, origin, mode, filename):
def get_file_uri(mode, filename, git):
commit_hash = git.rev_parse("HEAD")
connector = ""
if mode == "github":
connector = "/blob/"
return "https://github.com/tj/git-extras/blob/" + commit_hash + '/' + filename
if mode == "gitlab":
connector = "/-/blob/"
return "https://gitlab.com/tj/git-extras/-/blob/" + commit_hash + '/' + filename
if mode == "bitbucket":
connector = "/src/"
return origin + connector + 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()
git.remote("add", "origin", github_origin + ".git")
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "darwin" }):
with MockCommand("open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, github_origin, "github", tmp_file)
openCommand.assert_called([expected_url])
filename = temp_repo.get_filename(0)
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])
def test_browse_gitlab_file_on_mac(self, temp_repo):
temp_repo.change_origin_to_gitlab()
git = temp_repo.get_repo_git()
set_origin_url(git, gitlab_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "darwin" }):
with MockCommand("open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, gitlab_origin, "gitlab", tmp_file)
openCommand.assert_called([expected_url])
filename = temp_repo.get_filename(0)
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])
def test_browse_bitbucket_file_on_mac(self, temp_repo):
temp_repo.change_origin_to_bitbucket()
git = temp_repo.get_repo_git()
set_origin_url(git, bitbucket_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "darwin" }):
with MockCommand("open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, bitbucket_origin, "bitbucket", tmp_file)
openCommand.assert_called([expected_url])
filename = temp_repo.get_filename(0)
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])
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()
set_origin_url(git, github_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "msys" }):
with MockCommand("start") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, github_origin, "github", tmp_file)
openCommand.assert_called([expected_url])
filename = temp_repo.get_filename(0)
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])
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()
set_origin_url(git, gitlab_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "msys" }):
with MockCommand("start") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, gitlab_origin, "gitlab", tmp_file)
openCommand.assert_called([expected_url])
filename = temp_repo.get_filename(0)
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])
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()
set_origin_url(git, bitbucket_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "msys" }):
with MockCommand("start") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, bitbucket_origin, "bitbucket", tmp_file)
openCommand.assert_called([expected_url])
filename = temp_repo.get_filename(0)
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])
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()
set_origin_url(git, github_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "linux" }):
with MockCommand.fixed_output("uname", "microsoft"):
with MockCommand.fixed_output("command", "/powershell.exe"):
with MockCommand("powershell.exe") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, github_origin, "github", tmp_file)
openCommand.assert_called(["-NoProfile", "start", expected_url])
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:
temp_repo.invoke_extras_command("browse", "origin", filename)
expected_url = get_file_uri("github", filename, git)
openCommand.assert_called(["-NoProfile", "start", expected_url])
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()
set_origin_url(git, gitlab_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "linux" }):
with MockCommand.fixed_output("uname", "microsoft"):
with MockCommand.fixed_output("command", "/powershell.exe"):
with MockCommand("powershell.exe") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, gitlab_origin, "gitlab", tmp_file)
openCommand.assert_called(["-NoProfile", "start", expected_url])
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:
temp_repo.invoke_extras_command("browse", "origin", filename)
expected_url = get_file_uri("gitlab", filename, git)
openCommand.assert_called(["-NoProfile", "start", expected_url])
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()
set_origin_url(git, bitbucket_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "linux" }):
with MockCommand.fixed_output("uname", "microsoft"):
with MockCommand.fixed_output("command", "/powershell.exe"):
with MockCommand("powershell.exe") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, bitbucket_origin, "bitbucket", tmp_file)
openCommand.assert_called(["-NoProfile", "start", expected_url])
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:
temp_repo.invoke_extras_command("browse", "origin", filename)
expected_url = get_file_uri("bitbucket", filename, git)
openCommand.assert_called(["-NoProfile", "start", expected_url])
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()
set_origin_url(git, github_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "linux" }):
with MockCommand.fixed_output("uname", "no-micro-soft"):
with MockCommand.fixed_output("command", "/powershell.exe"):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, github_origin, "github", tmp_file)
openCommand.assert_called([expected_url])
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:
temp_repo.invoke_extras_command("browse", "origin", filename)
expected_url = get_file_uri("github", filename, git)
openCommand.assert_called([expected_url])
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()
set_origin_url(git, gitlab_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "linux" }):
with MockCommand.fixed_output("uname", "no-micro-soft"):
with MockCommand.fixed_output("command", "/powershell.exe"):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, gitlab_origin, "gitlab", tmp_file)
openCommand.assert_called([expected_url])
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:
temp_repo.invoke_extras_command("browse", "origin", filename)
expected_url = get_file_uri("gitlab", filename, git)
openCommand.assert_called([expected_url])
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()
set_origin_url(git, bitbucket_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "linux" }):
with MockCommand.fixed_output("uname", "no-micro-soft"):
with MockCommand.fixed_output("command", "/powershell.exe"):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, bitbucket_origin, "bitbucket", tmp_file)
openCommand.assert_called([expected_url])
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:
temp_repo.invoke_extras_command("browse", "origin", filename)
expected_url = get_file_uri("bitbucket", filename, git)
openCommand.assert_called([expected_url])
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()
set_origin_url(git, github_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "unique-system" }):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, github_origin, "github", tmp_file)
openCommand.assert_called([expected_url])
filename = temp_repo.get_filename(0)
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])
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()
set_origin_url(git, gitlab_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "unique-system" }):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, gitlab_origin, "gitlab", tmp_file)
openCommand.assert_called([expected_url])
filename = temp_repo.get_filename(0)
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])
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()
set_origin_url(git, bitbucket_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "unique-system" }):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:])
expected_url = create_expected_filename(git, bitbucket_origin, "bitbucket", tmp_file)
openCommand.assert_called([expected_url])
filename = temp_repo.get_filename(0)
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])
def test_browse_github_file_with_line_number(self, temp_repo):
temp_repo.change_origin_to_github()
git = temp_repo.get_repo_git()
set_origin_url(git, github_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "unique-system" }):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:], "10", "20")
expected_url = create_expected_filename(git, github_origin, "github", tmp_file)
openCommand.assert_called([expected_url + "#L10-20"])
filename = temp_repo.get_filename(0)
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"])
def test_browse_gitlab_file_with_line_number(self, temp_repo):
temp_repo.change_origin_to_gitlab()
git = temp_repo.get_repo_git()
set_origin_url(git, gitlab_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "unique-system" }):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:], "10", "20")
expected_url = create_expected_filename(git, gitlab_origin, "gitlab", tmp_file)
openCommand.assert_called([expected_url + "#L10-20"])
filename = temp_repo.get_filename(0)
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"])
def test_browse_github_file_with_line_number(self, temp_repo):
def test_browse_bitbucket_file_with_line_number(self, temp_repo):
temp_repo.change_origin_to_bitbucket()
git = temp_repo.get_repo_git()
set_origin_url(git, bitbucket_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "unique-system" }):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:], "10", "20")
expected_url = create_expected_filename(git, bitbucket_origin, "bitbucket", tmp_file)
openCommand.assert_called([expected_url + "#lines-10:20"])
filename = temp_repo.get_filename(0)
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"])
def test_browse_unknown_site_file(self, temp_repo):
temp_repo.change_origin(UNKNOWN_SITE_ORIGIN)
git = temp_repo.get_repo_git()
set_origin_url(git, unknown_site_origin)
with modified_env({ "OSTYPE": "unique-system" }):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin")
openCommand.assert_called([unknown_site_origin])
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()
set_origin_url(git, unknown_site_origin)
tmp_file = temp_repo.get_file(0)
with modified_env({ "OSTYPE": "unique-system" }):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse", "origin", tmp_file[1:], "10", "20")
openCommand.assert_called([unknown_site_origin])
filename = temp_repo.get_filename(0)
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]])

View file

@ -1,174 +1,129 @@
import os, subprocess
from testpath import MockCommand, modified_env
github_origin = "https://github.com/tj/git-extras"
gitlab_origin = "https://gitlab.com/tj/git-extras"
bitbucket_origin = "https://bitbucket.org/tj/git-extras"
unknown_site_origin = "https://unknown-site.com/tj/git-extras"
UNKNOWN_SITE_ORIGIN = "https://unknown-site.com/tj/git-extras.git"
def set_origin_url(git, url):
git.remote("set-url", "origin", url + ".git")
def create_expected_action_url(git, mode):
def get_ci_uri_by_domain(mode):
if mode == "github":
return github_origin + '/actions'
return "https://github.com/tj/git-extras/actions"
if mode == "gitlab":
return gitlab_origin + '/-/pipelines'
return "https://gitlab.com/tj/git-extras/-/pipelines"
if mode == "bitbucket":
return bitbucket_origin + '/addon/pipelines/home'
return "https://bitbucket.org/tj/git-extras/addon/pipelines/home"
class TestGitBrowse:
def test_browse_github_ci_on_mac(self, temp_repo):
git = temp_repo.get_repo_git()
git.remote("add", "origin", github_origin + ".git")
with modified_env({ "OSTYPE": "darwin" }):
with MockCommand("open") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "github")
openCommand.assert_called([expected_url])
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):
git = temp_repo.get_repo_git()
set_origin_url(git, gitlab_origin)
with modified_env({ "OSTYPE": "darwin" }):
with MockCommand("open") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "gitlab")
openCommand.assert_called([expected_url])
temp_repo.change_origin_to_gitlab()
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):
git = temp_repo.get_repo_git()
set_origin_url(git, bitbucket_origin)
with modified_env({ "OSTYPE": "darwin" }):
with MockCommand("open") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "bitbucket")
openCommand.assert_called([expected_url])
temp_repo.change_origin_to_bitbucket()
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):
git = temp_repo.get_repo_git()
set_origin_url(git, github_origin)
with modified_env({ "OSTYPE": "msys" }):
with MockCommand("start") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "github")
openCommand.assert_called([expected_url])
temp_repo.change_origin_to_github()
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):
git = temp_repo.get_repo_git()
set_origin_url(git, gitlab_origin)
with modified_env({ "OSTYPE": "msys" }):
with MockCommand("start") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "gitlab")
openCommand.assert_called([expected_url])
temp_repo.change_origin_to_gitlab()
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):
git = temp_repo.get_repo_git()
set_origin_url(git, bitbucket_origin)
with modified_env({ "OSTYPE": "msys" }):
with MockCommand("start") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "bitbucket")
openCommand.assert_called([expected_url])
temp_repo.change_origin_to_bitbucket()
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):
git = temp_repo.get_repo_git()
set_origin_url(git, github_origin)
with modified_env({ "OSTYPE": "linux" }):
with MockCommand.fixed_output("uname", "microsoft"):
with MockCommand.fixed_output("command", "/powershell.exe"):
with MockCommand("powershell.exe") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "github")
openCommand.assert_called(["-NoProfile", "start", expected_url])
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:
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):
git = temp_repo.get_repo_git()
set_origin_url(git, gitlab_origin)
with modified_env({ "OSTYPE": "linux" }):
with MockCommand.fixed_output("uname", "microsoft"):
with MockCommand.fixed_output("command", "/powershell.exe"):
with MockCommand("powershell.exe") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "gitlab")
openCommand.assert_called(["-NoProfile", "start", expected_url])
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:
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):
git = temp_repo.get_repo_git()
set_origin_url(git, bitbucket_origin)
with modified_env({ "OSTYPE": "linux" }):
with MockCommand.fixed_output("uname", "microsoft"):
with MockCommand.fixed_output("command", "/powershell.exe"):
with MockCommand("powershell.exe") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "bitbucket")
openCommand.assert_called(["-NoProfile", "start", expected_url])
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:
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):
git = temp_repo.get_repo_git()
set_origin_url(git, github_origin)
with modified_env({ "OSTYPE": "linux" }):
with MockCommand.fixed_output("uname", "no-micro-soft"):
with MockCommand.fixed_output("command", "/powershell.exe"):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "github")
openCommand.assert_called([expected_url])
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:
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):
git = temp_repo.get_repo_git()
set_origin_url(git, gitlab_origin)
with modified_env({ "OSTYPE": "linux" }):
with MockCommand.fixed_output("uname", "no-micro-soft"):
with MockCommand.fixed_output("command", "/powershell.exe"):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "gitlab")
openCommand.assert_called([expected_url])
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:
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):
git = temp_repo.get_repo_git()
set_origin_url(git, bitbucket_origin)
with modified_env({ "OSTYPE": "linux" }):
with MockCommand.fixed_output("uname", "no-micro-soft"):
with MockCommand.fixed_output("command", "/powershell.exe"):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "bitbucket")
openCommand.assert_called([expected_url])
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:
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):
git = temp_repo.get_repo_git()
set_origin_url(git, github_origin)
with modified_env({ "OSTYPE": "unique-system" }):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "github")
openCommand.assert_called([expected_url])
temp_repo.change_origin_to_github()
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):
git = temp_repo.get_repo_git()
set_origin_url(git, gitlab_origin)
with modified_env({ "OSTYPE": "unique-system" }):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "gitlab")
openCommand.assert_called([expected_url])
temp_repo.change_origin_to_gitlab()
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):
git = temp_repo.get_repo_git()
set_origin_url(git, bitbucket_origin)
with modified_env({ "OSTYPE": "unique-system" }):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
expected_url = create_expected_action_url(git, "bitbucket")
openCommand.assert_called([expected_url])
temp_repo.change_origin_to_bitbucket()
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):
git = temp_repo.get_repo_git()
set_origin_url(git, unknown_site_origin)
with modified_env({ "OSTYPE": "unique-system" }):
with MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
openCommand.assert_called([''])
temp_repo.change_origin(UNKNOWN_SITE_ORIGIN)
with modified_env({ "OSTYPE": "unique-system" }), MockCommand("xdg-open") as openCommand:
temp_repo.invoke_extras_command("browse-ci", "origin")
openCommand.assert_called([''])