Fix test_mercurial.py (black, node_id and git->hg)
@@ -8,9 +8,7 @@ import pytest
from repo2docker.contentproviders import Mercurial
-skipif_py35 = pytest.mark.skipif(
- sys.version_info < (3, 6), reason="requires python3.6"
-)
+skipif_py35 = pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6")
def _add_content_to_hg(repo_dir):
@@ -23,33 +21,33 @@ def _add_content_to_hg(repo_dir):
subprocess.check_call(["hg", "commit", "-m", "Test commit"], cwd=repo_dir)
-def _get_sha1(repo_dir):
- """Get repository's current commit SHA1."""
- sha1 = subprocess.Popen(
- ["hg", "identify"], stdout=subprocess.PIPE, cwd=repo_dir
+def _get_node_id(repo_dir):
+ """Get repository's current commit node ID (currently SHA1)."""
+ node_id = subprocess.Popen(
+ ["hg", "identify", "-i"], stdout=subprocess.PIPE, cwd=repo_dir
)
- return sha1.stdout.read().decode().strip()
+ return node_id.stdout.read().decode().strip()
@pytest.fixture()
def hg_repo():
"""
- Make a dummy git repo in which user can perform git operations
+ Make a dummy hg repo in which user can perform hg operations
Should be used as a contextmanager, it will delete directory when done
"""
- with TemporaryDirectory() as gitdir:
- subprocess.check_call(["hg", "init"], cwd=gitdir)
- yield gitdir
+ with TemporaryDirectory() as hgdir:
+ subprocess.check_call(["hg", "init"], cwd=hgdir)
+ yield hgdir
@pytest.fixture()
def hg_repo_with_content(hg_repo):
"""Create a hg repository with content"""
_add_content_to_hg(hg_repo)
- sha1 = _get_sha1(hg_repo)
+ node_id = _get_node_id(hg_repo)
- yield hg_repo, sha1
+ yield hg_repo, node_id
@skipif_py35
@@ -68,7 +66,7 @@ def test_detect_mercurial(hg_repo_with_content, repo_with_content):
@skipif_py35
def test_clone(hg_repo_with_content):
"""Test simple hg clone to a target dir"""
- upstream, sha1 = hg_repo_with_content
+ upstream, node_id = hg_repo_with_content
with TemporaryDirectory() as clone_dir:
spec = {"repo": upstream}
@@ -77,7 +75,7 @@ def test_clone(hg_repo_with_content):
pass
assert (Path(clone_dir) / "test").exists()
- assert mercurial.content_id == sha1[:7]
+ assert mercurial.content_id == node_id
@skipif_py35
@@ -85,7 +83,7 @@ def test_bad_ref(hg_repo_with_content):
"""
Test trying to checkout a ref that doesn't exist
"""
- upstream, sha1 = hg_repo_with_content
+ upstream, node_id = hg_repo_with_content
with TemporaryDirectory() as clone_dir:
spec = {"repo": upstream, "ref": "does-not-exist"}
with pytest.raises(ValueError):
