Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Reichl <thetredev@gmail.com>
  • Loading branch information
thetredev committed Oct 8, 2023
1 parent 17a83ee commit 15c9ba8
Show file tree
Hide file tree
Showing 12 changed files with 328 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
bin
html
**/.pytest_cache
**/__pycache__
15 changes: 15 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

# note: tests will run with 'latest' version of xdeb for now
# because tests/test_xdeb.py installs 'latest' last

mkdir -p html
PYTEST_TEST_REPORT_ARGS="--html=html/test-report.html --self-contained-html"

if [ "${1}" = "html" ]; then
pytest ${PYTEST_TEST_REPORT_ARGS}
else
pytest
fi
Empty file added tests/__init__.py
Empty file.
124 changes: 124 additions & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
from pathlib import Path


DEB_NONEXISTENT_PACKAGE = "DEFINITELY-NON-EXISTENT-PACKAGE"


XDEB_BINARY_PATH = Path("/usr/local/bin/xdeb")
XDEB_RELEASES = (
"1.0",
"1.1",
"1.2",
"1.3"
)

XDEB_INSTALL_BINARY_PATH = Path(__file__).parent.parent.joinpath("bin", "xdeb-install-linux-x86_64")

XDEB_INSTALL_PROVIDERS = (
"debian.org",
"linuxmint.com",
"ubuntu.com",
"microsoft.com",
"google.com",
)

XDEB_INSTALL_HAVE_PACKAGE = {
"speedcrunch": {
"debian.org": {
"any": True,
"distributions": {
"bookworm": True,
"bookworm-backports": False,
"bullseye": True,
"bullseye-backports": False,
"buster": True,
"buster-backports": False,
"sid": True,
"testing": True,
"testing-backports": False
},
},
"linuxmint.com": {
"any": False
},
"ubuntu.com": {
"any": True,
"distributions": {
"bionic": True,
"focal": True,
"jammy": True
}
},
"microsoft.com": {
"any": False
},
"google.com": {
"any": False
},
},
"vscode": {
"debian.org": {
"any": False
},
"linuxmint.com": {
"any": False
},
"ubuntu.com": {
"any": False
},
"microsoft.com": {
"any": True,
"distributions": {
"current": True
}
},
"google.com": {
"any": False
}
},
"google-chrome": {
"debian.org": {
"any": False
},
"linuxmint.com": {
"any": False
},
"ubuntu.com": {
"any": False
},
"microsoft.com": {
"any": False
},
"google.com": {
"any": True,
"distributions": {
"current": True
}
}
},
"google-chrome-unstable": {
"debian.org": {
"any": False
},
"linuxmint.com": {
"any": False
},
"ubuntu.com": {
"any": False
},
"microsoft.com": {
"any": False
},
"google.com": {
"any": True,
"distributions": {
"current": True
}
}
}
}

XDEB_INSTALL_PACKAGE_MAP = {
"vscode": "code",
"google-chrome": "google-chrome-stable"
}
35 changes: 35 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import subprocess

from . import constants


def assert_xdeb_install_command(*args):
subprocess.check_call([constants.XDEB_INSTALL_BINARY_PATH, *args])


def assert_command_assume_yes(returncode: int, *args):
process = subprocess.run(*args, input="yes\n".encode(), stdout=subprocess.PIPE)
assert process.returncode == returncode


def assert_xdeb_install_xbps(returncode: int, *args):
assert_command_assume_yes(returncode, [constants.XDEB_INSTALL_BINARY_PATH, *args])

if returncode == 0:
package = args[-1] if args[-1] not in constants.XDEB_INSTALL_PACKAGE_MAP else constants.XDEB_INSTALL_PACKAGE_MAP[args[-1]]
assert_command_assume_yes(0, ["sudo", "xbps-remove", package])
assert_command_assume_yes(0, ["sudo", "xbps-remove", "-Oo"])


def assert_xdeb_installation(version: str = None):
# remove any previous xdeb binary
subprocess.check_call(["sudo", "rm", "-rf", constants.XDEB_BINARY_PATH])

# install xdeb version
args = ["xdeb"]

if version is not None:
args.append(version)

assert_xdeb_install_command(*args)
subprocess.check_call([constants.XDEB_BINARY_PATH, "-h"])
13 changes: 13 additions & 0 deletions tests/test_00_general.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

