Skip to content
Open
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/docs/criteria_graphs/symbolic_equality_mermaid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/docs/criteria_graphs/symbolic_other_mermaid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/docs/criteria_graphs/symbolic_where_mermaid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/docs/criteria_graphs/symbolic_written_as_mermaid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 32 additions & 7 deletions app/evaluation_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,45 @@
Entry point for the `healthcheck` command of the deployed function.

The base image's healthcheck loads `TestEvaluationFunction` from this module
with `unittest`, so this wraps a run of the pytest suite in this directory
(`tests/`). Tests marked `@pytest.mark.slow` are left out so
the healthcheck stays within the request timeout; CI runs them all. pytest
doesn't collect `*_tests.py`, so this module isn't picked up by that run.
with `unittest`, so this wraps a run of the pytest suite in `tests/`. Tests
marked `@pytest.mark.slow` are left out so the healthcheck stays within the
request timeout; CI runs them all. pytest doesn't collect `*_tests.py`, so
this module isn't picked up by that run.

In the image, `tests/` also holds the base image's own tests, and its
`commands_test.py` calls the healthcheck, which would run this suite again,
without end. So only this repository's test files are passed to pytest, and
a nested run (from any other route back here) is skipped.
"""
import os
import unittest
from pathlib import Path

import pytest

TESTS_DIR = Path(__file__).resolve().parent / "tests"

# This repository's test files. The base image's (`commands_test.py`, `handling_test.py`, ...) don't match.
OWN_TEST_PATTERNS = ("evaluation*_test.py", "example_test.py", "*_evaluation_test.py", "*_preview_test.py")

# Set while the suite runs, so that a healthcheck started from inside it doesn't run it again
RUNNING_ENV_VAR = "COMPARE_EXPRESSIONS_HEALTHCHECK_RUNNING"


def own_test_files() -> list[str]:
"""The paths of this repository's test files in `tests/`, sorted."""
return sorted({str(path) for pattern in OWN_TEST_PATTERNS for path in TESTS_DIR.glob(pattern)})


class TestEvaluationFunction(unittest.TestCase):

def test_pytest_suite(self) -> None:
# The Lambda filesystem is read-only, so pytest's cache is disabled
exit_code = pytest.main([os.path.dirname(os.path.abspath(__file__)), "-q", "-m", "not slow", "-p", "no:cacheprovider"])
self.assertEqual(exit_code, pytest.ExitCode.OK)
if os.environ.get(RUNNING_ENV_VAR):
self.skipTest("The healthcheck suite is already running")
os.environ[RUNNING_ENV_VAR] = "1"
try:
# The Lambda filesystem is read-only, so pytest's cache is disabled
exit_code = pytest.main([*own_test_files(), "-q", "-m", "not slow", "-p", "no:cacheprovider"])
finally:
del os.environ[RUNNING_ENV_VAR]
self.assertEqual(exit_code, pytest.ExitCode.OK)