From ee4debc7256e29d9804ccc52b7c74d7e8f9f6405 Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Wed, 20 Nov 2024 23:33:01 +0100 Subject: [PATCH] tests/integration: make the cache folder local to a test folder --- strictdoc/core/project_config.py | 7 +++++++ tasks.py | 7 ++++++- .../html/precompiled_jinja_templates/01_basic/test.itest | 2 +- tests/integration/lit.cfg | 3 +++ tox.ini | 1 + 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/strictdoc/core/project_config.py b/strictdoc/core/project_config.py index ac6cd118a..46c0e72e3 100644 --- a/strictdoc/core/project_config.py +++ b/strictdoc/core/project_config.py @@ -111,7 +111,14 @@ def __init__( # Settings obtained from the strictdoc.toml config file. self.project_title: str = project_title self.dir_for_sdoc_assets: str = dir_for_sdoc_assets + + if env_cache_dir := os.environ.get("STRICTDOC_CACHE_DIR"): + # The only use case for STRICTDOC_CACHE_DIR is to make the cache + # local to an itest folder. + assert env_cache_dir == "Output/cache", env_cache_dir + dir_for_sdoc_cache = env_cache_dir self.dir_for_sdoc_cache: str = dir_for_sdoc_cache + self.project_features: List[str] = project_features self.server_host: str = server_host self.server_port: int = server_port diff --git a/tasks.py b/tasks.py index b61d1fdf6..49cee2fc8 100644 --- a/tasks.py +++ b/tasks.py @@ -5,7 +5,7 @@ import re import sys from enum import Enum -from typing import Optional +from typing import Optional, Dict if not hasattr(inspect, "getargspec"): inspect.getargspec = inspect.getfullargspec @@ -58,10 +58,13 @@ def run_invoke_with_tox( context, environment_type: ToxEnvironment, command: str, + environment: Optional[Dict] = None, ) -> invoke.runners.Result: assert isinstance(environment_type, ToxEnvironment) assert isinstance(command, str) + tox_py_version = f"py{sys.version_info.major}{sys.version_info.minor}" + return run_invoke( context, f""" @@ -69,6 +72,7 @@ def run_invoke_with_tox( -e {tox_py_version}-{environment_type.value} -- {command} """, + environment=environment, ) @@ -369,6 +373,7 @@ def test_integration( context, environment, itest_command, + environment={"STRICTDOC_CACHE_DIR": "Output/cache"}, ) diff --git a/tests/integration/commands/export/html/precompiled_jinja_templates/01_basic/test.itest b/tests/integration/commands/export/html/precompiled_jinja_templates/01_basic/test.itest index 519235ae8..e53172058 100644 --- a/tests/integration/commands/export/html/precompiled_jinja_templates/01_basic/test.itest +++ b/tests/integration/commands/export/html/precompiled_jinja_templates/01_basic/test.itest @@ -6,7 +6,7 @@ RUN: %strictdoc export %S --output-dir Output | filecheck %s --dump-input=fail CHECK: Compile Jinja templates {{.*}}s CHECK: Published: Hello world doc -RUN: rm -rf Output/ +RUN: rm -rf Output/html RUN: %strictdoc export %S --output-dir Output | filecheck %s --dump-input=fail --check-prefix=CHECK-SECOND CHECK-SECOND-NOT: Compile Jinja templates {{.*}}s diff --git a/tests/integration/lit.cfg b/tests/integration/lit.cfg index 79ec48c3a..8a60a3b3b 100644 --- a/tests/integration/lit.cfg +++ b/tests/integration/lit.cfg @@ -47,3 +47,6 @@ if "TEST_HTML2PDF" in lit_config.params: chromedriver = lit_config.params['CHROMEDRIVER'] config.substitutions.append(('%chromedriver', chromedriver)) config.available_features.add('SYSTEM_CHROMEDRIVER') + +if (env_cache_dir := os.getenv('STRICTDOC_CACHE_DIR', None)) is not None: + config.environment['STRICTDOC_CACHE_DIR'] = env_cache_dir diff --git a/tox.ini b/tox.ini index 2e5b98ee1..b62942667 100644 --- a/tox.ini +++ b/tox.ini @@ -29,6 +29,7 @@ deps = -rrequirements.check.txt pass_env= CHROMEWEBDRIVER + STRICTDOC_CACHE_DIR commands = python developer/pip_install_strictdoc_deps.py {posargs}