from . import helpers


@pytest.mark.order(0)
def test_version():
helpers.assert_xdeb_install_command("--version")


@pytest.mark.order(1)
def test_help():
helpers.assert_xdeb_install_command("--help")
14 changes: 14 additions & 0 deletions tests/test_10_xdeb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest

from . import constants
from . import helpers


@pytest.mark.order(10)
def test_xdeb():
helpers.assert_xdeb_installation()

for release in constants.XDEB_RELEASES:
helpers.assert_xdeb_installation(release)

helpers.assert_xdeb_installation("latest")
12 changes: 12 additions & 0 deletions tests/test_20_providers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest
from . import helpers


@pytest.mark.order(20)
def test_providers():
helpers.assert_xdeb_install_command("providers")


@pytest.mark.order(21)
def test_providers_details():
helpers.assert_xdeb_install_command("providers", "--details")
20 changes: 20 additions & 0 deletions tests/test_30_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from . import constants
from . import helpers


@pytest.mark.order(30)
def test_sync():
helpers.assert_xdeb_install_command("sync")


@pytest.mark.order(31)
def test_sync_single():
for provider in constants.XDEB_INSTALL_PROVIDERS:
helpers.assert_xdeb_install_command("sync", provider)


@pytest.mark.order(32)
def test_sync_each():
helpers.assert_xdeb_install_command("sync", *constants.XDEB_INSTALL_PROVIDERS)
42 changes: 42 additions & 0 deletions tests/test_40_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import subprocess
import pytest

from . import constants
from . import helpers


@pytest.mark.order(40)
def test_search_nothing():
with pytest.raises(subprocess.CalledProcessError):
helpers.assert_xdeb_install_command("search")


@pytest.mark.order(41)
def test_search_nonexistent():
with pytest.raises(subprocess.CalledProcessError):
helpers.assert_xdeb_install_command("search", constants.DEB_NONEXISTENT_PACKAGE)


@pytest.mark.order(42)
def test_search_speedcrunch():
helpers.assert_xdeb_install_command("search", "speedcrunch")


@pytest.mark.order(43)
def test_search_packages():
for package, provider_data in constants.XDEB_INSTALL_HAVE_PACKAGE.items():
for provider, data in provider_data.items():
if not data["any"]:
with pytest.raises(subprocess.CalledProcessError):
helpers.assert_xdeb_install_command("search", "--provider", provider, package)
continue

helpers.assert_xdeb_install_command("search", "--provider", provider, package)

for distribution, available in data["distributions"].items():
if not available:
with pytest.raises(subprocess.CalledProcessError):
helpers.assert_xdeb_install_command("search", "--provider", provider, "--distribution", distribution, package)
continue

helpers.assert_xdeb_install_command("search", "--provider", provider, "--distribution", distribution, package)
37 changes: 37 additions & 0 deletions tests/test_50_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest

from . import constants
from . import helpers


@pytest.mark.order(51)
def test_install_nothing():
helpers.assert_xdeb_install_xbps(1)


@pytest.mark.order(52)
def test_install_nonexistent():
helpers.assert_xdeb_install_xbps(1, constants.DEB_NONEXISTENT_PACKAGE)


@pytest.mark.order(53)
def test_install_speedcrunch():
helpers.assert_xdeb_install_xbps(0, "speedcrunch")


@pytest.mark.order(54)
def test_install_packages():
for package, provider_data in constants.XDEB_INSTALL_HAVE_PACKAGE.items():
for provider, data in provider_data.items():
if not data["any"]:
helpers.assert_xdeb_install_xbps(1, "--provider", provider, package)
continue

helpers.assert_xdeb_install_xbps(0, "--provider", provider, package)

for distribution, available in data["distributions"].items():
if not available:
helpers.assert_xdeb_install_xbps(1, "--provider", provider, "--distribution", distribution, package)
continue

helpers.assert_xdeb_install_xbps(0, "--provider", provider, "--distribution", distribution, package)
13 changes: 13 additions & 0 deletions tests/test_60_clean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

from . import helpers


@pytest.mark.order(60)
def test_clean():
helpers.assert_xdeb_install_command("clean")


@pytest.mark.order(61)
def test_clean_lists():
helpers.assert_xdeb_install_command("clean", "--lists")

0 comments on commit 15c9ba8

Please sign in to comment.