|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import subprocess |
| 4 | +import sys |
| 5 | +import sysconfig |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +import pytest |
| 9 | + |
| 10 | +if sys.version_info < (3, 10): |
| 11 | + from importlib_metadata import distribution |
| 12 | +else: |
| 13 | + from importlib.metadata import distribution |
| 14 | + |
| 15 | +import s5cmd |
| 16 | + |
| 17 | +from . import push_argv |
| 18 | + |
| 19 | +all_tools = pytest.mark.parametrize("tool", ["s5cmd"]) |
| 20 | + |
| 21 | + |
| 22 | +def _run(program, args): |
| 23 | + func = getattr(s5cmd, program) |
| 24 | + args = [f"{program}.py", *args] |
| 25 | + with push_argv(args), pytest.raises(SystemExit) as excinfo: |
| 26 | + func() |
| 27 | + assert excinfo.value.code == 0 |
| 28 | + |
| 29 | + |
| 30 | +@all_tools |
| 31 | +def test_module(tool): |
| 32 | + _run(tool, ["version"]) |
| 33 | + |
| 34 | + |
| 35 | +def _get_scripts(): |
| 36 | + dist = distribution("s5cmd") |
| 37 | + scripts_paths = [ |
| 38 | + Path(sysconfig.get_path("scripts", scheme)).resolve() |
| 39 | + for scheme in sysconfig.get_scheme_names() |
| 40 | + ] |
| 41 | + scripts = [] |
| 42 | + for file in dist.files: |
| 43 | + if file.locate().parent.resolve(strict=True) in scripts_paths: |
| 44 | + scripts.append(file.locate().resolve(strict=True)) |
| 45 | + return scripts |
| 46 | + |
| 47 | + |
| 48 | +@all_tools |
| 49 | +def test_package_script(tool): |
| 50 | + expected_version = "2.2.2" |
| 51 | + scripts = [script for script in _get_scripts() if script.stem == tool] |
| 52 | + assert len(scripts) == 1 |
| 53 | + output = subprocess.check_output([str(scripts[0]), "version"]).decode("ascii") |
| 54 | + # Output of the form "vX.Y.Z-SHA{N}" |
| 55 | + assert output.splitlines()[0].split("-")[0] == f"v{expected_version}" |
0 commit comments