Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cidrblock committed Jun 3, 2024
1 parent 7c321b2 commit b232cc5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def test_no_option_string(
"""Test an argument without an option string.
Args:
<<<<<<< HEAD
capsys: Pytest fixture.
=======
capsys (pytest.CaptureFixture[str]): Pytest fixture.
>>>>>>> 556acba (Add some tests)
"""
parser = ArgumentParser(
formatter_class=CustomHelpFormatter,
Expand All @@ -36,7 +40,11 @@ def test_one_string(
"""Test an argument without an option string.
Args:
<<<<<<< HEAD
capsys: Pytest fixture.
=======
capsys (pytest.CaptureFixture[str]): Pytest fixture.
>>>>>>> 556acba (Add some tests)
"""
parser = ArgumentParser(
formatter_class=CustomHelpFormatter,
Expand All @@ -58,7 +66,11 @@ def test_too_many_string(
"""Test an argument with too many option strings.
Args:
<<<<<<< HEAD
monkeypatch: Pytest fixture.
=======
monkeypatch (pytest.MonkeyPatch): Pytest fixture.
>>>>>>> 556acba (Add some tests)
"""
monkeypatch.setattr("sys.argv", ["prog", "--help"])

Expand All @@ -80,7 +92,11 @@ def test_group_no_title(capsys: pytest.CaptureFixture[str]) -> None:
"""Test a group without a title.
Args:
<<<<<<< HEAD
capsys: Pytest fixture.
=======
capsys (pytest.CaptureFixture[str]): Pytest fixture.
>>>>>>> 556acba (Add some tests)
"""
parser = ArgumentParser(
formatter_class=CustomHelpFormatter,
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def main(cli: Cli) -> None:
"""Stub main function for testing.
Args:
<<<<<<< HEAD
cli: Cli object.
=======
cli (Cli): Cli object.
>>>>>>> 556acba (Add some tests)
"""
cli.parse_args()
cli.init_output()
Expand All @@ -24,7 +28,11 @@ def test_cpi(monkeypatch: pytest.MonkeyPatch) -> None:
"""Test the cpi option.
Args:
<<<<<<< HEAD
monkeypatch: Pytest fixture.
=======
monkeypatch (pytest.MonkeyPatch): Pytest fixture.
>>>>>>> 556acba (Add some tests)
"""
monkeypatch.setattr("sys.argv", ["ansible-dev-environment", "install", "--cpi"])
cli = Cli()
Expand All @@ -40,7 +48,11 @@ def test_tty(monkeypatch: pytest.MonkeyPatch) -> None:
"""Test term features with tty.
Args:
<<<<<<< HEAD
monkeypatch: Pytest fixture.
=======
monkeypatch (pytest.MonkeyPatch): Pytest fixture.
>>>>>>> 556acba (Add some tests)
"""
monkeypatch.setattr("sys.stdout.isatty", (lambda: True))
monkeypatch.setattr("os.environ", {"NO_COLOR": ""})
Expand Down Expand Up @@ -85,8 +97,12 @@ def test_editable_many(
"""Test the editable option with too many arguments.
Args:
<<<<<<< HEAD
capsys: Pytest stdout capture fixture.
monkeypatch: Pytest fixture.
=======
monkeypatch (pytest.MonkeyPatch): Pytest fixture.
>>>>>>> 556acba (Add some tests)
"""
monkeypatch.setattr(
"sys.argv",
Expand Down Expand Up @@ -143,7 +159,10 @@ def test_acp_env_var_set(
"""Test the ansible collection path environment variable set.
Args:
<<<<<<< HEAD
env_var: Environment variable name.
=======
>>>>>>> 556acba (Add some tests)
capsys: Pytest stdout capture fixture.
monkeypatch: Pytest fixture.
"""
Expand Down Expand Up @@ -200,6 +219,7 @@ def test_collections_in_user(
exists = Path.exists

def _exists(self: Path) -> bool:
<<<<<<< HEAD
"""Patch the exists method.
Args:
Expand All @@ -208,6 +228,9 @@ def _exists(self: Path) -> bool:
Returns:
bool: True if the path exists.
"""
=======
"""Patch the exists method."""
>>>>>>> 556acba (Add some tests)
if self == usr_path:
return True
return exists(self)
Expand All @@ -217,6 +240,7 @@ def _exists(self: Path) -> bool:
iterdir = Path.iterdir
def _iterdir(self: Path) -> list[Path] | Generator[Path, None, None]:
<<<<<<< HEAD
"""Patch the iterdir method.

Args:
Expand All @@ -225,6 +249,9 @@ def _iterdir(self: Path) -> list[Path] | Generator[Path, None, None]:
Returns:
List of paths or generator.
"""
=======
"""Patch the iterdir method."""
>>>>>>> 556acba (Add some tests)
if self == usr_path:
return [usr_path / "ansible_collections"]
return iterdir(self)
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_treemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ def collect_manifests(
Args:
target: Target path.
venv_cache_dir: Venv cache directory.
<<<<<<< HEAD
Returns:
Collection info.
=======
>>>>>>> 556acba (Add some tests)
"""
assert target
assert venv_cache_dir
Expand Down Expand Up @@ -126,9 +129,12 @@ def collect_manifests(
Args:
target: Target path.
venv_cache_dir: Venv cache directory.
<<<<<<< HEAD
Returns:
Collection info.
=======
>>>>>>> 556acba (Add some tests)
"""
assert target
assert venv_cache_dir
Expand Down Expand Up @@ -183,9 +189,12 @@ def collect_manifests(
Args:
target: Target path.
venv_cache_dir: Venv cache directory.
<<<<<<< HEAD
Returns:
Collection info.
=======
>>>>>>> 556acba (Add some tests)
"""
assert target
assert venv_cache_dir
Expand Down Expand Up @@ -238,9 +247,12 @@ def collect_manifests(
Args:
target: Target path.
venv_cache_dir: Venv cache directory.
<<<<<<< HEAD
Returns:
Collection info.
=======
>>>>>>> 556acba (Add some tests)
"""
assert target
assert venv_cache_dir
Expand Down

0 comments on commit b232cc5

Please sign in to comment.