diff --git a/.github/workflows/production-deploy.yml b/.github/workflows/production-deploy.yml index 92570dd..012eb0c 100644 --- a/.github/workflows/production-deploy.yml +++ b/.github/workflows/production-deploy.yml @@ -42,7 +42,7 @@ jobs: environment: "production" version-bump: ${{ inputs.version-bump }} branch: ${{ inputs.branch }} - run-database-tests: false + run-database-tests: true seed: ${{ inputs.seed }} request_delay: ${{ inputs.request_delay }} max_concurrency: ${{ inputs.max_concurrency }} diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml index 5e12dc2..4a8443b 100644 --- a/.github/workflows/staging-deploy.yml +++ b/.github/workflows/staging-deploy.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8"] + python-version: ["3.12"] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/test-lint.yml b/.github/workflows/test-lint.yml new file mode 100644 index 0000000..0f1e91d --- /dev/null +++ b/.github/workflows/test-lint.yml @@ -0,0 +1,55 @@ +name: Test and Lint + +on: + pull_request: + +jobs: + test: + name: Test + runs-on: ubuntu-latest + permissions: + contents: read + actions: read + checks: write + pull-requests: write + strategy: + fail-fast: false + matrix: + python-version: ["3.12"] + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + id: python-setup + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m venv .venv + .venv/bin/pip install pytest + .venv/bin/pip install -r app/requirements.txt + + - name: Lint with flake8 + run: | + source .venv/bin/activate + .venv/bin/pip install flake8 + # stop the build if there are Python syntax errors or undefined names + flake8 ./app --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 ./app --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + + - name: Run tests + if: always() + run: | + source .venv/bin/activate + pytest --junit-xml=./reports/pytest.xml --tb=auto -v + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-results-${{ matrix.python-version }} + path: ./reports/pytest.xml + if-no-files-found: warn \ No newline at end of file diff --git a/README.md b/README.md index ac8bc9b..6d49acf 100755 --- a/README.md +++ b/README.md @@ -19,9 +19,9 @@ This evaluation function compares physical quantities submitted by students agai app/ __init__.py evaluation.py # Main evaluation function - evaluation_test.py # Unit tests + evaluation_tests.py # Unit tests preview.py # Preview function - preview_test.py # Preview tests + preview_tests.py # Preview tests expression_utilities.py # Expression parsing utilities unit_system_conversions.py # Unit conversion logic static_unit_conversion_arrays.py # Pre-generated conversion data diff --git a/app/Dockerfile b/app/Dockerfile index c32d85a..0291cfe 100755 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -1,22 +1,28 @@ -# Base image that bundles AWS Lambda Python 3.8 image with some middleware functions -# FROM base-eval-tmp -FROM ghcr.io/lambda-feedback/baseevalutionfunctionlayer:main-3.8 +# Base image that bundles the AWS Lambda Python image with the lambda-feedback middleware (app.handler) +FROM ghcr.io/lambda-feedback/baseevalutionfunctionlayer:main-3.12 + +# The 3.12 image is Amazon Linux 2023, which doesn't ship `find` (used below). +# git is needed to pip install latex2sympy from GitHub. +RUN dnf install -y git findutils && dnf clean all WORKDIR /app -RUN yum install -y git +ENV PYTHONPATH=/app # Copy and install any packages/modules needed for your evaluation script. COPY requirements.txt . RUN pip3 install -r requirements.txt +# The healthcheck command runs the pytest suite +RUN pip3 install pytest + # Copy the evaluation and testing scripts COPY evaluation.py ./app/ -COPY evaluation_test.py ./app/ +COPY evaluation_tests.py ./app/ # Copy the preview and testing scripts COPY preview.py ./app/ -COPY preview_test.py ./app/ +COPY preview_tests.py ./app/ # Copy additional files COPY static_unit_conversion_arrays.py ./app/ @@ -30,5 +36,6 @@ COPY docs/user.md ./app/docs/user.md RUN chmod 644 $(find . -type f) RUN chmod 755 $(find . -type d) -# The entrypoint for AWS is to invoke the handler function within the app package -CMD [ "/app/app.handler" ] +# The entrypoint for AWS is to invoke the handler function within the app package. +# Python 3.12's Lambda runtime imports this as a module name, so it can't be a path. +CMD [ "app.handler" ] diff --git a/app/evaluation_test.py b/app/evaluation_tests.py similarity index 100% rename from app/evaluation_test.py rename to app/evaluation_tests.py diff --git a/app/preview_test.py b/app/preview_tests.py similarity index 100% rename from app/preview_test.py rename to app/preview_tests.py diff --git a/app/requirements.txt b/app/requirements.txt index 1f9031a..670bf6a 100755 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,5 +1,5 @@ typing_extensions mpmath==1.2.1 -sympy==1.10.1 +sympy==1.12.1 antlr4-python3-runtime==4.7.2 git+https://github.com/lambda-feedback/latex2sympy.git@master#egg=latex2sympy2 \ No newline at end of file diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..589497f --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +# evaluation_tests.py is the name the base layer's healthcheck imports, so +# include it alongside pytest's default patterns. +python_files = test_*.py *_test.py *_tests.py