Skip to content
Merged
Show file tree
Hide file tree
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
58 changes: 58 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Invoke is broken on Python 3.11
# https://github.com/pyinvoke/invoke/issues/833#issuecomment-1293148106
import inspect
import json
import os
import re
import sys
from pathlib import Path
from typing import Optional

if not hasattr(inspect, "getargspec"):
Expand Down Expand Up @@ -163,6 +165,7 @@ def lint(context):
def test_integration(
context,
focus=None,
full=False,
debug=False,
):
clean_itest_artifacts(context)
Expand All @@ -176,13 +179,17 @@ def test_integration(
focus_or_none = f"--filter {focus}" if focus else ""
debug_opts = "-vv --show-all" if debug else ""

full = full or _is_full_ci_test()
param_full_test = "--param HTML2PDF4DOC_FULL_TEST=1" if full else ""

# For now, the --threads are set to 1 because running tests parallelized
# will result in race conditions between Web Driver Manager downloading
# ChromeDriver.
itest_command = f"""
lit
--threads 1
--param HTML2PDF4DOC_EXEC="{html2pdf_exec}"
{param_full_test}
-v
{debug_opts}
{focus_or_none}
Expand Down Expand Up @@ -340,3 +347,54 @@ def test_docker(context, image: str = "html2pdf4doc:latest"):
"cd tests/integration/01_hello_world && html2pdf4doc print index.html /data/output/index.pdf"
),
)


def _is_full_ci_test() -> bool:
"""
Determine whether @full_test was requested in a GitHub CI run.
Returns True if the tag is found in PR body/title or commit message.
Returns False for local runs or when tag not found.
"""
event_name = os.getenv("GITHUB_EVENT_NAME")
event_path = os.getenv("GITHUB_EVENT_PATH")

# No GitHub env (e.g. local run)
if not event_name or not event_path or not Path(event_path).exists():
print( # noqa: T201
"[is_full_ci_test] No GitHub environment detected — running in local mode."
)
return False

try:
with open(event_path, encoding="utf-8") as f:
event = json.load(f)
except Exception as e:
print( # noqa: T201
f"[is_full_ci_test] Failed to parse event file: {e}"
)
return False

tag = "@full_test"

# Check PR body/title
if event_name == "pull_request":
pr = event.get("pull_request", {})
body = (pr.get("body") or "").lower()
title = (pr.get("title") or "").lower()
if tag in body or tag in title:
print( # noqa: T201
"[is_full_ci_test] Detected @full_test in PR body/title."
)
return True

# Check commit message
if event_name == "push":
commit_msg = (event.get("head_commit", {}).get("message") or "").lower()
if tag in commit_msg:
print( # noqa: T201
"[is_full_ci_test] Detected @full_test in commit message."
)
return True

print("[is_full_ci_test] @full_test not found.") # noqa: T201
return False
31 changes: 0 additions & 31 deletions tests/integration/lit.cfg

This file was deleted.

47 changes: 47 additions & 0 deletions tests/integration/lit.cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
from typing import Any

import lit.formats

config: Any
lit_config: Any

config.name = "html2pdf4doc Python API integration tests"
config.test_format = lit.formats.ShTest("0")

current_dir = os.getcwd()

html2pdf_exec = lit_config.params["HTML2PDF4DOC_EXEC"]
assert html2pdf_exec

config.substitutions.append(("%project_root", current_dir))
config.substitutions.append(("%html2pdf", html2pdf_exec))

config.substitutions.append(
(
"%check_exists",
'python "{}/tests/integration/check_exists.py"'.format(current_dir),
)
)
config.substitutions.append(
(
"%expect_exit",
'python "{}/tests/integration/expect_exit.py"'.format(current_dir),
)
)

config.suffixes = [".itest", ".c"]

config.is_windows = lit_config.isWindows
if not lit_config.isWindows:
config.available_features.add("PLATFORM_IS_NOT_WINDOWS")

is_full_test = lit_config.params.get("HTML2PDF4DOC_FULL_TEST", False)
if is_full_test:
config.available_features.add("FULL_TEST")

# In Linux CI, $HOME is required for Chrome as it needs to access things in ~/.local
config.environment["HOME"] = os.environ.get("HOME", "/tmp")

# In Windows CI, %ProgramW6432% is required for Selenium to properly detect browsers
config.environment["ProgramW6432"] = os.environ.get("ProgramW6432", "")
Loading