chore: Remove condition between default and exlude arguments

This commit is contained in:
Baptiste Roux
2023-02-07 16:50:45 +01:00
parent e796362e6b
commit 28881a23a9

View File

@@ -6,6 +6,7 @@ import tempfile
import pytest
import toml
import yaml
import re
from helpers import NonExistentPath, TempGitRepository, grm, shell
@@ -63,10 +64,10 @@ def test_repos_find_non_git_repos():
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("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:
shell(
f"""
@@ -100,15 +101,19 @@ def test_repos_find(configtype, exclude, default):
)
args = ["repos", "find", "local", tmpdir]
if not default:
if not default_format:
args += ["--format", configtype]
if exclude:
args += ["--exclude", exclude]
if exclude:
args += ["--exclude", exclude]
cmd = grm(args)
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)
elif configtype == "yaml":
output = yaml.safe_load(cmd.stdout)
@@ -123,9 +128,7 @@ def test_repos_find(configtype, exclude, default):
assert set(tree.keys()) == {"root", "repos"}
assert tree["root"] == tmpdir
assert isinstance(tree["repos"], list)
assert len(tree["repos"]) == (
1 if exclude == "^.*/repo2$" and not default else 2
)
assert len(tree["repos"]) == (1 if exclude == "^.*/repo2$" else 2)
repo1 = [r for r in tree["repos"] if r["name"] == "repo1"][0]
assert repo1["worktree_setup"] is False
@@ -142,7 +145,7 @@ def test_repos_find(configtype, exclude, default):
assert someremote["type"] == "ssh"
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"] == []
else:
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"
@pytest.mark.parametrize("default", [True, False])
@pytest.mark.parametrize("default_format", [True, False])
@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:
args = ["repos", "find", "local", repo_dir]
if not default:
if not default_format:
args += ["--format", configtype]
cmd = grm(args)
assert cmd.returncode == 0
assert len(cmd.stderr) == 0
if default or configtype == "toml":
if default_format or configtype == "toml":
output = toml.loads(cmd.stdout)
elif configtype == "yaml":
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("default", [True, False])
def test_repos_find_with_invalid_repo(configtype, default):
@pytest.mark.parametrize("default_format", [True, False])
def test_repos_find_with_invalid_repo(configtype, default_format):
with tempfile.TemporaryDirectory() as tmpdir:
shell(
f"""
@@ -237,13 +240,13 @@ def test_repos_find_with_invalid_repo(configtype, default):
)
args = ["repos", "find", "local", tmpdir]
if not default:
if not default_format:
args += ["--format", configtype]
cmd = grm(args)
assert cmd.returncode == 0
assert "broken" in cmd.stderr
if default or configtype == "toml":
if default_format or configtype == "toml":
output = toml.loads(cmd.stdout)
elif configtype == "yaml":
output = yaml.safe_load(cmd.stdout)