Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@
calling the entry point produce equivalent output.
"""

import shutil
import subprocess
import sys
import sysconfig
from pathlib import Path
from typing import Optional

BINDIR = Path(sys.executable).parent
import pytest


def _get_entry_point() -> Optional[str]:
exe = shutil.which("trove-classifiers")
if exe:
return exe
candidates = [
Path(sysconfig.get_path("scripts")),
Path(sys.executable).parent,
Path(sys.executable).parent / "Scripts",
Path(sys.executable).parent / "bin",
]
for candidate_dir in candidates:
exe = shutil.which("trove-classifiers", path=str(candidate_dir))
if exe:
return exe
return None


def test_module_run():
Expand All @@ -16,17 +36,31 @@ def test_module_run():

def test_entry_point():
"""Simple test for no error when calling the entry point. Output is not validated."""
subprocess.check_call(f"{BINDIR}/trove-classifiers")
entry_point = _get_entry_point()
if not entry_point:
pytest.skip(
"trove-classifiers CLI entry point not found in PATH or scripts directory"
)
subprocess.check_call([entry_point])


def test_module_run_is_entry_point():
"""Compare that module run output is the same as entry point output."""
entry_point = _get_entry_point()
if not entry_point:
pytest.skip(
"trove-classifiers CLI entry point not found in PATH or scripts directory"
)
module_run_proc = subprocess.run(
[sys.executable, "-m", "trove_classifiers"],
capture_output=True,
encoding="utf-8",
check=True,
)
entry_point_proc = subprocess.run(
f"{BINDIR}/trove-classifiers", capture_output=True, encoding="utf-8"
[entry_point],
capture_output=True,
encoding="utf-8",
check=True,
)
assert module_run_proc.stdout == entry_point_proc.stdout