Skip to content

Commit

Permalink
Tests: fix doctests and actually run them
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Savchenko authored and asfaltboy committed Jul 29, 2019
1 parent e946a54 commit e75d18c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 31 deletions.
12 changes: 6 additions & 6 deletions bitbucket/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def remote_to_url(remote):
"""
Parse out a Bitbucket HTTP URL from a remote URI:
r1 = remote_to_url("git://bitbucket.org/pasha_savchenko/GitSavvy.git")
assert r1 == "https://bitbucket.org/asfaltboy/GitSavvy"
>>> remote_to_url("git://bitbucket.org/pasha_savchenko/GitSavvy.git")
'https://bitbucket.org/pasha_savchenko/GitSavvy'
r2 = remote_to_url("git@bitbucket.org:pasha_savchenko/gitsavvy.git")
assert r2 == "https://bitbucket.org/asfaltboy/GitSavvy"
>>> remote_to_url("git@bitbucket.org:pasha_savchenko/gitsavvy.git")
'https://bitbucket.org/pasha_savchenko/gitsavvy'
r3 = remote_to_url("https://pasha_savchenko@bitbucket.org/pasha_savchenko/GitSavvy.git")
assert r3 == "https://pasha_savchenko@bitbucket.org/pasha_savchenko/GitSavvy"
>>> remote_to_url("https://pasha_savchenko@bitbucket.org/pasha_savchenko/GitSavvy.git")
'https://pasha_savchenko@bitbucket.org/pasha_savchenko/GitSavvy'
"""

if remote.endswith(".git"):
Expand Down
12 changes: 6 additions & 6 deletions github/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def remote_to_url(remote):
"""
Parse out a Github HTTP URL from a remote URI:
r1 = remote_to_url("git://github.com/divmain/GitSavvy.git")
assert r1 == "https://github.com/divmain/GitSavvy.git"
>>> r1 = remote_to_url("git://github.com/divmain/GitSavvy.git")
>>> assert r1 == "https://github.com/divmain/GitSavvy"
r2 = remote_to_url("git@github.com:divmain/GitSavvy.git")
assert r2 == "https://github.com/divmain/GitSavvy.git"
>>> r2 = remote_to_url("git@github.com:divmain/GitSavvy.git")
>>> assert r2 == "https://github.com/divmain/GitSavvy"
r3 = remote_to_url("https://github.com/divmain/GitSavvy.git")
assert r3 == "https://github.com/divmain/GitSavvy.git"
>>> r3 = remote_to_url("https://github.com/divmain/GitSavvy.git")
>>> assert r3 == "https://github.com/divmain/GitSavvy"
"""

if remote.endswith(".git"):
Expand Down
36 changes: 17 additions & 19 deletions gitlab/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ def remote_to_url(remote):
"""
Parse out a GitLab HTTP URL from a remote URI:
r1 = remote_to_url("git://gitlab.com/asfaltboy/GitSavvy.git")
assert r1 == "https://gitlab.com/asfaltboy/GitSavvy.git"
r2 = remote_to_url("git@gitlab.com:asfaltboy/GitSavvy.git")
assert r2 == "https://gitlab.com/asfaltboy/GitSavvy.git"
r3 = remote_to_url("https://gitlab.com/asfaltboy/GitSavvy.git")
assert r3 == "https://gitlab.com/asfaltboy/GitSavvy.git"
>>> remote_to_url("git://gitlab.com/asfaltboy/GitSavvy.git")
'https://gitlab.com/asfaltboy/GitSavvy'
>>> remote_to_url("git@gitlab.com:asfaltboy/GitSavvy.git")
'https://gitlab.com/asfaltboy/GitSavvy'
>>> remote_to_url("https://gitlab.com/asfaltboy/GitSavvy.git")
'https://gitlab.com/asfaltboy/GitSavvy'
"""

if remote.endswith(".git"):
Expand Down Expand Up @@ -83,14 +81,14 @@ def open_file_in_browser(rel_path, remote, commit_hash, start_line=None, end_lin
"""
Open the URL corresponding to the provided `rel_path` on `remote`.
"""
github_repo = parse_remote(remote)
if not github_repo:
gitlab_repo = parse_remote(remote)
if not gitlab_repo:
return None

line_numbers = "#L{}-{}".format(start_line, end_line) if start_line is not None else ""

url = "{repo_url}/blob/{commit_hash}/{path}{lines}".format(
repo_url=github_repo.url,
repo_url=gitlab_repo.url,
commit_hash=commit_hash,
path=rel_path,
lines=line_numbers
Expand All @@ -101,22 +99,22 @@ def open_file_in_browser(rel_path, remote, commit_hash, start_line=None, end_lin

def open_repo(remote):
"""
Open the GitHub repo in a new browser window, given the specified remote.
Open the GitLab repo in a new browser window, given the specified remote.
"""
github_repo = parse_remote(remote)
if not github_repo:
gitlab_repo = parse_remote(remote)
if not gitlab_repo:
return None
open_in_browser(github_repo.url)
open_in_browser(gitlab_repo.url)


def open_issues(remote):
"""
Open the GitHub issues in a new browser window, given the specified remote.
Open the GitLab issues in a new browser window, given the specified remote.
"""
github_repo = parse_remote(remote)
if not github_repo:
gitlab_repo = parse_remote(remote)
if not gitlab_repo:
return None
open_in_browser("{}/issues".format(github_repo.url))
open_in_browser("{}/issues".format(gitlab_repo.url))


def get_api_fqdn(gitlab_repo):
Expand Down
Empty file added tests/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions tests/test_docstrings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import doctest
import pkgutil

import GitSavvy


def load_tests(loader, tests, ignore):
package_iterator = pkgutil.walk_packages(GitSavvy.__path__, 'GitSavvy.')

for pkg_loader, module_name, is_pkg in package_iterator:

if module_name.startswith('GitSavvy.tests'):
continue

module = pkg_loader.find_module(module_name).load_module(module_name)

try:
module_tests = doctest.DocTestSuite(module)
except ValueError:
continue

tests.addTests(module_tests)

return tests

0 comments on commit e75d18c

Please sign in to comment.