chore: Remove condition between default and exlude arguments
This commit is contained in:
@@ -6,6 +6,7 @@ import tempfile
|
|||||||
import pytest
|
import pytest
|
||||||
import toml
|
import toml
|
||||||
import yaml
|
import yaml
|
||||||
|
import re
|
||||||
from helpers import NonExistentPath, TempGitRepository, grm, shell
|
from helpers import NonExistentPath, TempGitRepository, grm, shell
|
||||||
|
|
||||||
|
|
||||||
@@ -63,10 +64,10 @@ def test_repos_find_non_git_repos():
|
|||||||
assert len(cmd.stderr) != 0
|
assert len(cmd.stderr) != 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("default", [True, False])
|
@pytest.mark.parametrize("default_format", [True, False])
|
||||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||||
@pytest.mark.parametrize("exclude", [None, "^.*/repo2$", "^not_matching$"])
|
@pytest.mark.parametrize("exclude", [None, "^.*/repo2$", "^not_matching$"])
|
||||||
def test_repos_find(configtype, exclude, default):
|
def test_repos_find(configtype, exclude, default_format):
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
shell(
|
shell(
|
||||||
f"""
|
f"""
|
||||||
@@ -100,15 +101,19 @@ def test_repos_find(configtype, exclude, default):
|
|||||||
)
|
)
|
||||||
|
|
||||||
args = ["repos", "find", "local", tmpdir]
|
args = ["repos", "find", "local", tmpdir]
|
||||||
if not default:
|
if not default_format:
|
||||||
args += ["--format", configtype]
|
args += ["--format", configtype]
|
||||||
if exclude:
|
if exclude:
|
||||||
args += ["--exclude", exclude]
|
args += ["--exclude", exclude]
|
||||||
cmd = grm(args)
|
cmd = grm(args)
|
||||||
assert cmd.returncode == 0
|
assert cmd.returncode == 0
|
||||||
assert len(cmd.stderr) == (37 if exclude == "^.*/repo2$" and not default else 0)
|
if exclude == "^.*/repo2$":
|
||||||
|
assert re.match(r"^.*\[skipped\] .*\/repo2$", cmd.stderr.lower())
|
||||||
|
assert "repo2" in cmd.stderr.lower()
|
||||||
|
else:
|
||||||
|
assert len(cmd.stderr) == 0
|
||||||
|
|
||||||
if default or configtype == "toml":
|
if default_format or configtype == "toml":
|
||||||
output = toml.loads(cmd.stdout)
|
output = toml.loads(cmd.stdout)
|
||||||
elif configtype == "yaml":
|
elif configtype == "yaml":
|
||||||
output = yaml.safe_load(cmd.stdout)
|
output = yaml.safe_load(cmd.stdout)
|
||||||
@@ -123,9 +128,7 @@ def test_repos_find(configtype, exclude, default):
|
|||||||
assert set(tree.keys()) == {"root", "repos"}
|
assert set(tree.keys()) == {"root", "repos"}
|
||||||
assert tree["root"] == tmpdir
|
assert tree["root"] == tmpdir
|
||||||
assert isinstance(tree["repos"], list)
|
assert isinstance(tree["repos"], list)
|
||||||
assert len(tree["repos"]) == (
|
assert len(tree["repos"]) == (1 if exclude == "^.*/repo2$" else 2)
|
||||||
1 if exclude == "^.*/repo2$" and not default else 2
|
|
||||||
)
|
|
||||||
|
|
||||||
repo1 = [r for r in tree["repos"] if r["name"] == "repo1"][0]
|
repo1 = [r for r in tree["repos"] if r["name"] == "repo1"][0]
|
||||||
assert repo1["worktree_setup"] is False
|
assert repo1["worktree_setup"] is False
|
||||||
@@ -142,7 +145,7 @@ def test_repos_find(configtype, exclude, default):
|
|||||||
assert someremote["type"] == "ssh"
|
assert someremote["type"] == "ssh"
|
||||||
assert someremote["url"] == "ssh://example.com/repo2.git"
|
assert someremote["url"] == "ssh://example.com/repo2.git"
|
||||||
|
|
||||||
if exclude == "^.*/repo2$" and not default:
|
if exclude == "^.*/repo2$":
|
||||||
assert [r for r in tree["repos"] if r["name"] == "repo2"] == []
|
assert [r for r in tree["repos"] if r["name"] == "repo2"] == []
|
||||||
else:
|
else:
|
||||||
repo2 = [r for r in tree["repos"] if r["name"] == "repo2"][0]
|
repo2 = [r for r in tree["repos"] if r["name"] == "repo2"][0]
|
||||||
@@ -156,19 +159,19 @@ def test_repos_find(configtype, exclude, default):
|
|||||||
assert origin["url"] == "https://example.com/repo2.git"
|
assert origin["url"] == "https://example.com/repo2.git"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("default", [True, False])
|
@pytest.mark.parametrize("default_format", [True, False])
|
||||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||||
def test_repos_find_in_root(configtype, default):
|
def test_repos_find_in_root(configtype, default_format):
|
||||||
with TempGitRepository() as repo_dir:
|
with TempGitRepository() as repo_dir:
|
||||||
|
|
||||||
args = ["repos", "find", "local", repo_dir]
|
args = ["repos", "find", "local", repo_dir]
|
||||||
if not default:
|
if not default_format:
|
||||||
args += ["--format", configtype]
|
args += ["--format", configtype]
|
||||||
cmd = grm(args)
|
cmd = grm(args)
|
||||||
assert cmd.returncode == 0
|
assert cmd.returncode == 0
|
||||||
assert len(cmd.stderr) == 0
|
assert len(cmd.stderr) == 0
|
||||||
|
|
||||||
if default or configtype == "toml":
|
if default_format or configtype == "toml":
|
||||||
output = toml.loads(cmd.stdout)
|
output = toml.loads(cmd.stdout)
|
||||||
elif configtype == "yaml":
|
elif configtype == "yaml":
|
||||||
output = yaml.safe_load(cmd.stdout)
|
output = yaml.safe_load(cmd.stdout)
|
||||||
@@ -202,8 +205,8 @@ def test_repos_find_in_root(configtype, default):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
@pytest.mark.parametrize("configtype", ["toml", "yaml"])
|
||||||
@pytest.mark.parametrize("default", [True, False])
|
@pytest.mark.parametrize("default_format", [True, False])
|
||||||
def test_repos_find_with_invalid_repo(configtype, default):
|
def test_repos_find_with_invalid_repo(configtype, default_format):
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
shell(
|
shell(
|
||||||
f"""
|
f"""
|
||||||
@@ -237,13 +240,13 @@ def test_repos_find_with_invalid_repo(configtype, default):
|
|||||||
)
|
)
|
||||||
|
|
||||||
args = ["repos", "find", "local", tmpdir]
|
args = ["repos", "find", "local", tmpdir]
|
||||||
if not default:
|
if not default_format:
|
||||||
args += ["--format", configtype]
|
args += ["--format", configtype]
|
||||||
cmd = grm(args)
|
cmd = grm(args)
|
||||||
assert cmd.returncode == 0
|
assert cmd.returncode == 0
|
||||||
assert "broken" in cmd.stderr
|
assert "broken" in cmd.stderr
|
||||||
|
|
||||||
if default or configtype == "toml":
|
if default_format or configtype == "toml":
|
||||||
output = toml.loads(cmd.stdout)
|
output = toml.loads(cmd.stdout)
|
||||||
elif configtype == "yaml":
|
elif configtype == "yaml":
|
||||||
output = yaml.safe_load(cmd.stdout)
|
output = yaml.safe_load(cmd.stdout)
|
||||||
|
|||||||
Reference in New Issue
Block a user